bjornharrtell / jsts

JavaScript Topology Suite
http://bjornharrtell.github.io/jsts/
Other
1.49k stars 232 forks source link

Can not construct Prepared Geometries. #479

Open motto76 opened 2 years ago

motto76 commented 2 years ago

Each of the 3 Subclasses of BasicPreparedGeometry throw an Error if you call the constructor.

_TypeError: Cannot read properties of undefined (reading 'apply') at Function.getCoordinates (node_modules/jsts/org/locationtech/jts/geom/util/ComponentCoordinateExtracter.js:16:10) at PreparedPolygon.apply (node_modules/jsts/org/locationtech/jts/geom/prep/BasicPreparedGeometry.js:13:60) at new BasicPreparedGeometry (node_modules/jsts/org/locationtech/jts/geom/prep/BasicPreparedGeometry.js:6:40) at new PreparedPolygon (nodemodules/jsts/org/locationtech/jts/geom/prep/PreparedPolygon.js:13:5)

Testcase

it(' Fail PreparedPolygon' ,() => {
const gf = new GeometryFactory()
const reader = new WKTReader(gf)
const poly = reader.read('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))')
PreparedGeometryFactory.prepare(geom)
}

If you put a LineString or a Point in it, it fails as well.

To fix it simply call the super constructor with the given geometry.

PreparedPolygon:

constructor() {
    super(arguments[0])
    PreparedPolygon.constructor_.apply(this, arguments)
}
bjornharrtell commented 2 years ago

Interesting. But is there an actual use case for PreparedPolygon in JSTS? They are a performance enchantment for some usage in the original JTS but I would not assume those carry over in the transpilation.

motto76 commented 2 years ago

Actually there is no use case. We are just porting good old java Code and stumpling across this. We haven't done any performance testing yet either.

bjornharrtell commented 2 years ago

Ok so then I'll leave it as a possbible future nice to have. ;)

MikkoSteerpath commented 1 year ago

I noticed the lack of perpared geometries as well trying to use the intersects() method. For what its worth, it looks like the prepared polygon's intersects() uses two spatial indexes, one for checking if the other geometrys points are inside or outside the polygon, as well as a spatial segment index for finding intersections that touch the the polygon. I would imagine the performance advantages of using the spatial indexes would also carry over to this transpiled version.