Unity-Technologies / Unity-Technologies/Unity.Mathematics

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

Open
#225 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
1.4k
Forks
159
PR merge metrics
No merged PRs in 30d

Description

        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
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name a file or test; search the Unity.Mathematics sources for the existing math.all and math.any vector overloads and inspect how matrix types expose their columns. Add support matching the listed bool2x2 through bool4x4 cases, then verify the sample multi-dimensional boolean expressions compile and produce the requested per-axis results.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
computer-graphics
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.