Bloc
Bloc copied to clipboard
Bounds calculation API is confusing
BlBounds
comment states: "I am a mutable implementation of Rectangle which stores coordinates as Numbers and not Points.
I am very useful for chainable bounds transformations and may be transformed in-place by BlMatrix2D and BlMatrix3D"
I add: There are plenty kinds of bounds that can be calculated on elements
- considering stroke outskirts (or not)
- considering children
- considering effects
- coordinates space: local, parent, space
- precise vs. just a fast estimation
No problem with that, it sounds good. The issue is about bounds-related API.
BUT:
Methods that calculate those BlBounds
... there are cases that:
- modify an instance of
BlBounds
received as argument, and also return it - return a new instance that can be updated
- return a new instance that is cached so must be copied before update
- use a
BlBounds
to make calculation but return it converted toRectangle
(and a sender bight re-convert it toBlBounds
to calculate more)
Selectors, code and comment often don't explicit
Examples in BlElement
:
effectBounds
^ (self effectBounds: BlBounds new) asRectangle
boundsInSpace: aBounds
"I load my bounds in space in a given mutable rectangle and return provided one.
I do not rely on cache and always provide actual bounds.
I am a part of internal api, use me with caution"
self boundsInLocal: aBounds.
self localBoundsToGlobal: aBounds.
^ aBounds
invalidationBounds: aBounds
"Compute the bounds of self, including my children recursively, in my local
coordinates that would be invalidated if #invalidate would be sent to me."
| anInvalidationBounds |
anInvalidationBounds := (self effectBounds: aBounds) merge: self boundsInLocal.
(self clipChildren and: [ self hasChildren ]) ifFalse: [
| aChildBounds |
aChildBounds := BlBounds new.
self children do: [ :anElement |
anElement invalidationBounds: aChildBounds.
anElement localBoundsToParent: aChildBounds.
anInvalidationBounds merge: aChildBounds ] ].
^ anInvalidationBounds
Ideas:
-
effectBounds
either don't convert to Rectangle, or call iteffectRectangle
-
boundsInSpace:
may beaddBoundsInSpaceInto:
or alternative prefixes: load or compute; alternative suffix:On:
like inprintOn:
-
localBoundsToParent:
could betransformBoundsToParent:
@plantec @labordep ?
I agree, I find these names confusing too. And we should avoid Rectangle computation as much as possible