private bool UpdateFullRingGeometry(bool relativeMode) { var flag = false; flag |= GeometryHelper.EnsureGeometryType(out var geometry, ref CachedGeometry, () => new PathGeometry()); flag |= geometry.SetIfDifferent(PathGeometry.FillRuleProperty, FillRule.EvenOdd); flag |= geometry.Figures.EnsureListCount(2, () => new PathFigure()); flag |= PathFigureHelper.SyncEllipseFigure(geometry.Figures[0], LogicalBounds, SweepDirection.Clockwise); var logicalBounds = LogicalBounds; var num = logicalBounds.Width / 2.0; var num2 = logicalBounds.Height / 2.0; if (relativeMode || MathHelper.AreClose(num, num2)) { var bounds = LogicalBounds.Resize(1.0 - _relativeThickness); return(flag | PathFigureHelper.SyncEllipseFigure(geometry.Figures[1], bounds, SweepDirection.Counterclockwise)); } flag |= geometry.Figures[1].SetIfDifferent(PathFigure.IsClosedProperty, true); flag |= geometry.Figures[1].SetIfDifferent(PathFigure.IsFilledProperty, true); var firstPoint = new Point(); var intersect = InnerCurveSelfIntersect(num, num2, _absoluteThickness); var angles = ComputeAngleRanges(num, num2, intersect, 360.0, 0.0); flag |= SyncPieceWiseInnerCurves(geometry.Figures[1], 0, ref firstPoint, angles); return(flag | geometry.Figures[1].SetIfDifferent(PathFigure.StartPointProperty, firstPoint)); }
private bool UpdateZeroAngleGeometry(bool relativeMode, double angle) { Point point2; var flag = false; var arcPoint = GeometryHelper.GetArcPoint(angle, LogicalBounds); var logicalBounds = LogicalBounds; var num = logicalBounds.Width / 2.0; var num2 = logicalBounds.Height / 2.0; if (relativeMode || MathHelper.AreClose(num, num2)) { var bound = LogicalBounds.Resize(1.0 - _relativeThickness); point2 = GeometryHelper.GetArcPoint(angle, bound); } else { var intersect = InnerCurveSelfIntersect(num, num2, _absoluteThickness); var numArray = ComputeAngleRanges(num, num2, intersect, angle, angle); var a = numArray[0] * 3.1415926535897931 / 180.0; var vector = new Vector(num2 * Math.Sin(a), -num * Math.Cos(a)); point2 = GeometryHelper.GetArcPoint(numArray[0], LogicalBounds) - vector.Normalized() * _absoluteThickness; } flag |= GeometryHelper.EnsureGeometryType(out var geometry, ref CachedGeometry, () => new LineGeometry()); flag |= geometry.SetIfDifferent(LineGeometry.StartPointProperty, arcPoint); return(flag | geometry.SetIfDifferent(LineGeometry.EndPointProperty, point2)); }
/// <summary> /// Asserts whether dictionary of double values are close. /// </summary> /// <param name="expected">The expected.</param> /// <param name="actual">The actual.</param> /// <param name="epsilon">The epsilon.</param> public static void DictionaryAreClose(Dictionary <double, double> expected, Dictionary <double, double> actual, double epsilon = 1e-5) { Assert.AreEqual(expected.Count, actual.Count, "Dictionary count are not equal."); foreach (var value in actual) { var dictkey = expected.Keys.First(x => MathHelper.AreClose(x, value.Key)); AreClose(expected[dictkey], value.Value, epsilon); } }
private bool UpdateRingArcGeometry(bool relativeMode, double start, double end) { var flag = false; flag |= GeometryHelper.EnsureGeometryType(out var geometry, ref CachedGeometry, () => new PathGeometry()); flag |= geometry.SetIfDifferent(PathGeometry.FillRuleProperty, FillRule.Nonzero); flag |= geometry.Figures.EnsureListCount(1, () => new PathFigure()); var dependencyObject = geometry.Figures[0]; flag |= dependencyObject.SetIfDifferent(PathFigure.IsClosedProperty, true); flag |= dependencyObject.SetIfDifferent(PathFigure.IsFilledProperty, true); flag |= dependencyObject.SetIfDifferent(PathFigure.StartPointProperty, GeometryHelper.GetArcPoint(start, LogicalBounds)); flag |= dependencyObject.Segments.EnsureListCountAtLeast(3, () => new ArcSegment()); flag |= GeometryHelper.EnsureSegmentType(out var segment, dependencyObject.Segments, 0, () => new ArcSegment()); flag |= segment.SetIfDifferent(ArcSegment.PointProperty, GeometryHelper.GetArcPoint(end, LogicalBounds)); flag |= segment.SetIfDifferent(ArcSegment.SizeProperty, new Size(LogicalBounds.Width / 2.0, LogicalBounds.Height / 2.0)); flag |= segment.SetIfDifferent(ArcSegment.IsLargeArcProperty, end - start > 180.0); flag |= segment.SetIfDifferent(ArcSegment.SweepDirectionProperty, SweepDirection.Clockwise); flag |= GeometryHelper.EnsureSegmentType(out var segment2, dependencyObject.Segments, 1, () => new LineSegment()); var logicalBounds = LogicalBounds; var num = logicalBounds.Width / 2.0; var num2 = logicalBounds.Height / 2.0; if (relativeMode || MathHelper.AreClose(num, num2)) { var bound = LogicalBounds.Resize(1.0 - _relativeThickness); flag |= segment2.SetIfDifferent(LineSegment.PointProperty, GeometryHelper.GetArcPoint(end, bound)); flag |= dependencyObject.Segments.EnsureListCount(3, () => new ArcSegment()); flag |= GeometryHelper.EnsureSegmentType(out var segment3, dependencyObject.Segments, 2, () => new ArcSegment()); flag |= segment3.SetIfDifferent(ArcSegment.PointProperty, GeometryHelper.GetArcPoint(start, bound)); flag |= segment3.SetIfDifferent(ArcSegment.SizeProperty, GetArcSize(bound)); flag |= segment3.SetIfDifferent(ArcSegment.IsLargeArcProperty, end - start > 180.0); return(flag | segment3.SetIfDifferent(ArcSegment.SweepDirectionProperty, SweepDirection.Counterclockwise)); } var firstPoint = new Point(); var intersect = InnerCurveSelfIntersect(num, num2, _absoluteThickness); var angles = ComputeAngleRanges(num, num2, intersect, end, start); flag |= SyncPieceWiseInnerCurves(dependencyObject, 2, ref firstPoint, angles); return(flag | segment2.SetIfDifferent(LineSegment.PointProperty, firstPoint)); }
protected override double[] InterpolateValueCore(double[] baseValue, double keyFrameProgress) { if (MathHelper.IsVerySmall(keyFrameProgress)) { return(baseValue); } if (MathHelper.AreClose(keyFrameProgress, 1)) { return(Numbers); } return(AnimationHelper.InterpolateGeometryValue(baseValue, Numbers, keyFrameProgress)); }
private void SetDefaultValues() { if (this.Minimum > this.Maximum) { this.Minimum = this.Maximum; } if (MathHelper.AreClose(this.Minimum, this.Maximum)) { this.Maximum += Epsilon; } if (!this.isMaximumValueSet) { this.SelectedMaximum = this.Maximum; } if (!this.isMinimumValueSet) { this.SelectedMinimum = this.Minimum; } if (this.SelectedMinimum < this.Minimum) { this.SelectedMinimum = this.Minimum; } if (this.SelectedMaximum < this.Minimum) { this.SelectedMaximum = this.Minimum; } if (this.SelectedMinimum > this.Maximum) { this.SelectedMinimum = this.Maximum; } if (this.SelectedMaximum > this.Maximum) { this.SelectedMaximum = this.Maximum; } if (this.SelectedMaximum < this.SelectedMinimum) { this.SelectedMinimum = this.SelectedMaximum; } }
public static double RoundLayoutValue(double value, double dpiScale) { double newValue; if (!MathHelper.AreClose(dpiScale, 1.0)) { newValue = Math.Round(value * dpiScale) / dpiScale; if (double.IsNaN(newValue) || double.IsInfinity(newValue) || MathHelper.AreClose(newValue, double.MaxValue)) { newValue = value; } } else { newValue = Math.Round(value); } return(newValue); }
protected override bool UpdateCachedGeometry(IArcGeometrySourceParameters parameters) { var flag = false; NormalizeThickness(parameters); var relativeMode = parameters.ArcThicknessUnit == UnitType.Percent; var flag3 = MathHelper.AreClose(parameters.StartAngle, parameters.EndAngle); var angle = NormalizeAngle(parameters.StartAngle); var end = NormalizeAngle(parameters.EndAngle); if (end < angle) { end += 360.0; } var isFilled = _relativeThickness == 1.0; var flag5 = _relativeThickness == 0.0; if (flag3) { return(flag | UpdateZeroAngleGeometry(relativeMode, angle)); } if (MathHelper.IsVerySmall((end - angle) % 360.0)) { if (flag5 || isFilled) { return(flag | UpdateEllipseGeometry(isFilled)); } return(flag | UpdateFullRingGeometry(relativeMode)); } if (isFilled) { return(flag | UpdatePieGeometry(angle, end)); } if (flag5) { return(flag | UpdateOpenArcGeometry(angle, end)); } return(flag | UpdateRingArcGeometry(relativeMode, angle, end)); }
public static bool IsUniform(this Thickness thickness) => MathHelper.AreClose(thickness.Left, thickness.Top) && MathHelper.AreClose(thickness.Left, thickness.Right) && MathHelper.AreClose(thickness.Left, thickness.Bottom);
/// <summary> /// Asserts whether double values are close. /// </summary> /// <param name="expected">The expected.</param> /// <param name="actual">The actual.</param> /// <param name="epsilon">The epsilon.</param> public static void AreClose(double expected, double actual, double epsilon = 1e-5) { Assert.IsTrue(MathHelper.AreClose(expected, actual, epsilon), "Values are not close.\r\n Expected<{0}>. Actual<{1}>", expected, actual); }