Skip to content

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

@Thaina

Description

@Thaina
        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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions