rect = rect.scale(5.0, 5.0); if((cachedRect == null) || cachedRect.containsOrEquals(rect)) return cachedResult; Rect intersec = rect.intersection(cachedRect); if(intersec == null) { rect = rect.union(cachedRect); double r3h = rect.maxY -cachedRect.maxY; double r4w = rect.maxX -cachedRect.maxX; if (r1w > 0) rects.add(new Rect(rect.minX,rect.minY,cachedRect.minX,rect.maxY)); if (r4w > 0) rects.add(new Rect(cachedRect.maxX,rect.minY, rect.maxX,rect.maxY)); if (r2h > 0) rects.add(new Rect(cachedRect.minX,rect.minY,cachedRect.maxX,cachedRect.minY)); if (r3h > 0) rects.add(new Rect(cachedRect.minX,cachedRect.maxY,cachedRect.maxX,rect.maxY));
final double nw1 = this.northwest.bounds.calcDistance(x1, y1); if ( nw1 <= maxDistance && nw1 + this.northwest.bounds.calcDistance(x2, y2) <= maxDistance) { this.northwest.getElliptical(x1, y1, x2, y2, maxDistance, values); final double ne1 = this.northeast.bounds.calcDistance(x1, y1); if (ne1 <= maxDistance && ne1 + this.northeast.bounds.calcDistance(x2, y2) <= maxDistance) { this.northeast.getElliptical(x1, y1, x2, y2, maxDistance, values); final double se1 = this.southeast.bounds.calcDistance(x1, y1); if (se1 <= maxDistance && se1 + this.southeast.bounds.calcDistance(x2, y2) <= maxDistance) { this.southeast.getElliptical(x1, y1, x2, y2, maxDistance, values); final double sw1 = this.southwest.bounds.calcDistance(x1, y1); if (sw1 <= maxDistance && sw1 + this.southwest.bounds.calcDistance(x2, y2) <= maxDistance) { this.southwest.getElliptical(x1, y1, x2, y2, maxDistance, values);
/* default */ Collection<T> get(final Rect bounds, final Collection<T> values) { if (this.hasChilds) { if (this.northwest.bounds.intersects(bounds)) { this.northwest.get(bounds, values); } if (this.northeast.bounds.intersects(bounds)) { this.northeast.get(bounds, values); } if (this.southeast.bounds.intersects(bounds)) { this.southeast.get(bounds, values); } if (this.southwest.bounds.intersects(bounds)) { this.southwest.get(bounds, values); } return values; } // no more childs, so we must contain the closest object if (this.leaves != null) { for (Leaf<T> leaf : this.leaves) { if (bounds.containsOrEquals(leaf.x, leaf.y)) { if (leaf.value != null) { values.add(leaf.value); } else { values.addAll(leaf.values); } } } } return values; }
Rectangle2D initialZoom = otfVisConfig.getZoomValue("*Initial*"); if (initialZoom != null) { this.viewBounds = new Rect(initialZoom.getMinX(), initialZoom.getMinY(), initialZoom.getMaxX(), initialZoom.getMaxY());
rect = new QuadTree.Rect((float)clientQ.getMinEasting(), (float)clientQ.getMinNorthing(), (float)clientQ.getMaxEasting(), (float)clientQ.getMaxNorthing());
closest = bestChild.get(x, y, bestDistance); if (bestChild != this.northwest && this.northwest.bounds.calcDistance(x, y) < bestDistance.value) { T value = this.northwest.get(x, y, bestDistance); if (value != null) { closest = value; } if (bestChild != this.northeast && this.northeast.bounds.calcDistance(x, y) < bestDistance.value) { T value = this.northeast.get(x, y, bestDistance); if (value != null) { closest = value; } if (bestChild != this.southeast && this.southeast.bounds.calcDistance(x, y) < bestDistance.value) { T value = this.southeast.get(x, y, bestDistance); if (value != null) { closest = value; } if (bestChild != this.southwest && this.southwest.bounds.calcDistance(x, y) < bestDistance.value) { T value = this.southwest.get(x, y, bestDistance); if (value != null) { closest = value; }
/* default */ Collection<T> get(final double x, final double y, final double maxDistance, final Collection<T> values) { if (this.hasChilds) { if (this.northwest.bounds.calcDistance(x, y) <= maxDistance) { this.northwest.get(x, y, maxDistance, values); if (this.northeast.bounds.calcDistance(x, y) <= maxDistance) { this.northeast.get(x, y, maxDistance, values); if (this.southeast.bounds.calcDistance(x, y) <= maxDistance) { this.southeast.get(x, y, maxDistance, values); if (this.southwest.bounds.calcDistance(x, y) <= maxDistance) { this.southwest.get(x, y, maxDistance, values);
@Override public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); this.textRenderer = new TextRenderer(new Font("SansSerif", Font.PLAIN, 32), true, false); gl.setSwapInterval(0); float[] components = otfVisConfig.getBackgroundColor().getColorComponents(new float[4]); gl.glClearColor(components[0], components[1], components[2], components[3]); gl.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); if (!glInited) { // This method can (and will) be called several times. // (Gl contexts can change without notice.) float minEasting = (float)clientQ.getMinEasting(); float minNorthing = (float)clientQ.getMinNorthing(); float maxNorthing = (float)clientQ.getMaxNorthing(); double aspectRatio = (double) drawable.getSurfaceWidth() / (double) drawable.getSurfaceHeight(); double pixelRatio = (double) drawable.getSurfaceHeight() / (double) (maxNorthing-minNorthing); this.scale = 1.0f / (float) pixelRatio; this.viewBounds = new QuadTree.Rect(minEasting, minNorthing, minEasting + (maxNorthing - minNorthing) * aspectRatio, maxNorthing); if (otfVisConfig.isMapOverlayMode()) { setScale(nearestPowerOfTwo(this.scale)); } int time = this.hostControlBar.getSimTime(); QuadTree.Rect rect = new QuadTree.Rect((float)clientQ.getMinEasting(), (float)clientQ.getMinNorthing(), (float)clientQ.getMaxEasting(), (float)clientQ.getMaxNorthing()); this.currentSceneGraph = this.clientQ.getSceneGraph(time, rect); } marker = GLUtils.createTexture(gl, MatsimResource.getAsInputStream("otfvis/marker.png")); currentSceneGraph.glInit(); glInited = true; }
/* default */ int execute(final Rect globalBounds, final Executor<T> executor) { int count = 0; if (this.hasChilds) { if (this.northwest.bounds.intersects(globalBounds)) { count += this.northwest.execute(globalBounds, executor); if (this.northeast.bounds.intersects(globalBounds)) { count += this.northeast.execute(globalBounds, executor); if (this.southeast.bounds.intersects(globalBounds)) { count += this.southeast.execute(globalBounds, executor); if (this.southwest.bounds.intersects(globalBounds)) { count += this.southwest.execute(globalBounds, executor); if (globalBounds.contains(leaf.x, leaf.y)) { if (leaf.value != null) { count++;
/** * Computes the intersection of this <code>Rect</code> with the * specified <code>Rect</code>. Returns a new <code>Rect</code> * that represents the intersection of the two rectangles. * If the two rectangles do not intersect, the result will be * null. * * @param r the specified <code>Rectangle</code> * @return the largest <code>Rectangle</code> contained in both the * specified <code>Rectangle</code> and in * this <code>Rectangle</code>; or if the rectangles * do not intersect, an empty rectangle. */ public Rect intersection(final Rect r) { double tx1 = this.minX; double ty1 = this.minY; double tx2 = this.maxX; double ty2 = this.maxY; if (this.minX < r.minX) tx1 = r.minX; if (this.minY < r.minY) ty1 = r.minY; if (tx2 > r.maxX) tx2 = r.maxX; if (ty2 > r.maxY) ty2 = r.maxY; // did they intersect at all? if(tx2-tx1 <=0.f || ty2-ty1 <= 0.f) return null; return new Rect(tx1, ty1, tx2, ty2); }
/** * Associates the specified value with the specified coordinates in this * QuadTree. * * @param x x-coordinate where the specified value is to be associated. * @param y y-coordinate where the specified value is to be associated. * @param value value to be associated with the specified coordinates. * * @return true if insertion was successful and the data structure changed, * false otherwise. */ public boolean put(final double x, final double y, final T value) { if (!this.top.bounds.containsOrEquals(x, y)) { throw new IllegalArgumentException("cannot add a point at x=" + x + ", y=" + y + " with bounds " + this.top.bounds); } if (this.top.put(x, y, value)) { incrementSize(); return true; } return false; }
@Test public void testGetRect_flatNetwork() { QuadTree<String> qt = new QuadTree<>(0, 0, 1000, 0); qt.put(0, 0, "node1"); qt.put(100, 0, "node2"); qt.put(500, 0, "node3"); qt.put(900, 0, "node4"); Collection<String> values = new ArrayList<>(); qt.getRectangle(new Rect(90, -10, 600, +10), values); Assert.assertEquals(2, values.size()); Assert.assertTrue(values.contains("node2")); Assert.assertTrue(values.contains("node3")); Collection<String> values2 = new ArrayList<>(); qt.getRectangle(new Rect(90, 0, 600, 0), values2); Assert.assertEquals(2, values2.size()); Assert.assertTrue(values2.contains("node2")); Assert.assertTrue(values2.contains("node3")); }
@Override public void installQuery(SimulationViewForQueries simulationView) { this.result = new Result(); OTFServerQuadTree quad = simulationView.getNetworkQuadTree(); double regionWidth = (quad.getMaxEasting()-quad.getMinEasting())*0.1; double regionHeight = (quad.getMaxNorthing()-quad.getMinNorthing())*0.1; QuadTree.Rect rect; if (width == 0) { rect = new QuadTree.Rect(sx-regionWidth, sy-regionHeight, sx+regionWidth, sy+regionHeight); } else { rect = new QuadTree.Rect(sx,sy,sx+width,sy+height); } quad.execute(rect, new AddIdStringExecutor(width == 0)); }
public Node(final double minX, final double minY, final double maxX, final double maxY) { this.bounds = new Rect(minX, minY, maxX, maxY); }
/** * Increases the size of the rectangle by scaleX and scaleY. * * (and "increase by" means: * 1.0: increase it by 100% (scale it by 2.0) * -0.5: decrease it by 50% (scale it by 0.5) * 0.0: do nothing) michaz * */ public Rect scale(double scaleX, double scaleY) { scaleY *= this.centerY - this.minY; scaleX *= this.centerX - this.minX; return new Rect(this.minX - scaleX, this.minY-scaleY, this.maxX + scaleX, this.maxY + scaleY); }
/** * Gets all objects inside the specified area. Objects on the border of * the area are not included. * * @param minX The minimum left-right location, longitude * @param minY The minimum up-down location, latitude * @param maxX The maximum left-right location, longitude * @param maxY The maximum up-down location, latitude * @param values1 A collection to store the found objects in. * @return The objects found within the area. */ public Collection<T> getRectangle(final double minX, final double minY, final double maxX, final double maxY, final Collection<T> values1) { return getRectangle(new Rect(minX, minY, maxX, maxY), values1); }
/** * Executes executor on all objects inside the rectangle (minX,minY):(maxX,maxY) * * @param minX The minimum left-right location, longitude * @param minY The minimum up-down location, latitude * @param maxX The maximum left-right location, longitude * @param maxY The maximum up-down location, latitude * @param executor is executed on the fitting objects * @return the count of objects found within the rectangle. */ public int execute(final double minX, final double minY, final double maxX, final double maxY, final Executor<T> executor) { return execute(new Rect(minX, minY, maxX, maxY), executor); }
@Test public void testGetRect() { QuadTree<String> qt = new QuadTree<>(0, 0, 1000, 1000); qt.put(100, 200, "node1"); qt.put(400, 900, "node2"); qt.put(700, 300, "node3"); qt.put(900, 400, "node4"); Collection<String> values = new ArrayList<>(); qt.getRectangle(new Rect(400, 300, 700, 900), values); Assert.assertEquals(2, values.size()); Assert.assertTrue(values.contains("node2")); Assert.assertTrue(values.contains("node3")); }
public void setTranslateX(double translateX) { this.viewBounds = new Rect(viewBounds.minX + (translateX - this.translateX), viewBounds.minY, viewBounds.maxX + (translateX - this.translateX), viewBounds.maxY); this.translateX = translateX; }
@Override public void actionPerformed( ActionEvent e ) { int num = Integer.parseInt(e.getActionCommand()); OTFOGLDrawer.this.lastZoom = zooms.get(num); Rectangle2D viewBounds1 = OTFOGLDrawer.this.lastZoom.getZoomstart(); OTFOGLDrawer.this.viewBounds = new Rect(viewBounds1.getMinX(), viewBounds1.getMinY(), viewBounds1.getMaxX(), viewBounds1.getMaxY()); OTFOGLDrawer.this.zoomD.setVisible(false); } } );