public Rectangle2 intersect(final ReadOnlyRectangle2 other, final Rectangle2 store) { Rectangle2 rVal = store; if (rVal == null) { rVal = new Rectangle2(); } final int x1 = Math.max(getX(), other.getX()); final int y1 = Math.max(getY(), other.getY()); final int x2 = Math.min(getX() + getWidth(), other.getX() + other.getWidth()); final int y2 = Math.min(getY() + getHeight(), other.getY() + other.getHeight()); rVal.set(x1, y1, x2 - x1, y2 - y1); return rVal; }
final Rectangle2 init = Rectangle2.fetchTempInstance(); init.set(-1, -1, -1, -1); ReadOnlyRectangle2 r; boolean first = true; init.set(r); first = false; } else { init.intersect(r, init); if (init.getWidth() <= 0 || init.getHeight() <= 0) { init.setWidth(0); init.setHeight(0); break; if (init.getWidth() == -1) { setClippingEnabled(rendRecord, false); } else { setClippingEnabled(rendRecord, true); GL11C.glScissor(init.getX(), init.getY(), init.getWidth(), init.getHeight()); Rectangle2.releaseTempInstance(init); } else {
public static Rectangle2 intersect(final ReadOnlyRectangle2 src1, final ReadOnlyRectangle2 src2, final Rectangle2 store) { Rectangle2 rVal = store; if (rVal == null) { rVal = new Rectangle2(); } rVal.set(src1); return rVal.intersect(src2, rVal); }
final Rectangle2 storeA = Rectangle2.fetchTempInstance(); final Rectangle2 storeB = Rectangle2.fetchTempInstance(); final Rectangle2 minRect = comp.getRelativeMinComponentBounds(storeB); if (_horizontal) { comp.fitComponentIn(minRect.getWidth(), rect.getHeight()); } else { comp.fitComponentIn(rect.getWidth(), minRect.getHeight()); final UIComponent comp = comps.remove(0); Rectangle2 rect = comp.getRelativeComponentBounds(storeA); final Rectangle2 origRect = storeB.set(rect); if (freeSpace < 0) { freeSpace = 0; final int height = _expandsVertically ? container.getContentHeight() : rect.getHeight(); final int width = (_expandsHorizontally ? extraPerComp : 0) + rect.getWidth(); if (height == rect.getHeight() && width == rect.getWidth()) { continue; if (Math.abs(rect.getWidth() - width) <= 1) { compsBack.add(comp); freeSpace -= rect.getWidth() - origRect.getWidth(); } else { final int width = _expandsHorizontally ? container.getContentWidth() : rect.getWidth(); final int height = (_expandsVertically ? extraPerComp : 0) + rect.getHeight(); if (height == rect.getHeight() && width == rect.getWidth()) { continue;
@Test public void testGetSet() { final Rectangle2 rect1 = new Rectangle2(); assertTrue(0 == rect1.getX()); assertTrue(0 == rect1.getY()); assertTrue(0 == rect1.getWidth()); assertTrue(0 == rect1.getHeight()); final Rectangle2 rect2 = new Rectangle2(2, 3, 4, 5); assertTrue(2 == rect2.getX()); assertTrue(3 == rect2.getY()); assertTrue(4 == rect2.getWidth()); assertTrue(5 == rect2.getHeight()); rect1.set(rect2); assertTrue(2 == rect1.getX()); assertTrue(3 == rect1.getY()); assertTrue(4 == rect1.getWidth()); assertTrue(5 == rect1.getHeight()); final Rectangle2 rect3 = new Rectangle2(rect1); assertTrue(2 == rect3.getX()); assertTrue(3 == rect3.getY()); assertTrue(4 == rect3.getWidth()); assertTrue(5 == rect3.getHeight()); rect1.set(5, 0, 10, 15); assertTrue(5 == rect1.getX()); assertTrue(0 == rect1.getY()); assertTrue(10 == rect1.getWidth());
@Test public void testIntersect() { final Rectangle2 rect1 = new Rectangle2(0, 0, 10, 10); final Rectangle2 rect2 = new Rectangle2(5, 5, 10, 10); Rectangle2 intersection = rect1.intersect(rect2, Rectangle2.fetchTempInstance()); assertTrue(5 == intersection.getX()); assertTrue(5 == intersection.getY()); assertTrue(5 == intersection.getWidth()); assertTrue(5 == intersection.getHeight()); Rectangle2.releaseTempInstance(intersection); assertNotNull(rect1.intersect(rect2, null)); intersection = Rectangle2.intersect(rect1, rect2, Rectangle2.fetchTempInstance()); assertTrue(5 == intersection.getX()); assertTrue(5 == intersection.getY()); assertTrue(5 == intersection.getWidth()); assertTrue(5 == intersection.getHeight()); Rectangle2.releaseTempInstance(intersection); assertNotNull(Rectangle2.intersect(rect1, rect2, null)); } }
/** * @return true if this frame can be fully contained by the hud. */ public boolean smallerThanWindow() { final int dispWidth = uiFrame.getHud().getWidth(); final int dispHeight = uiFrame.getHud().getHeight(); final Rectangle2 rect = uiFrame.getRelativeComponentBounds(null); return rect.getWidth() <= dispWidth && rect.getHeight() <= dispHeight; }
private void localCopyBuffer(final ByteBuffer dataAsFloatBuffer, final Rectangle2 rectangle, final int xFrom, final int yFrom, final int xTo, final int yTo) { final int componentsTarget = useAlpha ? 4 : 3; final int sourceIndex = ((yFrom + rectangle.getY()) * atlasWidth + xFrom + rectangle.getX()) * componentsTarget; final int targetIndex = ((yTo + rectangle.getY()) * atlasWidth + xTo + rectangle.getX()) * componentsTarget; fillDataBuffer(dataAsFloatBuffer, dataAsFloatBuffer, sourceIndex, targetIndex, useAlpha); }
@Override public void updateMinimumSizeFromContents(final UIContainer container) { int minW = 0, minH = 0; if (container.getNumberOfChildren() > 0) { final List<Spatial> content = container.getChildren(); // compute the min width and height of the container final Rectangle2 store = new Rectangle2(); for (final Spatial s : content) { if (!(s instanceof UIComponent)) { continue; } final UIComponent comp = (UIComponent) s; final Rectangle2 rect = comp.getRelativeMinComponentBounds(store); if (_horizontal) { minW += rect.getWidth(); if (minH < rect.getHeight()) { minH = rect.getHeight(); } } else { if (minW < rect.getWidth()) { minW = rect.getWidth(); } minH += rect.getHeight(); } } } container.setMinimumContentSize(minW, minH); }
final Rectangle2 storeA = Rectangle2.fetchTempInstance(); for (int i = 0; i < content.size(); i++) { final Spatial spat = content.get(i); final UIComponent comp = (UIComponent) spat; final Rectangle2 minRect = comp.getRelativeMinComponentBounds(storeA); comp.fitComponentIn(minRect.getWidth(), minRect.getHeight()); if (comp == _center) { final Rectangle2 rect = comp.getRelativeComponentBounds(storeA); comp.setLocalXY(-rect.getWidth() / 2, -rect.getHeight() / 2); continue; Rectangle2.releaseTempInstance(storeA); return; final int y = (int) MathUtils.round(radius * MathUtils.cos(position)); comp.setLocalXY(x - rect.getWidth() / 2, y - rect.getHeight() / 2); Rectangle2.releaseTempInstance(storeA); _menuDirty = false;
private int getSumOfAllHeights(final List<Spatial> content) { int sum = 0; if (content != null) { final Rectangle2 store = new Rectangle2(); for (final Spatial spat : content) { if (spat instanceof UIComponent) { final Rectangle2 rect = ((UIComponent) spat).getRelativeMinComponentBounds(store); sum += rect.getHeight(); } } } return sum; }
private int getSumOfAllWidths(final List<Spatial> content) { int sum = 0; if (content != null) { final Rectangle2 store = new Rectangle2(); for (final Spatial spat : content) { if (spat instanceof UIComponent) { final Rectangle2 rect = ((UIComponent) spat).getRelativeMinComponentBounds(store); sum += rect.getWidth(); } } } return sum; }
/** * Constructor creates a new <code>Rectangle2</code> using the values of the provided source rectangle. * * @param source * the rectangle to copy from */ public Rectangle2(final ReadOnlyRectangle2 source) { set(source); }
@Override public Rectangle2 clone() { return new Rectangle2(this); }
public int getX() { return _bounds.getX(); }
public int getY() { return _bounds.getY(); }
@Test public void testSimpleHash() { // Just a simple sanity check. final Rectangle2 rect1 = new Rectangle2(1, 2, 0, 0); final Rectangle2 rect2 = new Rectangle2(1, 2, 0, 0); final Rectangle2 rect3 = new Rectangle2(2, 2, 0, 0); assertTrue(rect1.hashCode() == rect2.hashCode()); assertTrue(rect1.hashCode() != rect3.hashCode()); }