gumyr / build123d

A python CAD programming library
Apache License 2.0
512 stars 86 forks source link

Plane() initializer sometimes ignores arguments #188

Closed barnabywalters closed 1 year ago

barnabywalters commented 1 year ago

In cases where named and positional arguments are mixed, like this (and probably many others, but this is the real-world example I ran into):

Plane((0, 0, 0), x_dir=(1, 0, 0), z_dir=(0, 0, 1))

the first argument is ignored by __init__, as it expects either all positional or all named arguments. IMO b3d should either attempt to handle mixed arguments somehow (e.g. in this case inferring that it’s the origin), or at least raise an error when it ignores an argument, so that the user is aware of what’s happening. Something like:

if args and kwargs:
  raise ValueError("Plane() initializer expects either positional OR named arguments, not both")
gumyr commented 1 year ago

I've lot track of the commit that fixed this but:

from build123d import *

p = Plane((1, 1, 1), x_dir=(1, 0, 0), z_dir=(0, 0, 1))
print(p)
Plane(o=(1.00, 1.00, 1.00), x=(1.00, 0.00, 0.00), z=(0.00, 0.00, 1.00))

shows that it's fixed now.