gumyr / build123d

A python CAD programming library
Apache License 2.0
397 stars 73 forks source link

Bezier argument auto list parsing incorrect #534

Open MatthiasJ1 opened 5 months ago

MatthiasJ1 commented 5 months ago
a = Bezier((0,-5), (0,5))
b = Bezier([0,-5], [0,5])
Screenshot
gumyr commented 5 months ago

This is fundamentally an issue with how accepting Vector is, i.e. this is valid:

>>> Vector(1)
Vector: (1.0, 0.0, 0.0)

If we look at the debugger while processing: Bezier([0,-5], [0,5]) we see this: Screenshot from 2024-02-04 10-28-47 cntl_pnts is the raw inputs flattened, here the two lists are flattened into four points: [0, -5, 0, 5] which gets turned into four polls/Vectors (three of which are unique): Vector(0,0,0), Vector(-5,0,0), Vector(0,0,0), Vector(5,0,0). This ultimately results in a horizontal line.

So, is Vector too accepting? It's possible to do this currently Line(-5,5) which would create the same horizontal line as b.

Should Bezier (and other objects) reject multiple lists? Should inputs like Bezier((0,0), other_points) be rejected?

At this point I'm leaning towards saying that points must be tuples, so (5,) would be acceptable, but not 5. Therefore, [0,-5], [0,5] would be rejected as containing no points.

Thoughts?

MatthiasJ1 commented 5 months ago

The list expansion only makes sense in the case len(vargs)==1 and adding that condition will fix these issues.