public RectangleF (PointF origin, SizeF size) { X = origin.X; Y = origin.Y; Width = size.Width; Height = size.Height; }
public IntersectionInfo (PointF loc) { Location = loc; }
public static PointF Subtract (this PointF a, PointF b) { return new PointF (a.X - b.X, a.Y - b.Y); }
public static PointF Add (this PointF a, PointF b) { return new PointF (a.X + b.X, a.Y + b.Y); }
public float DistanceTo (PointF p3) { var x21 = EndX - X; var y21 = EndY - Y; var x31 = p3.X - X; var y31 = p3.Y - Y; var d = x21*x21 + y21*y21; if (d <= 0) return (float)Math.Sqrt (x31*x31 + y31*y31); var n = x31*x21 + y31*y21; var u = n / d; if (u <= 0) { return (float)Math.Sqrt (x31*x31 + y31*y31); } else if (u >= 1) { var x32 = p3.X - EndX; var y32 = p3.Y - EndY; return (float)Math.Sqrt (x32*x32 + y32*y32); } else { var dx = X + u*x21 - p3.X; var dy = Y + u*y21 - p3.Y; return (float)Math.Sqrt (dx*dx + dy*dy); } }
public void AddPoint(PointF rawPoint) { _points.Add(rawPoint); _apoints = null; _bbvalid = false; }
public static float Dot (this PointF a, PointF b) { return a.X * b.X + a.Y * b.Y; }
public void AddPoint (PointF rawPoint) { _points.Add (rawPoint); _apoints = null; _bbvalid = false; }
public static void DrawLine(this IGraphics g, PointF s, PointF e, float w) { g.DrawLine (s.X, s.Y, e.X, e.Y, w); }
public static float DistanceTo (this PointF a, PointF b) { var dx = a.X - b.X; var dy = a.Y - b.Y; return (float)Math.Sqrt (dx*dx + dy*dy); }
public static void DrawString(this IGraphics g, string s, PointF p, Font f) { g.SetFont (f); g.DrawString (s, p.X, p.Y); }
public static void DrawString (this IGraphics g, string s, PointF p) { g.DrawString(s, p.X, p.Y); }
public static void AddPoint(this Polygon poly, PointF p) { poly.AddPoint (p.X, p.Y); }
public IntersectionInfo GetIntersectionWith (Stroke other) { for (var i = 0; i < _points.Count - 1; i++) { var x1 = _points [i].X; var y1 = _points [i].Y; var x21 = _points [i + 1].X - x1; var y21 = _points [i + 1].Y - y1; for (var j = 0; j < other._points.Count - 1; j++) { var x3 = other._points [j].X; var y3 = other._points [j].Y; var x43 = other._points [j + 1].X - x3; var y43 = other._points [j + 1].Y - y3; var x13 = x1 - x3; var y13 = y1 - y3; var d = y43*x21 - x43*y21; if (d == 0.0f) continue; var na = x43*y13 - y43*x13; var ua = na / d; if (ua < 0 || ua > 1) continue; var nb = x21*y13 - y21*x13; var ub = nb / d; if (ub >= 0 && ub <= 1) { var loc = new PointF (x1 + ua * x21, y1 + ua * y21); return new IntersectionInfo (loc); } } } return null; }
public static PointF Lerp (this PointF s, PointF d, float t) { var dx = d.X - s.X; var dy = d.Y - s.Y; return new PointF (s.X + t * dx, s.Y + t * dy); }
int RemoveInitialFlourish () { var stroke = this; var points = stroke.Points; var totalLength = 0.0f; for (var i = 0; i < points.Length - 1; i++) { totalLength += points [i].DistanceTo (points [i+1]); } // // Look for a sharp bend within the first bit of the shape // var len = 0.0f; var lastDir = new PointF (); for (var i = 0; i < points.Length - 1; i++) { var dir = points [i+1].Subtract (points [i]).Normalized (); if (i > 0) { var dot = lastDir.Dot (dir); if (dot < 0) { // // Big turn // //stroke.WriteSvg ("/Users/fak/Desktop/turn.svg"); return i; } } lastDir = dir; // // Only look at the first 5% // len += points [i].DistanceTo (points [i+1]); if (len > totalLength * 0.05f) { return 0; } } return 0; }
public static float DistanceToLine (this PointF p3, PointF p1, PointF p2) { return new LineSegmentF (p1, p2).DistanceTo (p3); }
public int GetClosestPoint (PointF p/*, out float dist*/) { var minIndex = -1; var minDist = 0.0f; for (var i = StartIndex; i <= EndIndex; i++) { var d = _points [i].DistanceTo (p); if (minIndex == -1 || (d < minDist)) { minIndex = i; minDist = d; } } //dist = minDist; return minIndex; }
public LineSegmentF (PointF begin, PointF end) { X = begin.X; Y = begin.Y; EndX = end.X; EndY = end.Y; }
public bool Contains(PointF loc) { return (X <= loc.X && loc.X < (X + Width) && Y <= loc.Y && loc.Y < (Y + Height)); }
public IntersectionInfo(PointF loc) { Location = loc; }