// 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); }
// 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); }
public SvgViewBox(SvgPoint orgin, double width, double height) { this.x = orgin.X; this.y = orgin.Y; this.width = width; this.height = height; }
// 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); }
internal SvgPoint(SvgPoint point) { this.exact = point.exact; this.id = point.id; this.marked = point.marked; this.x = point.x; this.y = point.y; }
public CurveToCommand(SvgPoint controlPoint1, SvgPoint controlPoint2, SvgPoint endPoint) { _controlPoint1 = controlPoint1; _controlPoint2 = controlPoint2; _endPoint = endPoint; }
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)); }
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); }
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); }
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); }
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); }
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); }
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); }
public MoveToCommand(SvgPoint point) { _point = point; }
public void SetUp() { p = new SvgPoint(10, 20); }