-
Notifications
You must be signed in to change notification settings - Fork 944
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
transformScale doesn't always create similar shapes #895
Comments
Thanks for the report @DingoEatingFuzz This is one for you @stebogit :) |
Very interesting... 🤔 |
@DingoEatingFuzz the issue has something to do with the var scaledGrid = turf.featureCollection([]);
scaledGrid.features = processedGrid.features.map(f => {
var factors = f.properties.list.map(ms => (ms - minDate) / dateDiff);
var avgFactor = factors.reduce((sum, n) => sum + n, 0) / factors.length;
return turf.transformScale(f, avgFactor * (maxFactor - minFactor) + minFactor);
})
map.getSource('grid').setData(scaledGrid); |
👍 @stebogit I'll look into this, I might know where the issue is on this one. Also we can add |
Strange one... 🤔 I've been able to get the same "expected" results as @stebogit using a slightly different approach. processedGrid.features = processedGrid.features.map(feature => {
var factors = feature.properties.list.map(ms => (ms - minDate) / dateDiff);
var avgFactor = factors.reduce((sum, n) => sum + n, 0) / factors.length;
var factor = avgFactor * (maxFactor - minFactor) + minFactor;
return turf.transformScale(feature, factor, 'centroid')
}) @stebogit This is the type of "strange" unexpected mutations that @morganherlocker has been advocating, hence why all of the early TurfJS modules don't have Mutate as param since it's hard to control the expected outputs. I initially added the |
@DenisCarriere this is really interesting, I thought it was not possible to map an array to "itself" processedGrid.features = processedGrid.features.map(feature => { I guess JS creates a temporary copy of the array then. Cool! 👍 |
Yep! |
I'm still 🤔 why this issue happening... don't know why this would cause this. |
Maybe |
@stebogit Ok I've been able to make a test case for it. |
OOOOH I got it! I think I've got a fix for this. The scaling happens twice on the |
cloned last vertex in turf-hex-grid; reverted changes in transform-scale; fixed JDoc types;
I believe there's still an issue when passing |
Triangles become scalene and hexagons go concave.
I discovered this while working in Glitch. Here's the project link: https://glitch.com/edit/#!/nosy-flare?path=map.js:96:8
The text was updated successfully, but these errors were encountered: