private int getOrAppendVertex ( Coordinate newCoord , Quadtree ptQuad ) { Envelope queryEnv = new Envelope ( newCoord ) ; queryEnv . expandBy ( epsilon ) ; QuadTreeVisitor visitor = new QuadTreeVisitor ( epsilon , newCoord ) ; try { ptQuad . query ( queryEnv , visitor ) ; } catch ( RuntimeException ex ) { //ignore } if ( visitor . getNearest ( ) != null ) { return visitor . getNearest ( ) . index ; } // Not found then // Append to the list and QuadTree EnvelopeWithIndex ret = new EnvelopeWithIndex ( triVertex . size ( ) , newCoord ) ; ptQuad . insert ( queryEnv , ret ) ; triVertex . add ( ret ) ; return ret . index ; }
Compute unique index for the coordinate Index count from 0 to n If the new vertex is closer than distMerge with an another vertex then it will return its index .