StandardGISGridSet extends AbstractGISGridSet<P> { @Override public boolean add(P point) { if (this.grid.addElement(point)) { updateComponentType(point); return true; } return false; } StandardGISGridSet(int nRows, int nColumns, Rectangle2d bounds);  StandardGISGridSet(int nRows, int nColumns, double boundsX, double boundsY, double boundsWidth, double boundsHeight); @Override boolean add(P point);  }
@Test public void testAddAll() { this.reference.clear(); this.reference.add(new MapPoint(1000,1000)); this.reference.add(new MapPoint(0,0)); this.reference.add(new MapPoint(501,801)); this.reference.add(new MapPoint(500,800)); this.reference.add(new MapPoint(502,802)); this.reference.add(new MapPoint(100,800)); this.reference.add(new MapPoint(800,0)); Rectangle2d bounds = new Rectangle2d(); List<Point2d> transformed = new ArrayList<>(); for (final GISPrimitive it : this.reference) { transformed.add(((MapPoint) it).getPoint()); } bounds.setFromPointCloud(transformed); StandardGISGridSet<GISPrimitive> test = new StandardGISGridSet<>(100, 100, bounds); assertTrue(test.addAll(this.reference)); int nb = 0; for(GISPrimitive p : test) { assertTrue(this.reference.contains(p)); ++nb; } assertEquals(this.reference.size(), nb); }
@Test public void testAddE() { StandardGISGridSet<GISPrimitive> test = new StandardGISGridSet<>(100,100,this.worldBounds); assertTrue(test.addAll(this.reference)); assertEquals(this.reference.size(), test.size()); String msg; Random rnd = new Random(); int testCount = rnd.nextInt(5)+1; for(int i=0; i<testCount; ++i) { msg = "test "+(i+1)+"/"+testCount; getLogger().info(msg+"..."); double x = this.worldBounds.getMinX() + rnd.nextDouble() * this.worldBounds.getWidth(); double y = this.worldBounds.getMinY() + rnd.nextDouble() * this.worldBounds.getHeight(); GISPrimitive newElement = new MapPoint(x,y); assertTrue(this.reference.add(newElement)); assertTrue(test.add(newElement), msg); assertEquals(this.reference.size(), test.size(), msg); assertTrue(test.slowContains(newElement), msg); assertEpsilonEquals(this.reference.toArray(),test.toArray(), msg); getLogger().info("done"); } }
@Test public void testIteratorRectangle() { StandardGISGridSet<GISPrimitive> test = new StandardGISGridSet<>(100,100,this.worldBounds); test.addAll(this.reference); assertEquals(this.reference.size(), test.size()); Random rnd = new Random(); int testCount = rnd.nextInt(20)+10; Rectangle2d bounds; Collection<GISPrimitive> inter = new TreeSet<>(new Comparator<GISPrimitive>() { @Override public int compare(GISPrimitive o1, GISPrimitive o2) { return System.identityHashCode(o2) - System.identityHashCode(o1); } }); Iterator<GISPrimitive> iter; int deltaX,deltaY,width,height; String msg; for(int idxTest=0; idxTest<testCount; ++idxTest) { msg = "test "+(idxTest+1)+"/"+testCount; getLogger().info(msg+"..."); deltaX = rnd.nextInt(1000)*(rnd.nextBoolean() ? -1 : 1); deltaY = rnd.nextInt(1000)*(rnd.nextBoolean() ? -1 : 1); width = rnd.nextInt(100); height = rnd.nextInt(100); bounds = new Rectangle2d(); bounds.setFromCorners( this.center.getX()+deltaX, this.center.getY()+deltaY, this.center.getX()+deltaX+width, this.center.getY()+deltaY+height); inter.clear(); for (GISPrimitive primitive : this.reference) { Shape2d<?> primitiveRect = primitive.getGeoLocation().toBounds2D(); if (bounds.intersects(primitiveRect)) { inter.add(primitive); } } iter = test.iterator(bounds); GISPrimitive primitive; while (iter.hasNext()) { primitive = iter.next(); assertTrue(inter.remove(primitive), msg); } if (!inter.isEmpty()) { for (GISPrimitive pr: this.reference) { Shape2d<?> primitiveRect = pr.getGeoLocation().toBounds2D(); if (bounds.intersects(primitiveRect)) { inter.add(pr); } } iter = test.iterator(bounds); while (iter.hasNext()) { primitive = iter.next(); assertTrue(inter.remove(primitive), msg); } } getLogger().info("done"); } }