Skip to content

Commit

Permalink
very useful aabb function
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed Apr 23, 2018
1 parent 583dfe6 commit 01f5ed4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
12 changes: 11 additions & 1 deletion math/AxisAlignedBox3d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public Vector3d Center {
get { return new Vector3d(0.5 * (Min.x + Max.x), 0.5 * (Min.y + Max.y), 0.5 * (Min.z + Max.z)); }
}


public static bool operator ==(AxisAlignedBox3d a, AxisAlignedBox3d b) {
return a.Min == b.Min && a.Max == b.Max;
}
Expand Down Expand Up @@ -138,6 +137,17 @@ public Vector3d Corner(int i)
return new Vector3d(x, y, z);
}

/// <summary>
/// Returns point on face/edge/corner. For each coord value neg==min, 0==center, pos==max
/// </summary>
public Vector3d Point(int xi, int yi, int zi)
{
double x = (xi < 0) ? Min.x : ((xi == 0) ? (0.5*(Min.x + Max.x)) : Max.x);
double y = (yi < 0) ? Min.y : ((yi == 0) ? (0.5*(Min.y + Max.y)) : Max.y);
double z = (zi < 0) ? Min.z : ((zi == 0) ? (0.5*(Min.z + Max.z)) : Max.z);
return new Vector3d(x, y, z);
}


// TODO
////! 0 == bottom-left, 1 = bottom-right, 2 == top-right, 3 == top-left
Expand Down
12 changes: 12 additions & 0 deletions math/AxisAlignedBox3f.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ public Vector3f Corner(int i)
}


/// <summary>
/// Returns point on face/edge/corner. For each coord value neg==min, 0==center, pos==max
/// </summary>
public Vector3f Point(int xi, int yi, int zi)
{
float x = (xi < 0) ? Min.x : ((xi == 0) ? (0.5f * (Min.x + Max.x)) : Max.x);
float y = (yi < 0) ? Min.y : ((yi == 0) ? (0.5f * (Min.y + Max.y)) : Max.y);
float z = (zi < 0) ? Min.z : ((zi == 0) ? (0.5f * (Min.z + Max.z)) : Max.z);
return new Vector3f(x, y, z);
}


//! value is subtracted from min and added to max
public void Expand(float fRadius)
{
Expand Down

0 comments on commit 01f5ed4

Please sign in to comment.