public static bool TryGetCenterAndRadius(Rect bounds, Angle start, Angle end, out Point center, out double radius) { if (DoubleUtil.IsZero(bounds.Width) || double.IsNaN(bounds.Width) || DoubleUtil.IsZero(bounds.Height) || double.IsNaN(bounds.Height)) { center = default(Point); radius = 0; return(false); } var p0 = new Point(0, 0); var unitArc = new ArcInfo(p0, 1, start, end); var rect = default(Rect); var ps = unitArc.StartPoint; rect.Union(ps); rect.Union(unitArc.EndPoint); foreach (var quadrant in unitArc.QuadrantPoints) { rect.Union(quadrant); } var wf = bounds.Width / rect.Width; var hf = bounds.Height / rect.Height; radius = Math.Min(wf, hf); rect.Scale(radius, radius); var v = bounds.MidPoint() - rect.MidPoint(); center = p0 + v; return(true); }
protected override Size ArrangeOverride(Size finalSize) { var strokeThickness = this.GetStrokeThickness(); var arc = new ArcInfo(default(Point), 1, this.Start, this.End); this.Overflow = arc.Overflow(strokeThickness / 2, this.Padding); return(finalSize); }
public Point Interpolate(ArcInfo arc, bool isDirectionReversed) { var angle = isDirectionReversed ? Gauges.Interpolate.Linear(arc.End, arc.Start, this) : Gauges.Interpolate.Linear(arc.Start, arc.End, this); return(arc.GetPoint(angle)); }
public static Geometry CreateGeometry(ArcInfo arc, Angle start, Angle end, double thickness, double strokeThickness) { if (DoubleUtil.AreClose(start, end) || (DoubleUtil.AreClose(thickness, 0) && DoubleUtil.AreClose(strokeThickness, 0)) || DoubleUtil.AreClose(arc.Radius, 0)) { return(Geometry.Empty); } if (DoubleUtil.LessThanOrClose(thickness, strokeThickness)) { return(new PathGeometry(new[] { CreateArcPathFigure(arc, start, end, strokeThickness, strokeThickness) })); } return(new PathGeometry(new[] { CreateArcPathFigure(arc, start, end, thickness, strokeThickness) })); }
protected virtual Geometry CreateArcGeometry(double value) { var arc = ArcInfo.Fit(this.RenderSize, this.Padding, this.Start, this.End); if (double.IsNaN(value) || DoubleUtil.AreClose(value, this.Maximum)) { return(CreateGeometry(arc, this.Start, this.End, this.Thickness, this.GetStrokeThickness())); } var from = this.IsDirectionReversed ? this.End : this.Start; var to = Interpolate.Linear(this.Minimum, this.Maximum, value) .Clamp(0, 1) .Interpolate(this.Start, this.End, this.IsDirectionReversed); return(CreateGeometry(arc, from, to, this.Thickness, this.GetStrokeThickness())); }
public static PathFigure CreateArcPathFigure(ArcInfo arc, Angle startAngle, Angle endAngle, double thickness, double strokeThickness) { if (strokeThickness > thickness || double.IsInfinity(strokeThickness)) { return(CreateArcPathFigure(arc, startAngle, endAngle, thickness, 0)); } var op1 = arc.GetPointAtRadiusOffset(startAngle, -strokeThickness / 2); var figure = new PathFigure { StartPoint = op1 }; var isStroked = DoubleUtil.GreaterThan(strokeThickness, 0); var ro = arc.Radius - (strokeThickness / 2); foreach (var arcSegment in arc.CreateArcSegments(startAngle, endAngle, ro, isStroked)) { figure.Segments.Add(arcSegment); } if (DoubleUtil.LessThanOrClose(thickness, strokeThickness)) { figure.IsClosed = false; figure.IsFilled = false; return(figure); } if (thickness >= arc.Radius) { figure.Segments.Add(new LineSegment(arc.Center, isStroked)); } else { var ip2 = arc.GetPointAtRadiusOffset(endAngle, (strokeThickness / 2) - thickness); figure.Segments.Add(new LineSegment(ip2, isStroked)); var ri = arc.Radius - thickness + (strokeThickness / 2); foreach (var arcSegment in arc.CreateArcSegments(endAngle, startAngle, ri, isStroked)) { figure.Segments.Add(arcSegment); } } figure.IsClosed = true; return(figure); }
/// <inheritdoc /> public override Thickness ArrangeTick(TickText tickText, ArcInfo arc, AngularTextBar textBar) { var angle = Interpolate.Linear(textBar.Minimum, textBar.Maximum, tickText.Value) .Clamp(0, 1) .Interpolate(textBar.Start, textBar.End, textBar.IsDirectionReversed); tickText.Transform = Transform.Identity; var textGeometry = tickText.BuildGeometry(new Point(0, 0)); var compVector = textGeometry.Bounds.TopLeft.ToVector(); var rotatedCompVector = new Vector(compVector.X, compVector.Y); var diffVector = new Vector(0, 0); var textAngle = Angle.Zero; switch (textBar.TextOrientation) { case TextOrientation.Tangential: textAngle = angle.IsUpperQuadrants() ? angle : angle + Angle.FromDegrees(180); tickText.Transform = new RotateTransform(textAngle.Degrees); rotatedCompVector = compVector.Rotate(textAngle); var vectorFromCenterToUpperLeft = new Vector(textGeometry.Bounds.Width / 2, textGeometry.Bounds.Height / 2); var rotatedCenterVectorComp = vectorFromCenterToUpperLeft.Rotate(textAngle); diffVector = vectorFromCenterToUpperLeft - rotatedCenterVectorComp; break; case TextOrientation.Horizontal: tickText.Transform = Transform.Identity; break; default: throw new ArgumentOutOfRangeException(); } var pos = arc.GetUpperLeftPointAtOffset(textGeometry.Bounds.Size.Rotate(textAngle), angle, textBar.TextOffset); tickText.TranslateTransform.SetCurrentValue(TranslateTransform.XProperty, pos.X + diffVector.X - rotatedCompVector.X); tickText.TranslateTransform.SetCurrentValue(TranslateTransform.YProperty, pos.Y + diffVector.Y - rotatedCompVector.Y); return(default(Thickness)); }
/// <summary> /// Updates the transform of <paramref name="tickText"/> /// </summary> /// <returns>Returns the overflow.</returns> public abstract Thickness ArrangeTick(TickText tickText, ArcInfo arc, AngularTextBar textBar);