public static BezierCurve FromEllipse(Point center, Size radius) { var pt1 = new Point(0, radius.Height); // top var pt2 = new Point(radius.Width, 0); // right var pt3 = new Point(0, -radius.Height); // bottom var pt4 = new Point(-radius.Width, 0); // left double dx = radius.Width * 4.0 * (System.Math.Sqrt(2) - 1) / 3; double dy = radius.Height * 4.0 * (System.Math.Sqrt(2) - 1) / 3; var curve_control_points = new [] { pt1, pt1.Add(dx, 0), pt2.Add(0, dy), pt2, pt2.Add(0, -dy), pt3.Add(dx, 0), pt3, pt3.Add(-dx, 0), pt4.Add(0, -dy), pt4, pt4.Add(0, dy), pt1.Add(-dx, 0), pt1 } .Select(p => p + center).ToArray(); var curve_Degree = 3; var curve = new BezierCurve(curve_control_points, curve_Degree); return curve; }
public static BezierSegment[] FromArc(double startangle, double endangle) { if (endangle < startangle) { throw new System.ArgumentOutOfRangeException(nameof(endangle), "endangle must be >= startangle"); } double min_angle = 0; double max_angle = System.Math.PI * 2; double total_angle = endangle - startangle; if (total_angle == min_angle) { var arr = new BezierSegment[1]; double cos_theta = System.Math.Cos(startangle); double sin_theta = System.Math.Sin(startangle); var p0 = new Point(cos_theta, -sin_theta); var p1 = BezierSegment.RotateAroundOrigin( p0, startangle); arr[0] = new BezierSegment(p1,p1,p1,p1); } if (total_angle > max_angle) { endangle = startangle + max_angle; } var bez_arr = BezierSegment.subdivide_arc_nicely(startangle, endangle) .Select(a => BezierSegment.get_bezier_points_for_small_arc(a.begin, a.end)) .ToArray(); return bez_arr; }
private void connect(IVisio.Shape a, IVisio.Shape b, bool a_arrow, bool b_arrow) { var page = a.ContainingPage; var connectors_stencil = page.Application.Documents.OpenStencil("connec_u.vss"); var connectors_masters = connectors_stencil.Masters; var dcm = connectors_masters["Dynamic Connector"]; var drop_point = new VADRAW.Point(-2, -2); var c1 = page.Drop(dcm, drop_point); ConnectorHelper.ConnectShapes(a, b, c1); //a.AutoConnect(b, connect_dir_none, null); if (a_arrow || b_arrow) { var writer = new FormulaWriterSIDSRC(); if (a_arrow) { writer.SetFormula(c1.ID16, VASS.SRCConstants.BeginArrow, "13"); } if (b_arrow) { writer.SetFormula(c1.ID16, VASS.SRCConstants.EndArrow, "13"); } writer.Commit(page); } }
private void connect(IVisio.Shape a, IVisio.Shape b, bool a_arrow, bool b_arrow) { var page = a.ContainingPage; var connectors_stencil = page.Application.Documents.OpenStencil("connec_u.vss"); var connectors_masters = connectors_stencil.Masters; var dcm = connectors_masters["Dynamic Connector"]; var drop_point = new VADRAW.Point(-2, -2); var c1 = page.Drop(dcm, drop_point); VACONNECT.ConnectorHelper.ConnectShapes(a, b, c1); //a.AutoConnect(b, connect_dir_none, null); if (a_arrow || b_arrow) { var update = new VASS.Update(); if (a_arrow) { update.SetFormula(c1.ID16, VASS.SRCConstants.BeginArrow, "13"); } if (b_arrow) { update.SetFormula(c1.ID16, VASS.SRCConstants.EndArrow, "13"); } update.Execute(page); } }
public VisioAutomation.Drawing.Rectangle GetRectangle() { var pin = new VisioAutomation.Drawing.Point(this.PinX, this.PinY); var locpin = new VisioAutomation.Drawing.Point(this.LocPinX, this.LocPinY); var size = new VisioAutomation.Drawing.Size(this.Width, this.Height); return(new VisioAutomation.Drawing.Rectangle(pin - locpin, size)); }
public BezierSegment(Point start, Point handle1, Point handle2, Point end) : this() { this.Start = start; this.Handle1 = handle1; this.Handle2 = handle2; this.End = end; }
public BezierCurve(Point[] controlpoints, int degree) { if (controlpoints== null) { throw new System.ArgumentNullException(nameof(controlpoints)); } if (degree < 1) { throw new System.ArgumentOutOfRangeException(nameof(degree)); } this.ControlPoints = controlpoints; this.Degree = degree; }
public BezierSegment(IList<Point> points) : this() { if (points == null) { throw new System.ArgumentNullException(nameof(points)); } if (points.Count != 4) { string msg = $"A {typeof (BezierSegment)} must have exactly 4 points"; throw new System.ArgumentException(msg, nameof(points)); } this.Start = points[0]; this.Handle1 = points[1]; this.Handle2 = points[2]; this.End = points[3]; }
public void Add(Point p) { if (this.initialized) { if (p.X < this.min_x) { this.min_x = p.X; } else if (p.X > this.max_x) { this.max_x = p.X; } else { // do nothing } if (p.Y < this.min_y) { this.min_y = p.Y; } else if (p.Y > this.max_y) { this.max_y = p.Y; } else { // do nothing } } else { this.min_x = p.X; this.max_x = p.X; this.min_y = p.Y; this.max_y = p.Y; this.initialized = true; } }
public IVisio.Shape DrawLine(Point p1, Point p2) { if (this.Target.Master != null) { var shape = this.Target.Master.DrawLine(p1.X, p1.Y, p2.X, p2.Y); return shape; } else if (this.Target.Page != null) { var shape = this.Target.Page.DrawLine(p1.X, p1.Y, p2.X, p2.Y); return shape; } else if (this.Target.Shape != null) { var shape = this.Target.Shape.DrawLine(p1.X, p1.Y, p2.X, p2.Y); return shape; } throw new System.ArgumentException("Unhandled Drawing Surface"); }
public Point Subtract(Point p) { var new_point = new Point(this.X - p.X, this.Y - p.Y); return new_point; }
public Point Subtract(double dx, double dy) { var new_point = new Point(this.X - dx, this.Y - dy); return new_point; }
public Point Add(Point p) { var new_point = new Point(this.X + p.X, this.Y + p.Y); return new_point; }
public Rectangle Subtract(Point s) { var r2 = new Rectangle(Left - s.X, Bottom - s.Y, Right - s.X, Top - s.Y); return r2; }
public Point Add(double dx, double dy) { var new_point = new Point(this.X + dx, this.Y + dy); return new_point; }
public Point Multiply(double sx, double sy) { var new_point = new Point(this.X*sx, this.Y*sy); return new_point; }
public static void AreEqual(double x, double y, VADRAW.Point actual_point, double delta) { Assert.AreEqual(x, actual_point.X, delta); Assert.AreEqual(y, actual_point.Y, delta); }
public Point Subtract(Point p) { var new_point = new Point(X - p.X, Y - p.Y); return new_point; }
public static void AreEqual(VADRAW.Point p1, VADRAW.Point p2, double delta) { Assert.AreEqual(p1.X, p2.X, delta); Assert.AreEqual(p1.Y, p2.Y, delta); }
public Point Subtract(VA.Drawing.Size s) { var new_point = new Point(X - s.Width, Y - s.Height); return new_point; }
public IVisio.Shape DrawOval(Point center, double radius) { var A = center.Add(-radius, -radius); var B = center.Add(radius, radius); var rect = new Rectangle(A, B); return this.DrawOval(rect); }
private static Point RotateAroundOrigin(Point p1, double theta) { double nx = (System.Math.Cos(theta)*p1.X) - (System.Math.Sin(theta)*p1.Y); double ny = (System.Math.Sin(theta)*p1.X) + (System.Math.Cos(theta)*p1.Y); return new Point(nx, ny); }
private static BezierSegment get_bezier_points_for_small_arc(double start_angle, double end_angle) { const double right_angle = System.Math.PI/2; double total_angle = end_angle - start_angle; if (total_angle > right_angle) { throw new System.ArgumentOutOfRangeException(nameof(end_angle), "angle formed by start and end must <= right angle (pi/2)"); } double theta = (end_angle - start_angle)/2; double cos_theta = System.Math.Cos(theta); double sin_theta = System.Math.Sin(theta); var p0 = new Point(cos_theta, -sin_theta); var p1 = new Point((4 - cos_theta) / 3.0, ((1 - cos_theta) * (cos_theta - 3.0)) / (3 * sin_theta)); var p2 = new Point(p1.X, -p1.Y); var p3 = new Point(p0.X, -p0.Y); var arc_bezier = new[] {p0, p1, p2, p3} .Select(p => BezierSegment.RotateAroundOrigin(p, theta + start_angle)) .ToArray(); return new BezierSegment(arc_bezier); }
public Point Add(double dx, double dy) { var new_point = new Point(X + dx, Y + dy); return new_point; }
public Point Add(Size s) { var new_point = new Point(this.X + s.Width, this.Y + s.Height); return new_point; }
public static Point operator +(Point pa, Point pb) { var result = new Point(pa.X + pb.X, pa.Y + pb.Y); return result; }
public Point Subtract(Size s) { var new_point = new Point(this.X - s.Width, this.Y - s.Height); return new_point; }
public static Point operator *(Point pa, double s) { var result = new Point(pa.X*s, pa.Y*s); return result; }
public static void AreEqual(VADRAW.Point point, VADRAW.Point actual_point, double delta) { Assert.AreEqual(point.X, actual_point.X, delta); Assert.AreEqual(point.Y, actual_point.Y, delta); }
public static Point operator *(Point pa, Size s) { var result = new Point(pa.X*s.Width, pa.Y*s.Height); return result; }
public IVisio.Shape DrawQuarterArc(Point p0, Point p1, IVisio.VisArcSweepFlags flags) { if (this.Target.Master != null) { return this.Target.Master.DrawQuarterArc(p0.X, p0.Y, p1.X, p1.Y, flags); } else if (this.Target.Page != null) { return this.Target.Page.DrawQuarterArc(p0.X, p0.Y, p1.X, p1.Y, flags); } else if (this.Target.Shape != null) { return this.Target.Shape.DrawQuarterArc(p0.X, p0.Y, p1.X, p1.Y, flags); } throw new System.ArgumentException("Unhandled Drawing Surface"); }
public Rectangle Add(Point s) { var r2 = new Rectangle(Left + s.X, Bottom + s.Y, Right + s.X, Top + s.Y); return r2; }
public IVisio.Shape Drop( IVisio.Master master, Point point) { if (master == null) { throw new System.ArgumentNullException(nameof(master)); } if (this.Target.Master != null) { return this.Target.Master.Drop(master, point.X, point.Y); } else if (this.Target.Page != null) { return this.Target.Page.Drop(master, point.X, point.Y); } else if (this.Target.Shape != null) { return this.Target.Shape.Drop(master, point.X, point.Y); } throw new System.ArgumentException("Unhandled Drawing Surface"); }
public Point Multiply(Size s) { var new_point = new Point(this.X*s.Width, this.Y*s.Height); return new_point; }
public Point Divide(double sx, double sy) { var new_point = new Point(this.X/sx, this.Y/sy); return new_point; }
public static void AreEqual(double x, double y, VADRAW.Point p, double delta) { Assert.AreEqual(x, p.X, delta); Assert.AreEqual(y, p.Y, delta); }