feat(core) coordinateSystem prop now accepts no-import string constants#10140
feat(core) coordinateSystem prop now accepts no-import string constants#10140Pessimistress merged 6 commits intomasterfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70cdaa0c52
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| default: | ||
| throw new Error(`Invalid coordinateSystem: ${coordinateSystem}`); |
There was a problem hiding this comment.
Normalize
'default' before rejecting coordinate systems
The new default branch now throws for any unrecognized coordinate system, but Layer.project() still forwards this.props.coordinateSystem directly and the layer default is now 'default' (modules/core/src/lib/layer.ts), so calling layer.project(...) on layers that keep the default coordinate system will now throw Invalid coordinateSystem: default. This regresses a public helper for common layer configurations; please normalize 'default' to 'lnglat'/'cartesian' (as projectPosition already does) before this check.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Is the type recast at this point to make it impossible for the string value "default" to make it to this point?
Summary
One my pet peeves with deck.gl is the need to import the COORDINATE_SYSTEM enum. Today such APIs are specified with typescript string constants.
Previously
Now
Refactor
coordinateSystemto use string-valued coordinate system identifiers across the public API and internal runtime paths, while keepingCOORDINATE_SYSTEMas a deprecated compatibility export.Compared to
master, this updates 21 files with 213 insertions and 122 deletions.What Changed
Changed
CoordinateSysteminmodules/core/src/lib/constants.tsfrom numeric literals to a string union:'default''lnglat''meter-offsets''lnglat-offsets''cartesian'Updated
COORDINATE_SYSTEM.*runtime values to those string constants and markedCOORDINATE_SYSTEMas deprecated in favor of direct string usage.Kept
COORDINATE_SYSTEM.IDENTITYas a deprecated alias to cartesian behavior.Switched internal coordinate-system handling from enum comparisons to string comparisons in:
modules/core/src/lib/layer.tsmodules/core/src/shaderlib/project/project-functions.tsmodules/core/src/shaderlib/project/viewport-uniforms.tsmodules/layers/src/bitmap-layer/bitmap-layer.tsmodules/aggregation-layers/src/heatmap-layer/heatmap-layer.tsmodules/layers/src/solid-polygon-layer/solid-polygon-layer.tsmodules/mesh-layers/src/utils/matrix.tsmodules/extensions/src/fp64/fp64-extension.tsAdded an explicit string-to-shader mapping in
modules/core/src/shaderlib/project/viewport-uniforms.tsviagetShaderCoordinateSystem().Updated shader constant generation in:
modules/core/src/shaderlib/project/project.glsl.tsmodules/core/src/shaderlib/project/project.wgsl.tsso shader uniforms still receive numeric coordinate-system IDs even though the runtime API is now string-based.
Updated
modules/core/src/shaderlib/shadow/shadow.tsto compare against shader coordinate-system IDs instead of runtime enum values.Behavior Changes
coordinateSystem,fromCoordinateSystem, and_imageCoordinateSystemnow use string values instead of numeric values.COORDINATE_SYSTEM.LNGLATcontinues to work, but now resolves to strings.COORDINATE_SYSTEM.*being numeric will need to migrate.Docs
coordinateSystemas a string-valued API and list supported string values._imageCoordinateSystemas string-valued."meter-offsets"instead of numeric enum values.Tests
deck.COORDINATE_SYSTEM.*exports strings.COORDINATE_SYSTEM.IDENTITYcartesian behaviorVerification
yarn vitest run --project node test/modules/imports.node.spec.tsyarn vitest run --project headless test/modules/core/shaderlib/project/viewport-uniforms.spec.ts test/modules/core/shaderlib/project/project-functions.spec.ts test/modules/layers/bitmap-layer.spec.ts