-
-
Notifications
You must be signed in to change notification settings - Fork 977
Fix missing constrainOverride setter in TransformHelper.apply
#6642
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
Fix missing constrainOverride setter in TransformHelper.apply
#6642
Conversation
|
Switched to draft. Need to check the failing tests before review. |
constrain setter in TransformHelper.applyconstrain not being passed in clone()
Only set if the transform's constrain differs from its defaultConstrain
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6642 +/- ##
=======================================
Coverage 92.51% 92.52%
=======================================
Files 283 283
Lines 23389 23401 +12
Branches 5068 5071 +3
=======================================
+ Hits 21639 21652 +13
+ Misses 1750 1749 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I originally targeted public apply(thatI: ITransformGetters, constrain?: boolean, forceOverrideZ?: boolean): void {
this._constrain = thatI.constrain;However, this copies We need to set the constrain only if it differs from the default because that indicates it is custom. But we can't get the default from |
|
Unfortunately, this apply/clone is too complicated. But it might be that the way we decided to store the constrain is also complicated... IDK... |
|
Fair. And if we define "apply" as "apply everything from this transform", then the current implementation isn't doing that because it skips the constrain. |
constrain not being passed in clone()constrain(), transformConstrain; fix missing transformConstrain in apply()
|
The design now sets
*This means |
Use defaultConstrain, transformConstrain appropriately
|
Renamed the constrains. Perhaps a bit verbose, but I want to make it clear what is happening with this approach:
*I think I was using "override" incorrectly in my previous comments to describe what |
|
While there might be a different way to solve this, this is probably the most straight forward one. |
transformConstrain -> constrainOverride
|
Names updated:
I previously named the override "transformConstrain" because I read it as "the constrain that transforms the default constrain". But because it belongs to the transform, calling it Let me know if I interpreted your comments correctly. |
constrain(), transformConstrain; fix missing transformConstrain in apply()constrainOverride setter in TransformHelper.apply
| */ | ||
| defaultConstrain: TransformConstrainFunction; | ||
|
|
||
| /** |
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.
Should the above defaultConstrain be part of the interface? I would imagine that this is something more internal...?
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.
Yes, GlobeTransform relies on it being available when it calls it from this.currentTransform (ITransform):
public constructor(options?: TransformOptions) {
this._helper = new TransformHelper({
calcMatrices: () => { this._calcMatrices(); },
defaultConstrain: (center, zoom) => { return this.defaultConstrain(center, zoom); }
...
defaultConstrain: TransformConstrainFunction = (lngLat, zoom) => {
return this.currentTransform.defaultConstrain(lngLat, zoom);
};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.
Not the best design, but I guess it would do.
|
Thanks! This looks good now. |
|
Thanks again for your advice and review! |
…plibre#6642) * Add missing constrain set in TransformHelper.apply * Add CHANGELOG entry for apply fix * Fix lint * Set constrain in clone (not apply) Only set if the transform's constrain differs from its defaultConstrain * Add transform clone tests for custom constrain * Update CHANGELOG * Revert "Update CHANGELOG" This reverts commit cd4673b. * Revert "Add transform clone tests for custom constrain" This reverts commit cc96d8a. * Revert "Set constrain in clone (not apply)" This reverts commit 980e6ec. * Revert "Fix lint" This reverts commit 9974452. * Revert "Add CHANGELOG entry for apply fix" This reverts commit aee339c. * Revert "Add missing constrain set in TransformHelper.apply" This reverts commit e1d8ed1. * Redesign constrain, transformConstrain in Helper Return transformConstrain if defined, otherwise defaultConstrain * Use nullish coalescing operator, not OR * Clearer constrain names; constrain -> getConstrain Use defaultConstrain, transformConstrain appropriately * Clearer internal constrain names -> applyConstrain transformConstrain -> constrainOverride * Add CHANELOG entry --------- Co-authored-by: Harel M <harel.mazor@gmail.com>
Bug
In v5.10.0
transformConstrainis ignored when terrain is enabled. See CodePen example.Terrain relies on cloning the transform, but cloning does not pass the custom
constrain.Problem
The
apply()call inclone()does not setconstrain, meaning cloned transforms don't have the (potentially) custom constrain.If we set the old constrain to the new one, we might actually set an unchanged default constrain. This is a problem when we switch projections because we don't want to set the old default to an unrelated transform. (Mercator's default is different than Globe's, for example).
Proposal
Redesign
constrainandtransformConstrain:transformConstraintoITransformGettersTransformHelper.constrain()to returntransformConstrainif defined, otherwise returndefaultConstrain. We do not overwriteconstrain()and it cannot be set.transformConstraininTransformHelper.apply(), ensuring all transform clones retain the custom constrain.Launch Checklist
CHANGELOG.mdunder the## mainsection.