private static double CalculateSingleEdgeLowerBound( ShapeModel model, ShapeConstraints shapeConstraints, IList <ILengthAngleConstraints> lengthAngleConstraints) { // TODO: support models with multiple edges but without pairwise constraints Debug.Assert(model.Structure.Edges.Count == 1); Debug.Assert(lengthAngleConstraints.Count == 1); double result; // Calculate best possible edge width penalty EdgeConstraints edgeConstraints = shapeConstraints.EdgeConstraints[0]; ShapeEdgeParams edgeParams = model.GetEdgeParams(0); Range lengthBoundary = lengthAngleConstraints[0].LengthBoundary; Range scaledLengthRange = new Range(lengthBoundary.Left * edgeParams.WidthToEdgeLengthRatio, lengthBoundary.Right * edgeParams.WidthToEdgeLengthRatio); Range widthRange = new Range(edgeConstraints.MinWidth, edgeConstraints.MaxWidth); if (scaledLengthRange.IntersectsWith(widthRange)) { result = 0; } else { result = model.CalculateEdgeWidthEnergyTerm(0, widthRange.Right, lengthBoundary.Left); result = Math.Min(result, model.CalculateEdgeWidthEnergyTerm(0, widthRange.Left, lengthBoundary.Right)); } return(result); }
public double CalculateEdgeWidthEnergyTerm(int edgeIndex, double width, double edgeLength) { ShapeEdgeParams @params = this.edgeParams[edgeIndex]; double diff = width / edgeLength - @params.WidthToEdgeLengthRatio; return(diff * diff / (2 * @params.WidthToEdgeLengthRatioDeviation * @params.WidthToEdgeLengthRatioDeviation)); }