public void EqualWithinEpsilonTest()
        {
            Polygon a = Polygon.AsRectangle(new Vector(1000, 1000));
            Polygon b = Polygon.AsRectangle(new Vector(1000.000001, 1000.000001));

            Assert.IsTrue(ClipperUtility.EqualWithinEpsilon(a, b));
        }
        public void NotEqualWithinEpsilonTest()
        {
            Polygon a = Polygon.AsRectangle(new Vector(1000, 1000));
            Polygon b = Polygon.AsRectangle(new Vector(2000, 3000));

            Assert.IsFalse(ClipperUtility.EqualWithinEpsilon(a, b));
        }
        public void ContainsFullyTest()
        {
            Polygon a = Polygon.AsRectangle(new Vector(10, 10));
            Polygon b = Polygon.AsRectangle(new Vector(1, 1), new Vector(1, 1));

            Assert.IsTrue(ClipperUtility.ContainsWithinEpsilon(a, b));
            Assert.AreEqual(1, ClipperUtility.ContainsRelative(a, b), .001);
        }
        public void GetAreaTest()
        {
            Polygon polygon      = Polygon.AsRectangle(new Vector(10, 100));
            double  expectedArea = 10 * 100;
            double  resultArea   = ClipperUtility.GetArea(polygon);

            Assert.AreEqual(expectedArea, resultArea, .001);
        }
        public void EqualWithinHighEpsilonTest()
        {
            Polygon a = Polygon.AsRectangle(new Vector(10, 10));
            Polygon b = Polygon.AsRectangle(new Vector(10, 10), new Vector(1, 1));

            Assert.IsFalse(ClipperUtility.EqualWithinEpsilon(a, b));
            Assert.IsTrue(ClipperUtility.EqualWithinEpsilon(a, b, epsilon: 15 * Vector.Scale * 15 * Vector.Scale));
        }
        public void PolygonRotation90Degrees()
        {
            Polygon expectedPolygon = Polygon.AsRectangle(new Vector(2, 2), new Vector(-1, -1));
            Polygon actualPolygon   = expectedPolygon.DeepClone();

            actualPolygon.RotateCounter(90 * Math.PI / 180);

            CollectionAssert.AreNotEqual(expectedPolygon.Points, actualPolygon.Points);
            Assert.IsTrue(ClipperUtility.EqualWithinEpsilon(expectedPolygon, actualPolygon));
        }
        public void PolygonVectorAddition()
        {
            Polygon polygon = Polygon.AsRectangle(new Vector(3, 4));
            Vector  offset  = new Vector(1, 1);

            polygon += offset;

            List <IntPoint> expectedCoordinates = new List <IntPoint>(
                new IntPoint[] { new Vector(1, 1), new Vector(4, 1), new Vector(4, 5), new Vector(1, 5) });

            Assert.IsTrue(ClipperUtility.EqualWithinEpsilon(polygon, expectedCoordinates));
        }
        public void OffsetPolygonByHalfTest()
        {
            Polygon input          = Polygon.AsRectangle(new Vector(10, 10));
            Polygon expectedOutput = Polygon.AsRectangle(new Vector(5, 5), new Vector(2.5, 2.5));

            PolygonList output = ClipperUtility.OffsetPolygon(input, -2.5f);

            Assert.AreEqual(1, output.Count);

            Polygon actualOutput = output[0];

            Assert.IsTrue(ClipperUtility.EqualWithinEpsilon(expectedOutput, actualOutput));
        }
        public void SimpleOverlapTest()
        {
            Polygon a = Polygon.AsRectangle(new Vector(2, 2));
            Polygon b = Polygon.AsRectangle(new Vector(2, 2), new Vector(1, 1));

            Polygon     expectedPolygon    = Polygon.AsRectangle(new Vector(1, 1), new Vector(1, 1));
            PolygonList resultIntersection = ClipperUtility.Intersection(a, b);

            Assert.AreEqual(1, resultIntersection.Count);
            Polygon resultPolygon = resultIntersection[0];

            Assert.IsTrue(ClipperUtility.HaveIntersection(a, b));
            Assert.IsTrue(ClipperUtility.EqualWithinEpsilon(expectedPolygon, resultPolygon));
        }
        public void LineIntersectionTest()
        {
            Polygon line      = Polygon.AsLine(Vector.Zero, Vector.One);
            Polygon rectangle = Polygon.AsRectangle(Vector.One);

            PolygonList output = ClipperUtility.Intersection(line, rectangle);

            Assert.AreEqual(1, output.Count);

            Polygon actualOutput = output[0];

            Assert.IsTrue(ClipperUtility.EqualWithinEpsilon(line, actualOutput,
                                                            epsilon: 15 * Vector.Scale * 15 * Vector.Scale));
        }
        public void PolygonCircumferenceTest()
        {
            Polygon polygon = Polygon.AsRectangle(new Vector(3, 4));

            Assert.AreEqual(14, polygon.Circumference);
        }