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

Non-destructive topology creation. #4

Merged
merged 13 commits into from
Mar 31, 2017
Merged

Non-destructive topology creation. #4

merged 13 commits into from
Mar 31, 2017

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Mar 29, 2017

This fixes #2, changing topojson.topology so that it no longer destroys the input objects; instead, shallow copies are made as needed.

This also fixes #3 by removing type reduction: for example, an input MultiPolygon geometry with only a single polygon is no longer reduced to a Polygon, and an input empty MultiLineString geometry is no longer reduced to a null geometry. The output type of a geometry object is always the same as its input type. You can remove null geometries using topojson.filter.

This will be a major version change, released as 3.0.

For the other changes in 3.0, see:

This fixes #2, changing topojson.topology so that it no longer destroys the
input objects. It also fixes #3 by removing type reduction: for example, an
empty MultiLineString geometry on input is now an empty MultiLineString geometry
on output, rather than a null geometry.

Most of the internal implementation is still destructive. This works by changing
the geometry method to make a shallow copy of the input, and by changing the
prequantize method to make a copy of the coordinates.

I’d like to improve this so that prequantize operates on the extracted
coordinates, so that we can avoid the additional copy. This should be possible
in a future commit. (It would also be nice if the intermediate representation
used two typed arrays rather than an array of objects, but I think that will be
more difficult to implement.)
Since topojson.topology was previously destructive, it would delete the
coordinates array and assign a new arcs array. Now that it is non-destructive,
it makes sense to initialize the arcs array when making the geometry object.
However, per the spec, each arc must retain at least two positions, even if the
first and last point are coincident.
@mbostock mbostock self-assigned this Mar 30, 2017
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

Successfully merging this pull request may close these issues.

Disable automatic type reduction? Don’t modify input objects!
1 participant