UNPKG

@mkerkstra/jsts-cjs

Version:

A CommonJS fork of JSTS: A JavaScript library of spatial predicates and functions for processing geometry

51 lines (50 loc) 1.64 kB
import RelateNodeGraph from '../relate/RelateNodeGraph.js' import RobustLineIntersector from '../../algorithm/RobustLineIntersector.js' export default class ConsistentAreaTester { constructor() { ConsistentAreaTester.constructor_.apply(this, arguments) } static constructor_() { this._li = new RobustLineIntersector() this._geomGraph = null this._nodeGraph = new RelateNodeGraph() this._invalidPoint = null const geomGraph = arguments[0] this._geomGraph = geomGraph } isNodeEdgeAreaLabelsConsistent() { for (let nodeIt = this._nodeGraph.getNodeIterator(); nodeIt.hasNext(); ) { const node = nodeIt.next() if (!node.getEdges().isAreaLabelsConsistent(this._geomGraph)) { this._invalidPoint = node.getCoordinate().copy() return false } } return true } hasDuplicateRings() { for (let nodeIt = this._nodeGraph.getNodeIterator(); nodeIt.hasNext(); ) { const node = nodeIt.next() for (let i = node.getEdges().iterator(); i.hasNext(); ) { const eeb = i.next() if (eeb.getEdgeEnds().size() > 1) { this._invalidPoint = eeb.getEdge().getCoordinate(0) return true } } } return false } isNodeConsistentArea() { const intersector = this._geomGraph.computeSelfNodes(this._li, true, true) if (intersector.hasProperIntersection()) { this._invalidPoint = intersector.getProperIntersectionPoint() return false } this._nodeGraph.build(this._geomGraph) return this.isNodeEdgeAreaLabelsConsistent() } getInvalidPoint() { return this._invalidPoint } }