/** * Limits an int to the rgba value range (0-255) * * @param value The value for the r, g, b, or a. * @return An int between 0 - 255. */ public static int constrainValue(int value) { return Ints.constrainToRange(value, MIN_RGB_VALUE, MAX_RGB_VALUE); }
private Color colorAt(int x, int y) { x = Ints.constrainToRange(x, 0, size - 1); y = Ints.constrainToRange(y, 0, size - 1); return new Color(image.getRGB(x, y)); } }
/** * Moves the selector to a specified y coordinate. */ private void moveSelector(int y) { y = Ints.constrainToRange(y, 0, height - 1); if (y == this.selectedY) { return; } this.selectedY = y; paintImmediately(0, 0, PANEL_WIDTH, height); if (this.onColorChange != null) { this.onColorChange.accept(y); } }
public void testConstrainToRange() { assertEquals((int) 1, Ints.constrainToRange((int) 1, (int) 0, (int) 5)); assertEquals((int) 1, Ints.constrainToRange((int) 1, (int) 1, (int) 5)); assertEquals((int) 3, Ints.constrainToRange((int) 1, (int) 3, (int) 5)); assertEquals((int) -1, Ints.constrainToRange((int) 0, (int) -5, (int) -1)); assertEquals((int) 2, Ints.constrainToRange((int) 5, (int) 2, (int) 2)); try { Ints.constrainToRange((int) 1, (int) 3, (int) 2); fail(); } catch (IllegalArgumentException expected) { } }
/** * Moves the target (selector) to a specified x,y coordinates. */ private void moveTarget(int x, int y, boolean shouldUpdate) { if (targetPosition.x == x && targetPosition.y == y && !forceRedraw) { return; } x = Ints.constrainToRange(x, 0, size - 1); y = Ints.constrainToRange(y, 0, size - 1); targetPosition = new Point(x, y); paintImmediately(0, 0, size, size); if (onColorChange != null && shouldUpdate) { onColorChange.accept(colorAt(x, y)); } forceRedraw = false; }
private void moveTarget(int x, boolean shouldUpdate) { value = Ints.constrainToRange(x, ColorUtil.MIN_RGB_VALUE + KNOB_WIDTH, ColorUtil.MAX_RGB_VALUE + KNOB_WIDTH); paintImmediately(0, 0, this.getWidth(), this.getHeight()); if (shouldUpdate && onValueChanged != null) { onValueChanged.accept(getValue()); } }
@Override public MouseEvent mouseDragged(MouseEvent mouseEvent) { if (!inOverlayDraggingMode) { return mouseEvent; } final Point mousePoint = mouseEvent.getPoint(); mousePosition.setLocation(mousePoint); final Rectangle canvasRect = new Rectangle(client.getRealDimensions()); if (!canvasRect.contains(mousePoint)) { return mouseEvent; } if (movedOverlay != null) { final Dimension realDimension = client.getRealDimensions(); mousePoint.translate(-overlayOffset.x, -overlayOffset.y); mousePoint.x = Ints.constrainToRange(mousePoint.x, 0, realDimension.width - movedOverlay.getBounds().width); mousePoint.y = Ints.constrainToRange(mousePoint.y, 0, realDimension.height - movedOverlay.getBounds().height); movedOverlay.setPreferredPosition(null); movedOverlay.setPreferredLocation(mousePoint); mouseEvent.consume(); } return mouseEvent; }
int outerLimit = Ints.constrainToRange(zoomConfig.outerLimit(), ZoomConfig.OUTER_LIMIT_MIN, ZoomConfig.OUTER_LIMIT_MAX); int outerZoomLimit = 128 - outerLimit; intStack[intStackSize - 1] = outerZoomLimit;
value = Ints.constrainToRange(value, min, max);
location.x = Ints.constrainToRange(location.x, 0, realDimensions.width - dimension.width); location.y = Ints.constrainToRange(location.y, 0, realDimensions.height - dimension.height);
throw new IllegalStateException("obj:" + recovered); int recoveredWeight = constrainToRange((int) (initWeight * rate), 1, initWeight); currentWeightMap.put(recovered, recoveredWeight);
public void testConstrainToRange() { assertEquals((int) 1, Ints.constrainToRange((int) 1, (int) 0, (int) 5)); assertEquals((int) 1, Ints.constrainToRange((int) 1, (int) 1, (int) 5)); assertEquals((int) 3, Ints.constrainToRange((int) 1, (int) 3, (int) 5)); assertEquals((int) -1, Ints.constrainToRange((int) 0, (int) -5, (int) -1)); assertEquals((int) 2, Ints.constrainToRange((int) 5, (int) 2, (int) 2)); try { Ints.constrainToRange((int) 1, (int) 3, (int) 2); fail(); } catch (IllegalArgumentException expected) { } }
@Override public void handlePlacement(World world, int turns, BlockPos pos, IStructureBuilder builder) { BlockPos p1 = BlockTools.rotateAroundOrigin(pos1, turns).add(pos); BlockPos p2 = BlockTools.rotateAroundOrigin(pos2, turns).add(pos); BlockPos min = BlockTools.getMin(p1, p2); BlockPos max = BlockTools.getMax(p1, p2); for (int x1 = min.getX(); x1 <= max.getX(); x1++) { for (int y1 = min.getY(); y1 <= max.getY(); y1++) { for (int z1 = min.getZ(); z1 <= max.getZ(); z1++) { world.setBlockToAir(new BlockPos(x1, y1, z1)); } } } Optional<EntityGate> gate = Gate.constructGate(world, p1, p2, Gate.getGateByName(gateType), EnumFacing.HORIZONTALS[Ints.constrainToRange((orientation.getHorizontalIndex() + turns) % 4, 0, 4)], owner.isEmpty() ? Owner.EMPTY : new Owner(world, owner)); if (!gate.isPresent()) { AncientWarfareStructure.LOG.warn("Could not create gate for type: " + gateType); return; } world.spawnEntity(gate.get()); }