예제 #1
0
파일: Simplify.cs 프로젝트: fel88/GeomPad
        // rest of the code doesn't care about point format

        // basic distance-based simplification
        public static NFP simplifyRadialDist(NFP points, double?sqTolerance)
        {
            var prevPoint = points[0];
            var newPoints = new NFP();

            newPoints.AddPoint(prevPoint);

            SvgPoint point = null;
            int      i     = 1;

            for (var len = points.Length; i < len; i++)
            {
                point = points[i];

                if (point.marked || getSqDist(point, prevPoint) > sqTolerance)
                {
                    newPoints.AddPoint(point);
                    prevPoint = point;
                }
            }

            if (prevPoint != point)
            {
                newPoints.AddPoint(point);
            }
            return(newPoints);
        }
예제 #2
0
파일: Simplify.cs 프로젝트: fel88/GeomPad
        // to suit your point format, run search/replace for '.x' and '.y';
        // for 3D version, see 3d branch (configurability would draw significant performance overhead)

        // square distance between 2 points
        public static double getSqDist(SvgPoint p1, SvgPoint p2)
        {
            var dx = p1.X - p2.X;
            var dy = p1.Y - p2.Y;

            return(dx * dx + dy * dy);
        }
예제 #3
0
파일: SvgViewBox.cs 프로젝트: carbon/Svg
 public SvgViewBox(SvgPoint orgin, double width, double height)
 {
     this.x = orgin.X;
     this.y = orgin.Y;
     this.width = width;
     this.height = height;
 }
예제 #4
0
파일: Simplify.cs 프로젝트: fel88/GeomPad
        // square distance from a point to a segment
        public static double getSqSegDist(SvgPoint p, SvgPoint p1, SvgPoint p2)
        {
            var x  = p1.X;
            var y  = p1.Y;
            var dx = p2.X - x;
            var dy = p2.Y - y;

            if (dx != 0 || dy != 0)
            {
                var t = ((p.X - x) * dx + (p.Y - y) * dy) / (dx * dx + dy * dy);

                if (t > 1)
                {
                    x = p2.X;
                    y = p2.Y;
                }
                else if (t > 0)
                {
                    x += dx * t;
                    y += dy * t;
                }
            }

            dx = p.X - x;
            dy = p.Y - y;

            return(dx * dx + dy * dy);
        }
예제 #5
0
 internal SvgPoint(SvgPoint point)
 {
     this.exact  = point.exact;
     this.id     = point.id;
     this.marked = point.marked;
     this.x      = point.x;
     this.y      = point.y;
 }
예제 #6
0
 public CurveToCommand(SvgPoint controlPoint1,
                       SvgPoint controlPoint2,
                       SvgPoint endPoint)
 {
     _controlPoint1 = controlPoint1;
     _controlPoint2 = controlPoint2;
     _endPoint      = endPoint;
 }
예제 #7
0
 public void Rebuild()
 {
     Points = new SvgPoint[] { };
     AddPoint(new SvgPoint(x, y));
     AddPoint(new SvgPoint(x + Width, y));
     AddPoint(new SvgPoint(x + Width, y + Height));
     AddPoint(new SvgPoint(x, y + Height));
 }
예제 #8
0
        public void TestDivide2()

        {
            SvgPoint p2 = 100 / p;



            Assert.AreEqual(10, p.X);

            Assert.AreEqual(20, p.Y);

            Assert.AreEqual(10, p2.X);

            Assert.AreEqual(5, p2.Y);
        }
예제 #9
0
        public void TestDivide1()

        {
            SvgPoint p2 = p / 2.5;



            Assert.AreEqual(10, p.X);

            Assert.AreEqual(20, p.Y);

            Assert.AreEqual(4, p2.X);

            Assert.AreEqual(8, p2.Y);
        }
예제 #10
0
        public void TestMultiply2()

        {
            SvgPoint p2 = 3.5 * p;



            Assert.AreEqual(10, p.X);

            Assert.AreEqual(20, p.Y);

            Assert.AreEqual(35, p2.X);

            Assert.AreEqual(70, p2.Y);
        }
예제 #11
0
        public void TestLerp()

        {
            SvgPoint p2 = new SvgPoint(40, 30);

            SvgPoint p3 = p.lerp(p2, 0.25);



            Assert.AreEqual(10, p.X);

            Assert.AreEqual(20, p.Y);

            Assert.AreEqual(40, p2.X);

            Assert.AreEqual(30, p2.Y);

            Assert.AreEqual(17.5, p3.X);

            Assert.AreEqual(22.5, p3.Y);
        }
예제 #12
0
        public void TestSubtraction()

        {
            SvgPoint p2 = new SvgPoint(40, 30);

            SvgPoint p3 = p2 - p;



            Assert.AreEqual(10, p.X);

            Assert.AreEqual(20, p.Y);

            Assert.AreEqual(40, p2.X);

            Assert.AreEqual(30, p2.Y);

            Assert.AreEqual(30, p3.X);

            Assert.AreEqual(10, p3.Y);
        }
예제 #13
0
        public void TestAddition()

        {
            SvgPoint p2 = new SvgPoint(40, 30);

            SvgPoint p3 = p + p2;



            Assert.AreEqual(10, p.X);

            Assert.AreEqual(20, p.Y);

            Assert.AreEqual(40, p2.X);

            Assert.AreEqual(30, p2.Y);

            Assert.AreEqual(50, p3.X);

            Assert.AreEqual(50, p3.Y);
        }
예제 #14
0
 public MoveToCommand(SvgPoint point)
 {
     _point = point;
 }
예제 #15
0
        public void SetUp()

        {
            p = new SvgPoint(10, 20);
        }