/** * Adds a <code>Rect</code> to this <code>Rect</code>. * The resulting <code>Rect</code> is the union of the two * rectangles (i.e. the minimum rectangle that contains the two original rectangles) * @param r the specified <code>Rect</code> */ public Rect union(final Rect r) { return new Rect( Math.min(this.minX, r.minX), Math.min(this.minY, r.minY), Math.max(this.maxX, r.maxX), Math.max(this.maxY, r.maxY)); }
@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); } } );
@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")); }
Rectangle2D initialZoom = otfVisConfig.getZoomValue("*Initial*"); if (initialZoom != null) { this.viewBounds = new Rect(initialZoom.getMinX(), initialZoom.getMinY(), initialZoom.getMaxX(), initialZoom.getMaxY());
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));
rect = new QuadTree.Rect((float)clientQ.getMinEasting(), (float)clientQ.getMinNorthing(), (float)clientQ.getMaxEasting(), (float)clientQ.getMaxNorthing());
@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; }
/** * 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); }
@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 reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { if (oldWidth != 0.0f) { double pixelSizeX = (getViewBoundsAsQuadTreeRect().maxX - getViewBoundsAsQuadTreeRect().minX) / oldWidth; double pixelSizeY = (getViewBoundsAsQuadTreeRect().maxY - getViewBoundsAsQuadTreeRect().minY) / oldHeight; this.viewBounds = new QuadTree.Rect(getViewBoundsAsQuadTreeRect().minX, getViewBoundsAsQuadTreeRect().maxY - pixelSizeY * height, getViewBoundsAsQuadTreeRect().minX + pixelSizeX * width, getViewBoundsAsQuadTreeRect().maxY); } oldWidth = width; oldHeight = height; }
public void setTranslateY(double translateY) { this.viewBounds = new Rect(viewBounds.minX, viewBounds.minY + (translateY - this.translateY), viewBounds.maxX, viewBounds.maxY + (translateY - this.translateY)); this.translateY = translateY; } }