-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
Alignment rework #782
base: dev
Are you sure you want to change the base?
Alignment rework #782
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #782 +/- ##
==========================================
- Coverage 96.09% 96.02% -0.07%
==========================================
Files 25 25
Lines 8474 8460 -14
==========================================
- Hits 8143 8124 -19
- Misses 331 336 +5 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be some tests of Align.NONE
(even though they might not increase coverage).
src/build123d/geometry.py
Outdated
|
||
|
||
def to_align_offset( | ||
min_point: Sequence[float], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function would make more sense if the inputs were VectorLike
then all of the math could be done with Vectors instead of looping over floats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow how making them vectors helps us avoid the looping behavior in the general case. I have changed to VectorLike
as the signature and the only place I could see to remove the looping behavior was in the trivial case where we have a single alignment variable.
@@ -36,6 +36,7 @@ class Align(Enum): | |||
MIN = auto() | |||
CENTER = auto() | |||
MAX = auto() | |||
NONE = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to introduce the following two TypeVars here that can be used on all of the objects (not necessarily in the PR):
Align2DType = TypeVar(
"Align2DType", Union[Align, None], Tuple[Union[Align, None], Union[Align, None]]
)
Align3DType = TypeVar(
"Align3DType",
Union[Align, None],
Tuple[Union[Align, None], Union[Align, None], Union[Align, None]],
)
This could be done later though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression that typevars were meant to signal generics. I have added these using type aliases as that feels more correct to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out, I think there are other examples of where TypeAlias
should be used instead of TypeVar
. This might help with the documentation as well as it seems as though ReadtheDocs will show the TypeAlias
and not the full definition which will makes the docs more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, responded to a comment mid it being edited 😅.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm learning about TypeAlias
:)
src/build123d/geometry.py
Outdated
def to_align_offset( | ||
min_point: Sequence[float], | ||
max_point: Sequence[float], | ||
align: Sequence[Align], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
align could also be None so I think should be typed as align: Sequence[Union[Align,None]]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense to me. I guess if we add the Align2DType
and Align3DType
it could be typed Union[Align2DType, Align3DType]
Made the requested changes, waiting to make sure the design aspects are ironed out before adding tests. |
I'm surprised there is no coverage for the existing Align tests - I would have guessed that there are tests that would have covered them already. Add a few tests for the Align options shouldn't be difficult though. |
While using
build123d
I noticed that the type signature forBoundBox.to_align_offset
was wrong. While fixing it I noticed that there was a lot of replicated aligning logic. This is an attempt to rectify that.to_align_offset
function to thegeometry
module to allow for aligningAlign.NONE
enum memberto_align_offset
to return aVector
as every call site immediately constructed a vector anywayNot sure if there is interest in merging such a pr. If so I can go ahead and make sure the documentation lines up with the changes and make any changes y'all deem appropriate.
Would close:
Supersedes: