Replacement – Replace repeated multi-part pattern

As always with a replacement problem, look at the FullForm of your expressions. Here is your expression:

expr = (2-2 NormCDF(((-2 e+s^2) t-2 Log(A)+2 Log(K))/(2 s Sqrt(t))));
expr //FullForm

Plus (2, Times (-2, NormCDF (Times (Rational (1,2)), Power (s, -1), Power (t, Rational (-1,2)), Plus (Times (Plus (Times (- 2, e), Power (s, 2)), t), Times (-2, Record (A)), Times (2, Record (K))))))))

And here is your rule:

rule = n_-n_ NormCDF(x___);
rule //FullForm

Plus (Pattern (n, White ()), Times (-1, NormCDF (Pattern (x, BlankNullSequence ())), Pattern (n, White ())))

Notice how the product in its expression has the form:

Times(-2, _NormCDF)

and its replacement rule uses:

Times(-1, _NormCDF, n_)

As they do not match, no replacement occurs. An alternative that will work is:

expr /. n_ + m_ NormCDF(x_) /; n+m==0 :> n NormCDF(-x)

2 NormCDF (- (((- 2 e + s ^ 2) t – 2 Log (A) + 2 Log (K)) / (2 s Sqrt (t))))

user-centered design: can we use a different form pattern depending on the context in a single application?

The best solution is to maintain a concept throughout the application (this includes code scaling)

However, in critical cases the style can be changed, this requires a separate CSS code.

However, I wonder, in an aesthetic context, is the right alignment justified?

And if only the entrance to the left or above would not be a better solution

enter the description of the image here

Why?

Consider eye fixation

enter the description of the image here

Graphical user interface design: what is the best user interface pattern for a multi-level assignment?

I made the following design in the hope of helping the user to perform a multi-level assignment interaction more efficiently, but I am concerned that the amount of data displayed may be an information overload.

As seen below:

Current design

Let's say there are lots of records, and for each record: there can be multiple sections, for each section: 20-50 modules, and for each module there would be a 3-level assignment for a group of users or just a specific group of users. single user

java – A new type of construction pattern?

The fact is that I wanted to apply the construction pattern. But this could not be achieved, since I could not create an instance of the class with an empty constructor; this is dangerous. The goal is to make the list of parameters a little shorter and more meaningful. As a result, I created a new class, the generator, which sets all the fields that are in the class in the constructor. Here is the code:

GameObject:

public abstract class GameObject {
    protected boolean isHidden;
    protected Coordinate position;
    protected int pictureWidth, pictureHeight;
    protected Object filling;

    GameObject(GameObjectBuilder gameObjectBuilder) throws IOException{
        this.position = new Coordinate(gameObjectBuilder.getPosition());
        this.pictureWidth = gameObjectBuilder.getPictureWidth();
        this.pictureHeight = gameObjectBuilder.getPictureHeight();
        this.isHidden = gameObjectBuilder.isHidden();
        this.filling = gameObjectBuilder.getFilling(); // link is passed
    }

    public void paint(Graphics gr) throws IOException{
        if(filling instanceof BufferedImage) {
            gr.drawImage((Image) filling, position.getX(), position.getY(), null);
        }
        else if(filling instanceof Color) {
            gr.setColor((Color) filling);
            gr.fillRect(position.getX(), position.getY(), pictureWidth, pictureHeight);
        } else {
            System.err.println("You forgot to add a way to render filling");
        }
    }
    private Object getFilling() {
        return filling;
    }

    int getPictureWidth() {
        return pictureWidth;
    }
    int getPictureHeight() {
        return pictureHeight;
    }
    public boolean isHidden() {
        return isHidden;
    }
    public Coordinate getPosition() {
        return position;
    }
}

GameObjectBuilder:

public class GameObjectBuilder {
    protected boolean isHidden;
    protected Coordinate position;
    protected int pictureWidth, pictureHeight;
    public Object filling;

    public GameObjectBuilder(int pictureWidth, int pictureHeight, Coordinate position, boolean isHidden, Color filling){
        this.position = new Coordinate(position);
        this.pictureWidth = pictureWidth;
        this.pictureHeight = pictureHeight;
        this.isHidden = isHidden;
        this.filling = filling; // link
    }

    public GameObjectBuilder(Coordinate position, boolean isHidden, BufferedImage filling){
        this.position = position;
        this.pictureWidth = filling.getWidth();
        this.pictureHeight = filling.getHeight();
        this.isHidden = isHidden;
        this.filling = filling; // передается ссылка
    }

    public GameObjectBuilder(GameObjectBuilder gameObject) throws IOException{
        this.position = new Coordinate(gameObject.getPosition());
        this.pictureWidth = gameObject.getPictureWidth();
        this.pictureHeight = gameObject.getPictureWidth();
        this.isHidden = gameObject.isHidden();
        this.filling = gameObject.getFilling(); //link is passed
    }

    public Object getFilling() {
        return filling;
    }

    public int getPictureWidth() {
        return pictureWidth;
    }
    public int getPictureHeight() {
        return pictureHeight;
    }
    public boolean isHidden() {
        return isHidden;
    }
    public Coordinate getPosition() {
        return position;
    }
}

