Conversation
Constants - Add WORLD_ZOOM = 16, WORLD_SIZE = 256 * 2^WORLD_ZOOM, WORLD_HALF, ANGLE_EPSILON = 1e-12 - Replace magic number 16777216 with WORLD_SIZE throughout Viewport, Tiler, and tests Types - Add Vec4 type alias for [number, number, number, number] - Fix Extent.rectangle() return type to Vec4 (closes #301) Overloads / scalar fast-paths (avoid tuple allocation in hot loops) - vecDot: scalar overload (ax, ay, bx, by) - vecCross: scalar overload (ax, ay, bx, by) - vecLengthSquare: scalar overload (ax, ay) and (ax, ay, bx, by) - geoSphericalDistance: scalar overload (lon1, lat1, lon2, lat2) - geomLineIntersection: scalar 4-point overload; remove private _geomLineIntersection - geomPathIntersections / geomPathHasIntersections use 4-point overload - geomRotatePoints: precompute trig, inline scalar rotation - geoSphericalClosestPoint: use scalar geoSphericalDistance in loop - vecProject: use scalar vecDot in hot path Modernization - Replace Math.pow with ** throughout Transform - Constructor accepts Partial<TransformProps> - Snap near-zero and near-TAU rotation to 0 using ANGLE_EPSILON after numWrap Viewport / Tiler - Skip vecRotate when |rotation| <= ANGLE_EPSILON (epsilon-gated fast path) - Normalize sin/cos to zero in visibleDimensions / visiblePolygon when near-zero - Fix visibleDimensions assertion indexing and expected diagonal-rotation values Dependencies - Move @types/geojson to packages/math (correct ownership)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A focused quality and performance pass over the
@rapid-sdk/mathpackage.Constants
WORLD_ZOOM = 16,WORLD_SIZE = 256 * 2^WORLD_ZOOM,WORLD_HALF,ANGLE_EPSILON = 1e-1216777216withWORLD_SIZEthroughoutViewport,Tiler, and testsTypes
Vec4type alias for[number, number, number, number]Extent.rectangle()return type toVec4closes #301
Overloads / scalar fast-paths
Avoids tuple allocation in hot loops:
vecDot: scalar overload(ax, ay, bx, by)vecCross: scalar overload(ax, ay, bx, by)vecLengthSquare: scalar overloads(ax, ay)and(ax, ay, bx, by)geoSphericalDistance: scalar overload(lon1, lat1, lon2, lat2)geomLineIntersection: scalar 4-point overload; removes private_geomLineIntersectiongeomPathIntersections/geomPathHasIntersectionsuse 4-point overloadgeomRotatePoints: precomputes trig, inlines scalar rotationgeoSphericalClosestPoint: uses scalargeoSphericalDistancein loopvecProject: uses scalarvecDotin hot pathModernization
Math.powwith**throughoutTransform
Partial<TransformProps>TAUrotation to0usingANGLE_EPSILONafternumWrapViewport / Tiler
vecRotatewhen|rotation| <= ANGLE_EPSILON(epsilon-gated fast path)visibleDimensions/visiblePolygonwhen near-zerovisibleDimensionsassertion indexing and expected diagonal-rotation valuesDependencies
@types/geojsontopackages/math(correct ownership)