From 9bd12984022b34efbfe442121b698508f8be54a6 Mon Sep 17 00:00:00 2001 From: Nicolas MURE Date: Mon, 27 Mar 2023 21:28:47 +0200 Subject: [PATCH] only compute cosmetic folding points when there are curved edges i.e. not only straight edges --- test_generatrices.FCMacro | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/test_generatrices.FCMacro b/test_generatrices.FCMacro index 21705e0..e2ae3f3 100644 --- a/test_generatrices.FCMacro +++ b/test_generatrices.FCMacro @@ -68,20 +68,24 @@ class CosmeticFoldingPoint(FoldingPoint): pass -def getFoldingPointsOnStraightEdge(edge: Part.Edge) -> [FoldingPoint]: - firstPoint = edge.valueAt(edge.FirstParameter) - middlePoint = edge.valueAt(edge.FirstParameter + (edge.LastParameter - edge.FirstParameter) / 2) - lastPoint = edge.valueAt(edge.LastParameter) +def getFoldingPointsOnStraightEdge(edge: Part.Edge, computeCosmeticFoldingPoints: bool) -> [FoldingPoint]: + foldingPoints: [FoldingPoint] = [] + firstPoint = edge.valueAt(edge.FirstParameter) firstTangent = edge.tangentAt(edge.FirstParameter) - middleTangent = edge.tangentAt(edge.FirstParameter + (edge.LastParameter - edge.FirstParameter) / 2) + foldingPoints.append(FoldingPoint(firstPoint, firstTangent)) + + if computeCosmeticFoldingPoints: + at = edge.FirstParameter + (edge.LastParameter - edge.FirstParameter) / 2 + middlePoint = edge.valueAt(at) + middleTangent = edge.tangentAt(at) + foldingPoints.append(FoldingPoint(middlePoint, middleTangent)) + + lastPoint = edge.valueAt(edge.LastParameter) lastTangent = edge.tangentAt(edge.LastParameter) + foldingPoints.append(FoldingPoint(lastPoint, lastTangent)) - return [ - FoldingPoint(firstPoint, firstTangent), - CosmeticFoldingPoint(middlePoint, middleTangent), - FoldingPoint(lastPoint, lastTangent) - ] + return foldingPoints def buildFoldingPointsOnWire(wire: Part.Wire, maxPointsCount: int) -> [FoldingPoint]: @@ -90,6 +94,10 @@ def buildFoldingPointsOnWire(wire: Part.Wire, maxPointsCount: int) -> [FoldingPo foldingPoints = dict() totalLengthOfNonLinearEdges = getTotalLengthOfNonLinearEdges(edges) + # only compute cosmetic folding points when there are curved edges (i.e. + # not only straight edges) + computeCosmeticFoldingPoints = 0.0 != totalLengthOfNonLinearEdges + chunksOffset = 0 if len(edges) == 1: chunksOffset = 1 @@ -97,7 +105,7 @@ def buildFoldingPointsOnWire(wire: Part.Wire, maxPointsCount: int) -> [FoldingPo for edge in edges: if isinstance(edge.Curve, Part.Line): # pick the start and end points of a straight line - for foldingPoint in getFoldingPointsOnStraightEdge(edge): + for foldingPoint in getFoldingPointsOnStraightEdge(edge, computeCosmeticFoldingPoints): foldingPoints[serializeVector(foldingPoint.getPoint())] = foldingPoint continue