private double getVertexWeight(Polyline polyline, int pathIndex, int pointIndex) { ICoordinate p1 = polyline.Paths[pathIndex].Vertices[pointIndex - 1]; ICoordinate p2 = polyline.Paths[pathIndex].Vertices[pointIndex]; ICoordinate p3 = polyline.Paths[pathIndex].Vertices[pointIndex + 1]; switch (_vertexWeighting) { case VertexWeightingType.NormalizedLinear: case VertexWeightingType.AngleCube: // length of the segments double s1 = PlanimetryAlgorithms.Distance(p1, p2); double s2 = PlanimetryAlgorithms.Distance(p2, p3); double s1s2 = s1 * s2; // angle of rotation double angle = Math.PI - Math.Abs(Math.Acos(((p1.X - p2.X) * (p3.X - p2.X) + (p1.Y - p2.Y) * (p3.Y - p2.Y)) / s1s2)); if (_vertexWeighting == VertexWeightingType.SquareDifference) { return(s1s2 * angle / (s1 + s2)); } else { return(s1s2 * angle * angle * angle); } case VertexWeightingType.SquareDifference: return(Math.Abs((p2.X - p1.X) * (p3.Y - p1.Y) - (p3.X - p1.X) * (p2.Y - p1.Y))); case VertexWeightingType.Custom: if (SDMinVertexWeightNeeded != null) { SDMinVertexWeightNeededEventArgs args = new SDMinVertexWeightNeededEventArgs(p1, p2, p3, pathIndex, pointIndex); SDMinVertexWeightNeeded(this, args); return(args.Weight); } break; } return(0); }
private double getVertexWeight(Polyline polyline, int pathIndex, int pointIndex) { ICoordinate p1 = polyline.Paths[pathIndex].Vertices[pointIndex - 1]; ICoordinate p2 = polyline.Paths[pathIndex].Vertices[pointIndex]; ICoordinate p3 = polyline.Paths[pathIndex].Vertices[pointIndex + 1]; switch (_vertexWeighting) { case VertexWeightingType.NormalizedLinear: case VertexWeightingType.AngleCube: // length of the segments double s1 = PlanimetryAlgorithms.Distance(p1, p2); double s2 = PlanimetryAlgorithms.Distance(p2, p3); double s1s2 = s1 * s2; // angle of rotation double angle = Math.PI - Math.Abs(Math.Acos(((p1.X - p2.X) * (p3.X - p2.X) + (p1.Y - p2.Y) * (p3.Y - p2.Y)) / s1s2)); if (_vertexWeighting == VertexWeightingType.SquareDifference) return s1s2 * angle / (s1 + s2); else return s1s2 * angle * angle * angle; case VertexWeightingType.SquareDifference: return Math.Abs((p2.X - p1.X) * (p3.Y - p1.Y) - (p3.X - p1.X) * (p2.Y - p1.Y)); case VertexWeightingType.Custom: if (SDMinVertexWeightNeeded != null) { SDMinVertexWeightNeededEventArgs args = new SDMinVertexWeightNeededEventArgs(p1, p2, p3, pathIndex, pointIndex); SDMinVertexWeightNeeded(this, args); return args.Weight; } break; } return 0; }