Skip to content
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

Transform Translate/Rotate method do not recompute bounding box property #2835

Open
hf-farmqa opened this issue Feb 9, 2025 · 0 comments
Open

Comments

@hf-farmqa
Copy link

hf-farmqa commented Feb 9, 2025

Turf version: 7.2.0

Use of the transformTranslate/transformRotate methods seem to simply parrot back the .bbox property of their input feature.
I'm guessing that this generic behavior intended to preserve any/all properties that might have been on the input object.
Unfortunately, this can cause unexpected behavior when used in combination with other turf methods that depend upon or utilize the .bbox property.

Specifically, this became a problem for turf.bbox as of the 7.0.0 release since it will now also just return the .bbox property of an input unless the recompute option is set.

NOTE: Oddly enough, transformScale does not seem to suffer from this behavior

Trivial example:

const bbox = turf.bboxPolygon([-0.1, -0.1, 0.1, 0.1]); // Creates a feature with a top-level .bbox property

const translated = turf.transformTranslate(bbox, 200, 45, { mutate: false});
const scaled = turf.transformScale(bbox, 200, { mutate: false});
const rotated = turf.transformRotate(bbox, 45, { mutate: false });

console.log(turf.bbox(translated));
console.log(turf.bbox(translated, { recompute: true }));
console.log(turf.bbox(scaled));
console.log(turf.bbox(scaled, { recompute: true }));
console.log(turf.bbox(rotated));
console.log(turf.bbox(rotated, { recompute: true }));

Outputs:

// Translated
[-0.1, -0.1, 0.1, 0.1]  
[1.1719128101790375, 1.1718310552975468, 1.371962093942102, 1.3718310552975466]

// Scaled
[-20.418973863263318, -20.000000000000007, 20.418973863263318, 20.00000000000001]
[-20.418973863263318, -20.000000000000007, 20.418973863263318, 20.00000000000001]

// Rotated
[-0.1, -0.1, 0.1, 0.1]
[-0.1414213127535504, -0.14142132033780166, 0.14142138833847184, 0.1414213203377955]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant