Skip to content

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

@hf-farmqa

Description

@hf-farmqa

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions