private void updateMinMax() { Arrays.fill( min, Double.POSITIVE_INFINITY ); Arrays.fill( max, Double.NEGATIVE_INFINITY ); for ( double[] vertex : vertices ) { expandMinMax( vertex, vertex ); } }
@Override public void addVertex( final int index, final RealLocalizable vertex ) { if ( vertex.numDimensions() < n ) throw new IllegalArgumentException( "Vertex must have at least" + n + " dimensions" ); final double[] p = new double[ n ]; for ( int d = 0; d < n; d++ ) p[ d ] = vertex.getDoublePosition( d ); vertices.add( index, p ); expandMinMax( p, p ); }
@Override public void addVertices( int index, Collection< RealLocalizable > newVertices ) { // add the vertices vertices.addAll( index, newVertices.stream().map( vertex -> { if ( vertex.numDimensions() < n ) throw new IllegalArgumentException( "Vertex must have at least" + n + " dimensions" ); final double[] p = new double[ n ]; for ( int d = 0; d < n; d++ ) p[ d ] = vertex.getDoublePosition( d ); return p; } ).collect( Collectors.toList() ) ); // expand the bounds int offset = index; for ( int i = 0; i < newVertices.size(); i++ ) { final double[] vertex = vertices.get( offset++ ); expandMinMax( vertex, vertex ); } }