Exemple #1
0
        public void FlattenTo_SubdividesToCorrectError(double[] polygon, double acceptedError, int expectedNumSides)
        {
            var points          = UnflattenArrayToPoints(polygon);
            var resultingPoints = BezierTools.FlattenTo(points, acceptedError).ToArray();

            Assert.Equal(1 + expectedNumSides, resultingPoints.Length);
        }
Exemple #2
0
        public void FlattenTo_NoSubdivisionWhenLinearButOutOfOrder(double[] polygon)
        {
            var points = UnflattenArrayToPoints(polygon);
            var result = BezierTools.FlattenTo(points, .001).ToArray();

            Assert.Equal(4, result.Length);
            var flattened = FlattenPointsToArray(result);

            Assert.Equal(polygon, flattened);
        }
Exemple #3
0
        public void FlattenTo_LimitsRecursiveDepth_10metersSubdividesToNoLessThan100thOfMillimeterByDefault()
        {
            // If a curve is 10 meters, how many subdivisions would reduce a segment length to below 0.01 millimeters?
            // Take that as our maximum # of reasonable subdivisions for approximating a curve.
            var maxDivisions = Math.Ceiling(Math.Log(10 * 1000 / .01) / Math.Log(2));

            var points = UnflattenArrayToPoints(new double[] { 0, 0, 0, 1, 1, 1, 1, 0 });
            var result = BezierTools.FlattenTo(points, 0).ToArray();

            Assert.NotEmpty(result);
            var actualDivisions = Math.Log(result.Length / 3 /* points per bezier */) / Math.Log(2);

            Assert.InRange(actualDivisions, 1, maxDivisions);
        }