Skip to content

Commit

Permalink
only compute cosmetic folding points when there are curved edges
Browse files Browse the repository at this point in the history
i.e. not only straight edges
  • Loading branch information
nm2107 committed Mar 27, 2023
1 parent ac257e2 commit 9bd1298
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions test_generatrices.FCMacro
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -90,14 +94,18 @@ 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

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
Expand Down

0 comments on commit 9bd1298

Please sign in to comment.