private HPoint[] GetOutlinedRect(HPoint p1, HPoint p2, int outline) { /* p1 * +--+--+ * \ \ \ * \ \ \ * +--+--+ * p2 p2+len * */ if (p1 == p2) { return new[] { p1, p1, p1, p1 }; } var pt1 = new Point2D(p1.X, p1.Y); var pt2 = new Point2D(p2.X, p2.Y); var vector = Vector2D.FromPoints(pt2, pt1); var points = new[]{ new Point2D(-outline,0), new Point2D(0,outline), new Point2D(vector.Length,outline), new Point2D(vector.Length+outline,0), new Point2D(vector.Length,-outline), new Point2D(0,-outline), new Point2D(-outline,0), }; var rotated = points.Select(pt => pt1.Add(pt.Rotate(vector.Angle))).Select(pt => new HPoint((int)pt.X, (int)pt.Y)).ToArray(); return rotated; }
public Point2D Add(Point2D p2) { return new Point2D(X + p2.X, Y + p2.Y); }
public Size2D Sub(Point2D p2) { return new Size2D(X-p2.X, Y-p2.Y); }
public static Vector2D FromPoints(Point2D p1, Point2D p2) { return new Vector2D(new Size2D(p1.X - p2.X, p1.Y - p2.Y)); }