public PathGeometry OpenFit(List <Point> input, bool inputMayContainRepeats, double cornerThreshold, double distanceTolerance, bool onlyCubics, bool enforceStartTangent, Vector startTangent, bool enforceEndTangent, Vector endTangent) { if (cornerThreshold <= 0.0 || cornerThreshold >= Math.PI) { throw new ArgumentOutOfRangeException("cornerThreshold", (object)cornerThreshold, "Corner threshold must be strictly between zero and Pi."); } if (distanceTolerance <= 0.0) { throw new ArgumentOutOfRangeException("distanceTolerance", (object)distanceTolerance, "Distance tolerance must be strictly greater than zero."); } this.enforceStartTangent = enforceStartTangent; this.enforceEndTangent = enforceEndTangent; if (this.enforceStartTangent && startTangent.LengthSquared < FloatingPointArithmetic.SquaredDistanceTolerance && (this.enforceEndTangent && endTangent.LengthSquared < FloatingPointArithmetic.SquaredDistanceTolerance)) { throw new ArgumentException(ExceptionStringTable.CannotEnforceZeroLengthTangents); } if (this.enforceEndTangent) { endTangent.Normalize(); this.endTangent = endTangent; } if (this.enforceStartTangent) { startTangent.Normalize(); this.startTangent = startTangent; } this.sample = input; if (inputMayContainRepeats && input.Count > 1) { this.sample = new List <Point>(input.Count); this.sample.Add(input[0]); for (int index = 1; index < input.Count; ++index) { if (!VectorUtilities.ArePathPointsVeryClose(input[index], input[index - 1])) { this.sample.Add(input[index]); } } } PathGeometry path = new PathGeometry(); PathGeometryEditor pathGeometryEditor = new PathGeometryEditor(path); if (this.sample.Count > 0) { pathGeometryEditor.StartFigure(this.sample[0]); this.figure = path.Figures[0]; } PathFigureEditor pathFigureEditor = new PathFigureEditor(this.figure); if (this.sample.Count == 2) { if (VectorUtilities.Distance(this.sample[0], this.sample[1]) >= distanceTolerance) { if (onlyCubics) { pathFigureEditor.LinearCubicCurveTo(this.sample[1]); } else { pathFigureEditor.LineTo(this.sample[1]); } } } else if (this.sample.Count > 2) { int lastIndex = this.sample.Count - 1; this.chordLength = VectorUtilities.GetCumulatedChordLength(this.sample, 0, lastIndex); this.distanceTolerance = distanceTolerance; double cosThreshold = Math.Cos(cornerThreshold); int num = 0; int index = 1; while (true) { while (index >= lastIndex || this.IsSamplePointACorner(index, cosThreshold)) { if (index == num + 1) { if (onlyCubics) { pathFigureEditor.LinearCubicCurveTo(this.sample[index]); } else { pathFigureEditor.LineTo(this.sample[index]); } } else { this.OpenFit2DFromTo(num, this.GetUnitTangentVectorFirst(num), index, this.GetUnitTangentVectorLast(index), onlyCubics); } num = index; ++index; if (num >= lastIndex) { goto label_33; } } ++index; } } label_33: return(path); }