Git Product home page Git Product logo

Comments (5)

alexbol99 avatar alexbol99 commented on July 30, 2024

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.

frastlin avatar frastlin commented on July 30, 2024

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.

alexbol99 avatar alexbol99 commented on July 30, 2024

It makes sense. Maybe I will add this ability to the library

from flatten-js.

alexbol99 avatar alexbol99 commented on July 30, 2024

Available in @flatten-js/core v1.1.0

from flatten-js.

alexbol99 avatar alexbol99 commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.