Comments (5)
But this convert is pretty straightforward:
let array = [[[1,1],[1,3],[2,3],[2,1]], [[2,2], [2,3], [4,3], [4,2]]];
const polygon = new Polygon();
for (let points of array) {
let face = polygon.addFace(points.map(([x, y]) => new Point(x, y)));
}
Do you think it is not enough?
from flatten-js.
That doesn't work for both. The point is though, that this is probably an extremely common process, so there should be a method to handle it so the load to switch to Flatten is even easier. Here is my code:
shapeafy(poly, shape=null){
//only pass in a multi-level array for poly, don't pass in shape. it returns the Flatten.js polygon object
if(!shape){
shape = new Polygon()
}
if(poly[0][0].length === undefined){
const face = poly.map(p=> new Point(p))
shape.addFace(face)
} else {
poly.forEach(arr=>this.shapeafy(arr, shape))
}
if(shape.isValid()){
return shape
} else {
throw new Error("The shape is not valid: " + JSON.stringify(poly))
}
}
from flatten-js.
It makes sense. Maybe I will add this ability to the library
from flatten-js.
Available in @flatten-js/core v1.1.0
from flatten-js.
Available in v1.1.0.
Added ability to create polygon using class constructor and transfer array of numeric pairs or array of arrays.
from flatten-js.
Related Issues (20)
- ray and segment intersect HOT 5
- HELP - What is the best way to create parallel segments ? HOT 3
- Adding Point to Vector HOT 3
- Errors export HOT 2
- Cannot cut polygon with MultiLine HOT 3
- Can I merge duplicated edges and merge faces in Polygon? HOT 3
- Segment Wrong points after rotate? HOT 4
- Exported type not found HOT 1
- polygon.intersect() function not working in new version (v1.5.0) HOT 1
- Vector.add(Point) should return a point not a vector HOT 4
- breaking change between compatible semantic versioning releases 1.4.8 and 1.5.0 HOT 2
- Infinite Loop when calling unify for multipolygon with touching faces HOT 6
- [help] polygon.cut error: TypeError: Cannot set properties of undefined (setting 'prev') HOT 4
- Polygon.cut: TypeError: Cannot read properties of undefined (reading 'edge_after') HOT 3
- area() fails on polygon with arcs HOT 2
- Support WKT format HOT 1
- Additional SVG support HOT 1
- `length` and `pointAtLength` for multiline
- Intersection between a line and a multiline
- Point distance to multiline
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flatten-js.