private Vector3D ClosestPointOnBounds(BoundingBoxD b, Vector3D p) { Vector3D pp = (p - b.Center) / b.HalfExtents; int maxComp = pp.AbsMaxComponent(); if (maxComp == 0) { if (pp.X > 0) { p.X = b.Max.X; } else { p.X = b.Min.X; } } else if (maxComp == 1) { if (pp.Y > 0) { p.Y = b.Max.Y; } else { p.Y = b.Min.Y; } } else if (maxComp == 2) { if (pp.Z > 0) { p.Z = b.Max.Z; } else { p.Z = b.Min.Z; } } return(p); }
private Vector3D ClosestPointOnBounds(BoundingBoxD b, Vector3D p) { Vector3D vector3D = (p - b.Center) / b.HalfExtents; switch (vector3D.AbsMaxComponent()) { case 0: if (vector3D.X > 0.0) { p.X = b.Max.X; } else { p.X = b.Min.X; } break; case 1: if (vector3D.Y > 0.0) { p.Y = b.Max.Y; } else { p.Y = b.Min.Y; } break; case 2: if (vector3D.Z > 0.0) { p.Z = b.Max.Z; } else { p.Z = b.Min.Z; } break; } return(p); }