and now for dessert:

MaterialGameObject:

public abstract class MaterialGameObject extends GameObject{
    private int materialHeight, materialWidth;
    private Coordinate relativeCoordinateOfStartOfFilling;

    public MaterialGameObject(MaterialGameObjectBuilder materialGameObjectBuilder) throws IOException{
        super(materialGameObjectBuilder.getGameObjectBuilder());
        this.materialHeight = materialGameObjectBuilder.getMaterialHeight();
        this.materialWidth = materialGameObjectBuilder.getMaterialWidth();
        calculateRelativeCoordinateOfStartOfFilling();
    }

    private int getMaterialWidth() {
        return materialWidth;
    }

    public int getMaterialHeight() {
        return materialHeight;
    }
    public Coordinate getRelativeCoordinateOfStartOfFilling() {
        return relativeCoordinateOfStartOfFilling;
    }
    protected abstract void calculateRelativeCoordinateOfStartOfFilling();
}

MaterialGameObjectBuilder:

public class MaterialGameObjectBuilder{
    private GameObjectBuilder gameObjectBuilder;
    private int materialHeight, materialWidth;

    public MaterialGameObjectBuilder(GameObjectBuilder gameObjectBuilder, int materialHeight, int materialWidth) {
        this.gameObjectBuilder = gameObjectBuilder; // link
        this.materialHeight = materialHeight;
        this.materialWidth = materialWidth;
    }

    public GameObjectBuilder getGameObjectBuilder(){
        return gameObjectBuilder;
    }

    public int getMaterialHeight() {
        return materialHeight;
    }
    public int getMaterialWidth() {
        return materialWidth;
    }
}

Did I choose the right path?

MVC: Android application with MVC pattern

this developing an app in android studio, there is a database in sql server and I want to consume the data that is there through a web service, the point is that I want to use the MVC pattern, I know that I must separate both models into packages as controllers and views are already as activities. My question is how would they handle the connection ?, I know that if I use the android database I should use helpers and then call them from the model, would I do the same to connect to the web service? or is there a better way to do this

opengl – Calculate normal based on Voronoi pattern

I am applying a 3D Voronoi pattern on a mesh. Using those loops, I can calculate the position of the cell, an identification and the distance.

But I would like to calculate a normal based on the generated pattern.
How can I generate a normal or reorient the current normal based on this pattern and the associated cells?

The goal is to provide a frontal appearance for the mesh. The normality of each cell must point in the same direction and the adjacent cells point in different directions. Those directions must be based on the original mesh normals, I don't want to totally break the mesh normals and have those points in random directions.

This is how I generate the Voronoi pattern.

float3 p = floor(position);
float3 f = frac(position);
float id = 0.0;
float distance = 10.0;

for (int k = -1; k <= 1; k++)
{
    for (int j = -1; j <= 1; j++)
    {
        for (int i = -1; i <= 1; i++)
        {
            float3 cell = float3(float(i), float(j), float(k));
            float3 random = hash3(p + cell);
            float3 r = cell - f + random * angleOffset;
            float d = dot(r, r);

            if (d < distance)
            {
                id = random;
                distance = d;
                cellPosition = cell + p;
                normal = ?
            }
        }
    }
}

Graphical user interface design: the best user interface pattern to allow the user to assign 1 level nested elements to two groups

My problem is similar to this: the best user interface pattern to allow a user to assign items to groups

I am looking for a good user interface design to map elements between 2 groups (only one-to-one mapping). These items may be under a parent or by themselves.
I thought of dragging and dropping / having check boxes (or changing as) to activate any group.

Articles Group 1 Group 2

Article A
Article A1 check box check box

Article B check box check box

Command Pattern Implementation – Model Command Output

I am trying to implement a memory file system and wanted to model the commands. I currently want to admit mkdir, cd, up, dir. mkdir and cd take the name of the directory as an argument, while above and dir do not take any arguments. I'm thinking of implementing the commands as a command pattern and I started with ICommand, which is seen below,

interface Command {
boolean execute();
}

I am confused here about how I return the output of the command to the caller, since the output would be different for different commands, such as mkdir / cd / up, the output will be Boolean (indicating if the command was successful / not), while The dir command results in obtaining a list of items in that directory. Is it correct to apply the command pattern here?

unit: how can I unpack texture data following a 16 * 8 bit pattern?

Is it possible to decompress texture data following a specific bit wrapping scheme?

I have read that texture data in HLSL can be read as 4 32-bit floats, each with a total of 128 bits. The packaging scheme I am looking to use is 16 packing groups of 8 bits each. I have trouble finding out how to unpack this data without loss because they are interpreted as floating.

pattern matching – Partition a list by cumulative sum when the accumulation reaches a fixed value

I have a list dat = {10, 10, 10, 10, 10, 40} .

When the cumulative sum of dat achieves >= 25, the cumulative sum stops, the difference between 25 and the cumulative sum up to that point will be added to the next element of dat and the accumulated sum is restarted until it reaches 25 again and so on.

The desired result must be {{10, 20, 25}, { 15, 25}, {25}, {15}}

I cannot understand how to perform this task, either procedural or functional.

Thanks in advance.