Skip to content

Review the Location constructor and optimize the valid overloads #441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gumyr opened this issue Dec 20, 2023 · 3 comments · May be fixed by #992
Closed

Review the Location constructor and optimize the valid overloads #441

gumyr opened this issue Dec 20, 2023 · 3 comments · May be fixed by #992
Labels
enhancement New feature or request

Comments

@gumyr
Copy link
Owner

gumyr commented Dec 20, 2023

Some of the Location constructor's overloads seem confusing and may not be optimal. Specifically,

    @overload
    def __init__(
        self, translation: VectorLike, direction: VectorLike, angle: float
    ):

seems misleading at best. The term translation and direction should also be reconsidered as there are position and orientation properties.

@gumyr gumyr added the enhancement New feature or request label Dec 20, 2023
@gumyr gumyr added this to the Release 1.0.0 milestone Dec 20, 2023
@jdegenstein
Copy link
Collaborator

kwargs are currently not working in Location either Location((1,2,3),rotation=(10,20,30)) returns TypeError: Location.__init__() got an unexpected keyword argument 'rotation'

@jdegenstein
Copy link
Collaborator

jdegenstein commented May 15, 2025

@gumyr I have been looking at this issue again and here are the current overloads for the Location class. I propose we eliminate the three overloads marked with "X" below and combine marked with "C" below.

class Location:
    "@overloads" #omitting future @overload for brevity
X   def __init__(self):
    def __init__(self, location: Location):
X   def __init__(self, translation: VectorLike, angle: float = 0):
C   def __init__(self, translation: VectorLike, rotation: RotationLike | None = None):
C   def __init__(self, translation: VectorLike, rotation: RotationLike, ordering: Extrinsic | Intrinsic):
    def __init__(self, plane: Plane):
    def __init__(self, plane: Plane, plane_offset: VectorLike):
    def __init__(self, top_loc: TopLoc_Location):
    def __init__(self, gp_trsf: gp_Trsf):
X   def __init__(self, translation: VectorLike, direction: VectorLike, angle: float):
┕ DELETE those marked with "X", COMBINE marked with "C"

    #actual constructor \/
    def __init__(self, *args): # consider adding **kwargs
        ...

Furthermore I agree that all uses of translation should be replaced with position instead. Additionally I think that rotation should be renamed to orientation to match with the class properties. I also propose we also reorganize the overloads, as the order they are listed affects the order they show up in the language server. Here are my proposed, reworked overloads / constructor signature.

class Location:
    "@overloads" #omitting future @overload for brevity
    def __init__(self, position: VectorLike | None = None, orientation: RotationLike | None = None, ordering: Extrinsic | Intrinsic | None = None):
    def __init__(self, plane: Plane):
    def __init__(self, location: Location):
    def __init__(self, top_loc: TopLoc_Location):
    def __init__(self, gp_trsf: gp_Trsf):

    #actual constructor \/
    def __init__(self, *args, **kwargs):
        ...

What do you think? If this is acceptable I can work on the actual constructor init.

EDIT: I realized that it should be possible to eliminate the empty init overload, and changed the first init overload to have a default value for position of None.
EDIT2: deleted def __init__(self, plane: Plane, plane_offset: VectorLike): from the proposed table as it does not seem very useful in context of Location(Plane.XY.offset(5)) and the applicability of a vector offset seems limited.

@gumyr
Copy link
Owner Author

gumyr commented May 17, 2025

@jdegenstein thanks for all the work you did to close this one. Commit 6711511 adds a little to your PR #991 to handle all of the overload cases except Plane/plane offset so it has minimal backwards compatibility issues. All of your kwargs tests pass in addition to the existing Location tests (minus the one Plane/plane offset test that isn't needed anymore).

Hopefully this issue is good and closed now.

@gumyr gumyr closed this as completed May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants