Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] math.all + math.any for multi dimensional boolean #225

Open
Thaina opened this issue Jul 31, 2022 · 1 comment
Open

[FR] math.all + math.any for multi dimensional boolean #225

Thaina opened this issue Jul 31, 2022 · 1 comment

Comments

@Thaina
Copy link

Thaina commented Jul 31, 2022

        public static bool2 all(bool2x2 m) { return new bool2(all(m.c0),all(m.c1)); }
        public static bool2 all(bool3x2 m) { return new bool2(all(m.c0),all(m.c1)); }
        public static bool2 all(bool4x2 m) { return new bool2(all(m.c0),all(m.c1)); }

        public static bool2 any(bool2x2 m) { return new bool2(any(m.c0),any(m.c1)); }
        public static bool2 any(bool3x2 m) { return new bool2(any(m.c0),any(m.c1)); }
        public static bool2 any(bool4x2 m) { return new bool2(any(m.c0),any(m.c1)); }
        
        public static bool3 all(bool2x3 m) { return new bool3(all(m.c0),all(m.c1),all(m.c2)); }
        public static bool3 all(bool3x3 m) { return new bool3(all(m.c0),all(m.c1),all(m.c2)); }
        public static bool3 all(bool4x3 m) { return new bool3(all(m.c0),all(m.c1),all(m.c2)); }

        public static bool3 any(bool2x3 m) { return new bool3(any(m.c0),any(m.c1),any(m.c2)); }
        public static bool3 any(bool3x3 m) { return new bool3(any(m.c0),any(m.c1),any(m.c2)); }
        public static bool3 any(bool4x3 m) { return new bool3(any(m.c0),any(m.c1),any(m.c2)); }
        
        public static bool4 all(bool2x4 m) { return new bool4(all(m.c0),all(m.c1),all(m.c2),all(m.c3)); }
        public static bool4 all(bool3x4 m) { return new bool4(all(m.c0),all(m.c1),all(m.c2),all(m.c3)); }
        public static bool4 all(bool4x4 m) { return new bool4(all(m.c0),all(m.c1),all(m.c2),all(m.c3)); }

        public static bool4 any(bool2x4 m) { return new bool4(any(m.c0),any(m.c1),any(m.c2),any(m.c3)); }
        public static bool4 any(bool3x4 m) { return new bool4(any(m.c0),any(m.c1),any(m.c2),any(m.c3)); }
        public static bool4 any(bool4x4 m) { return new bool4(any(m.c0),any(m.c1),any(m.c2),any(m.c3)); }

Sample use case

int[] vertexTriangles; // index buffer of mesh
var rightEdge = new int3(0,1,4); // index of vertex on the right of uv rectangle
var topEdge = new int3(1,3,4); // index of vertex on the top of uv rectangle
var rightTop = new int3x2(new int3(0,1,4),new int3(1,3,4));

foreach(int index in vertexTriangles)
{
    bool3x2 checkRightTop = index % 6 == rightTop;
    bool2 isRightTop = math.any(checkRightTop); // check that vertexIndex is which corner of UV space
    // isRightTop.x is left or right
    // isRightTop.y is bottom or top
    var v = math.select(rightTopValue,leftBottomValue,isRightTop); // select leftTop/rightTop/leftBottom/rightBottom
}
@ltmx
Copy link

ltmx commented Sep 27, 2023

Implemented in Unity.mathx : https://github.com/LTMX/Unity.mathx
Enjoy !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants