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 UpdateSketchGeometry(PathGeometry inputPath) { var flag = false; flag |= GeometryHelper.EnsureGeometryType(out var geometry, ref CachedGeometry, () => new PathGeometry()); flag |= geometry.Figures.EnsureListCount(inputPath.Figures.Count, () => new PathFigure()); var random = new RandomEngine(_randomSeed); for (var i = 0; i < inputPath.Figures.Count; i++) { var pathFigure = inputPath.Figures[i]; var isClosed = pathFigure.IsClosed; var isFilled = pathFigure.IsFilled; if (pathFigure.Segments.Count == 0) { flag |= geometry.Figures[i] .SetIfDifferent(PathFigure.StartPointProperty, pathFigure.StartPoint); flag |= geometry.Figures[i].Segments.EnsureListCount(0); } else { var list = new List <Point>(pathFigure.Segments.Count * 3); foreach (var segment in GetEffectiveSegments(pathFigure)) { var resultPolyline = new List <Point> { segment.Points[0] }; segment.Flatten(resultPolyline, 0.0, null); var polyline = new PolylineData(resultPolyline); if (resultPolyline.Count > 1 && polyline.TotalLength > 4.0) { var a = polyline.TotalLength / 8.0; var sampleCount = (int)Math.Max(2.0, Math.Ceiling(a)); var interval = polyline.TotalLength / sampleCount; var scale = interval / 8.0; var samplePoints = new List <Point>(sampleCount); var sampleNormals = new List <Vector>(sampleCount); var sampleIndex = 0; PolylineHelper.PathMarch(polyline, 0.0, 0.0, delegate(MarchLocation location) { if (location.Reason == MarchStopReason.CompletePolyline) { return(double.NaN); } if (location.Reason != MarchStopReason.CompleteStep) { return(location.Remain); } if (sampleIndex++ == sampleCount) { return(double.NaN); } samplePoints.Add(location.GetPoint(polyline.Points)); sampleNormals.Add(location.GetNormal(polyline)); return(interval); }); DisturbPoints(random, scale, samplePoints, sampleNormals); list.AddRange(samplePoints); } else { list.AddRange(resultPolyline); list.RemoveLast(); } } if (!isClosed) { list.Add(pathFigure.Segments.Last().GetLastPoint()); } flag |= PathFigureHelper.SyncPolylineFigure(geometry.Figures[i], list, isClosed, isFilled); } } if (flag) { CachedGeometry = PathGeometryHelper.FixPathGeometryBoundary(CachedGeometry); } return(flag); }