예제 #1
0
        public void BoxInsideOutside_Intersects_OutsideTouchingMax()
        {
            var a = new Box3d(new V3d(0, 0, 0), new V3d(4, 4, 4));
            var b = new Box3d(new V3d(4, 0, 0), new V3d(8, 4, 4));

            Assert.IsTrue(!a.Intersects(b));
        }
예제 #2
0
 /// <summary>
 /// Counts points approximately outside axis-aligned box (cell granularity).
 /// Result is always equal or greater than exact number.
 /// Faster than CountPointsOutsideBox.
 /// </summary>
 public static long CountPointsApproximatelyOutsideBox(
     this IPointCloudNode self, Box3d query, int minCellExponent = int.MinValue
     )
 => CountPointsApproximately(self,
                             n => !query.Intersects(n.BoundingBoxExactGlobal),
                             n => query.Contains(n.BoundingBoxExactGlobal),
                             minCellExponent);
예제 #3
0
 public bool ObjectIntersectsBox(
     int objectIndex,
     Box3d box
     )
 {
     return(box.Intersects(Sphere3ds[objectIndex]));
 }
예제 #4
0
        public void ContainedBoxesDoIntersect()
        {
            var a = new Box3d(new V3d(0, 0, 0), new V3d(3, 3, 3));
            var b = new Box3d(new V3d(1, 1, 1), new V3d(2, 2, 2));

            Assert.IsTrue(a.Intersects(b));
        }
예제 #5
0
 /// <summary>
 /// Counts points approximately inside axis-aligned box (cell granularity).
 /// Result is always equal or greater than exact number.
 /// Faster than CountPointsInsideBox.
 /// </summary>
 public static long CountPointsApproximatelyInsideBox(
     this PointSetNode self, Box3d query, int minCellExponent = int.MinValue
     )
 => CountPointsApproximately(self,
                             n => query.Contains(n.BoundingBox),
                             n => !query.Intersects(n.BoundingBox),
                             minCellExponent);
예제 #6
0
        public void TouchingBoxesDoNotIntersect()
        {
            var a = new Box3d(new V3d(0, 0, 0), new V3d(1, 1, 1));
            var b = new Box3d(new V3d(1, 0, 0), new V3d(2, 1, 1));

            Assert.IsTrue(!a.Intersects(b));
        }
예제 #7
0
        public void ValidBoxDoesNotIntersectInvalidBox()
        {
            var a = new Box3d(new V3d(0, 0, 0), new V3d(1, 1, 1));
            var b = Box3d.Invalid;

            Assert.IsTrue(!a.Intersects(b));
        }
예제 #8
0
 /// <summary>
 /// All points outside axis-aligned box (excluding boundary).
 /// </summary>
 public static IEnumerable <Chunk> QueryPointsOutsideBox(
     this IPointCloudNode self, Box3d query, int minCellExponent = int.MinValue
     )
 => QueryPoints(self,
                n => !query.Intersects(n.BoundingBoxExactGlobal),
                n => query.Contains(n.BoundingBoxExactGlobal),
                p => !query.Contains(p),
                minCellExponent);
예제 #9
0
 /// <summary>
 /// All points inside axis-aligned box (including boundary).
 /// </summary>
 public static IEnumerable <Chunk> QueryPointsInsideBox(
     this PointSetNode self, Box3d query, int minCellExponent = int.MinValue
     )
 => QueryPoints(self,
                n => query.Contains(n.BoundingBox),
                n => !query.Intersects(n.BoundingBox),
                p => query.Contains(p),
                minCellExponent);
예제 #10
0
        public bool ObjectIntersectsBox(
            int objectIndex,
            Box3d box
            )
        {
            var pl = Position3dList;
            int pi = objectIndex * 3;

            return(box.Intersects(new Triangle3d(pl[pi], pl[pi + 1], pl[pi + 2])));
        }
        /// <summary>
        /// Clips given ray on box, or returns null if ray does not intersect box.
        /// </summary>
        private static Line3d?Clip(Box3d box, Ray3d ray0)
        {
            ray0.Direction = ray0.Direction.Normalized;

            if (!box.Intersects(ray0, out double t0))
            {
                return(null);
            }
            var p0 = ray0.GetPointOnRay(t0);

            var ray1 = new Ray3d(ray0.GetPointOnRay(t0 + box.Size.Length), -ray0.Direction);

            if (!box.Intersects(ray1, out double t1))
            {
                throw new InvalidOperationException();
            }
            var p1 = ray1.GetPointOnRay(t1);

            return(new Line3d(p0, p1));
        }
예제 #12
0
        public void BoxIntersectsTriangleTest()
        {
            Box3d box = new Box3d();

            // Triangle is inside box
            Triangle t = new Triangle(new Point3d(0, 0, 0), new Point3d(0.2, -0.1, 0), new Point3d(0, -0.2, -0.1));

            Assert.IsTrue(box.Intersects(t));

            // Triangle is outside of box
            t = new Triangle(new Point3d(1, 1, 1), new Point3d(2, 1, 1), new Point3d(1, 2, 1));
            Assert.IsFalse(box.Intersects(t));

            // Triangle touches box
            t = new Triangle(new Point3d(0.5, 0, 0), new Point3d(0.7, -0.1, 0), new Point3d(0.8, -0.2, -0.1));
            Assert.IsTrue(box.Intersects(t));

            // Triangle intersects box
            t = new Triangle(new Point3d(-1, -1, 0), new Point3d(0.7, 0.9, 0.1), new Point3d(0.8, -2, -0.1));
            Assert.IsTrue(box.Intersects(t));
        }
예제 #13
0
 public bool ObjectIntersectsBox(int objectIndex, Box3d box)
 {
     return(box.Intersects(m_boxes[objectIndex]));
 }
예제 #14
0
 /// <summary></summary>
 public bool IsFullyOutside(Box3d box)
 {
     return(!box.Intersects(m_sphere));
 }
예제 #15
0
        public void CanDeletePoints()
        {
            var q = new Box3d(new V3d(0.3), new V3d(0.7));

            var a = CreateRegularPointsInUnitCube(10, 1);

            Assert.IsTrue(a.QueryAllPoints().SelectMany(chunk => chunk.Positions).Any(p => q.Contains(p)));

            var b = a.Delete(n => q.Contains(n.BoundingBox), n => !(q.Contains(n.BoundingBox) || q.Intersects(n.BoundingBox)), p => q.Contains(p), CancellationToken.None);

            Assert.IsTrue(a.PointCount > b.PointCount);

            Assert.IsTrue(!b.QueryAllPoints().SelectMany(chunk => chunk.Positions).Any(p => q.Contains(p)));
        }
예제 #16
0
        public void BoxDoesIntersectItself()
        {
            var a = new Box3d(new V3d(1, 2, 3), new V3d(4, 5, 6));

            Assert.IsTrue(a.Intersects(a));
        }