Java Code Examples for com.badlogic.gdx.math.MathUtils#floor()

The following examples show how to use com.badlogic.gdx.math.MathUtils#floor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HudRenderer.java    From xibalba with MIT License 6 votes vote down vote up
private String createEntityHealth(Entity entity) {
  AttributesComponent attributes = ComponentMappers.attributes.get(entity);

  String healthTextColor = attributes.health < attributes.maxHealth / 2 ? "[RED]" : "[WHITE]";
  String healthText = healthTextColor + attributes.health
      + "[LIGHT_GRAY]/" + attributes.maxHealth;
  StringBuilder healthBar = new StringBuilder("[LIGHT_GRAY]HP [[");

  for (int i = 0; i < MathUtils.floor(attributes.maxHealth / 10); i++) {
    if (attributes.health < (i * 10)) {
      healthBar.append("[DARK_GRAY]x");
    } else {
      healthBar.append("[WHITE]x");
    }
  }

  healthBar.append("[LIGHT_GRAY]]");

  return healthBar + " " + healthText;
}
 
Example 2
Source File: PlotCell3f.java    From Radix with MIT License 6 votes vote down vote up
@Override
public void reset() {
    plotted = 0;

    index.x = MathUtils.floor((pos.x - off.x) / size.x);
    index.y = MathUtils.floor((pos.y - off.y) / size.y);
    index.z = MathUtils.floor((pos.z - off.z) / size.z);

    float ax = index.x * size.x + off.x;
    float ay = index.y * size.y + off.y;
    float az = index.z * size.z + off.z;

    max.x = (sign.x > 0) ? ax + size.x - pos.x : pos.x - ax;
    max.y = (sign.y > 0) ? ay + size.y - pos.y : pos.y - ay;
    max.z = (sign.z > 0) ? az + size.z - pos.z : pos.z - az;
    max.set(max.x / dir.x, max.y / dir.y, max.z / dir.z);
}
 
Example 3
Source File: Player.java    From Radix with MIT License 6 votes vote down vote up
public int getBlockInHead(IWorld world) {
    int x = MathUtils.floor(getPosition().getX());
    int z = MathUtils.floor(getPosition().getZ());
    int y = MathUtils.floor(getPosition().getY() + HEIGHT);
    IChunk chunk = world.getChunk(x, z);
    if (chunk != null) {
        if (y >= world.getHeight()) return 0;
        try {
            return chunk.getBlockId(x & (world.getChunkSize() - 1), y, z & (world.getChunkSize() - 1));
        } catch (BlockStorage.CoordinatesOutOfBoundsException e) {
            e.printStackTrace();
            return 0;
        }
    } else {
        return 0;
    }
}
 
Example 4
Source File: AStartPathFinding.java    From Pacman_libGdx with MIT License 6 votes vote down vote up
public Node findNextNode(Vector2 source, Vector2 target) {
    int sourceX = MathUtils.floor(source.x);
    int sourceY = MathUtils.floor(source.y);
    int targetX = MathUtils.floor(target.x);
    int targetY = MathUtils.floor(target.y);

    if (map == null
           || sourceX < 0 || sourceX >= map.getWidth()
           || sourceY < 0 || sourceY >= map.getHeight()
           || targetX < 0 || targetX >= map.getWidth()
           || targetY < 0 || targetY >= map.getHeight()) {
       return null;
    }
   
    Node sourceNode = map.getNodeAt(sourceX, sourceY);
    Node targetNode = map.getNodeAt(targetX, targetY);
    connectionPath.clear();
    pathfinder.searchConnectionPath(sourceNode, targetNode, heuristic, connectionPath);

    return connectionPath.getCount() == 0 ? null : connectionPath.get(0).getToNode();
}
 
Example 5
Source File: MetadataHeightRenderer.java    From Radix with MIT License 5 votes vote down vote up
@Override
public void renderWest(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    int zi = MathUtils.floor(z1);
    int xi = MathUtils.floor(x);
    int yi = MathUtils.floor(y1);
    IWorld world = RadixClient.getInstance().getWorld();
    IChunk chunk = world.getChunk(xi, zi);
    short meta = 0;
    try {
        meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1));
    } catch (CoordinatesOutOfBoundsException e) {
        e.printStackTrace();
    }
    super.renderWest(atlasIndex, z1, y1, z2, y1 + getHeight(meta), x, lightLevel, pcld, builder);
}
 
Example 6
Source File: MetadataHeightRenderer.java    From Radix with MIT License 5 votes vote down vote up
@Override
public void renderSouth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    int zi = MathUtils.floor(z);
    int xi = MathUtils.floor(x1);
    int yi = MathUtils.floor(y1);
    IWorld world = RadixClient.getInstance().getWorld();
    IChunk chunk = world.getChunk(xi, zi);
    short meta = 0;
    try {
        meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1));
    } catch (CoordinatesOutOfBoundsException e) {
        e.printStackTrace();
    }
    super.renderSouth(atlasIndex, x1, y1, x2, y1 + getHeight(meta), z, lightLevel, pcld, builder);
}
 
Example 7
Source File: MetadataHeightRenderer.java    From Radix with MIT License 5 votes vote down vote up
@Override
public void renderNorth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    int zi = MathUtils.floor(z - 1);
    int xi = MathUtils.floor(x1);
    int yi = MathUtils.floor(y1);
    IWorld world = RadixClient.getInstance().getWorld();
    IChunk chunk = world.getChunk(xi, zi);
    short meta = 0;
    try {
        meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1));
    } catch (CoordinatesOutOfBoundsException e) {
        e.printStackTrace();
    }
    super.renderNorth(atlasIndex, x1, y1, x2, y1 + getHeight(meta), z, lightLevel, pcld, builder);
}
 
Example 8
Source File: MovementHandler.java    From Radix with MIT License 5 votes vote down vote up
public boolean checkDeltaCollision(LivingEntity e, float deltaX, float deltaY, float deltaZ) {
    BoundingBox curBB = e.calculateBoundingBox();
    BoundingBox newBB = new BoundingBox(curBB.min.cpy().add(deltaX, deltaY, deltaZ), curBB.max.cpy().add(deltaX, deltaY, deltaZ));

    boolean collideSuccess = false;

    int x = MathUtils.floor(e.getPosition().x);
    int y = MathUtils.floor(e.getPosition().y);
    int z = MathUtils.floor(e.getPosition().z);

    IChunk chunk = game.getWorld().getChunk(x, z);
    if (chunk == null)
        return true;

    int cx = x & (game.getWorld().getChunkSize() - 1);
    int cz = z & (game.getWorld().getChunkSize() - 1);
    try {
        Block block = chunk.getBlock(cx, y, cz);

        for (Vector3 corner : getCorners(newBB)) {
            collideSuccess = collideSuccess || checkCollision(corner);
        }

        return collideSuccess ||
                (block != null && block.isSolid()
                        && block.calculateBoundingBox(chunk, cx, y, cz).intersects(newBB));
    } catch(CoordinatesOutOfBoundsException ex) {
        ex.printStackTrace();
        return true;
    }
}
 
Example 9
Source File: LivingEntity.java    From Radix with MIT License 5 votes vote down vote up
public int getBlockInFeet(IWorld world) {
    int x = MathUtils.floor(getPosition().getX());
    int y = MathUtils.floor(getPosition().getY());
    int z = MathUtils.floor(getPosition().getZ());
    IChunk chunk = world.getChunk(x, z);
    if (chunk != null && y < world.getHeight()) {
        int cx = x & (world.getChunkSize() - 1);
        int cz = z & (world.getChunkSize() - 1);
        try {
            int id = chunk.getBlockId(cx, y, cz);
            Block block = RadixAPI.instance.getBlock(id);
            if (block == null) return 0;
            BoundingBox blockBox = block.calculateBoundingBox(chunk, cx, y, cz);
            float halfWidth = width / 2f;
            Vector3 bottomBackLeft = getPosition().cpy().add(-halfWidth, 0, -halfWidth);
            Vector3 bottomBackRight = bottomBackLeft.cpy().add(width, 0, 0);
            Vector3 bottomFrontRight = bottomBackRight.cpy().add(0, 0, width);
            Vector3 bottomFrontLeft = bottomBackLeft.cpy().add(width, 0, 0);

            boolean inFeet = blockBox.contains(bottomBackLeft) || blockBox.contains(bottomBackRight) || blockBox.contains(bottomFrontLeft) || blockBox.contains(bottomFrontRight);

            return inFeet ? id : 0;
        } catch (BlockStorage.CoordinatesOutOfBoundsException ex) {
            ex.printStackTrace();
            return 0;
        }
    } else {
        return 0;
    }
}
 
Example 10
Source File: IsometricCamera.java    From riiablo with Apache License 2.0 5 votes vote down vote up
/**
 * Rounds tile coords to the floor integer tile coords from the specified float tile coords.
 */
public Vector2 toTile(float x, float y, Vector2 dst) {
  x += tileOffset.x;
  y += tileOffset.y;
  dst.x = x < 0 ? MathUtils.floor(x) : MathUtils.floorPositive(x);
  dst.y = y < 0 ? MathUtils.floor(y) : MathUtils.floorPositive(y);
  return dst;
}
 
Example 11
Source File: BlockingWindow.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void act(float delta) {
    super.act(delta);
    colorOffset += delta / colorTime;
    float colorListBlend = colorOffset /** (float) colors.size*/;
    int from = MathUtils.floor(colorListBlend);
    int to = MathUtils.ceil(colorListBlend);
    Color fromColor = colors.get(from % colors.size);
    Color toColor = colors.get(to % colors.size);
    setColor(blend(fromColor, toColor, colorListBlend - from));

    scaleOffset += delta / disappearTime;
    setScale(1 - scaleOffset % 1f);
}
 
Example 12
Source File: Dialog9Patch.java    From skin-composer with MIT License 5 votes vote down vote up
private void zoomAndRecenter() {
    pack();
    var widget = (NinePatchWidget) findActor("ninePatchWidget");
    var slider = (Slider) findActor("top-zoom");
    
    var widthRatio = MathUtils.floor(widget.getWidth() / (widget.getRegionWidth() + 4));
    var heightRatio = MathUtils.floor(widget.getHeight() / (widget.getRegionHeight() + 4));
    slider.setValue(Math.min(widthRatio, heightRatio));
    
    widget.setPositionX(-widget.getRegionWidth() / 2.0f);
    widget.setPositionY(-widget.getRegionHeight() / 2.0f);
}
 
Example 13
Source File: HudRenderer.java    From xibalba with MIT License 5 votes vote down vote up
private String createEntityDivineFavor(Entity entity) {
  AttributesComponent attributes = ComponentMappers.attributes.get(entity);

  String divineFavorColor;

  if (attributes.divineFavor <= 0) {
    divineFavorColor = "[RED]";
  } else if (attributes.divineFavor / 100 <= 0.5) {
    divineFavorColor = "[YELLOW]";
  } else {
    divineFavorColor = "[WHITE]";
  }

  String divineFavorText
      = divineFavorColor + Math.round(attributes.divineFavor) + "[LIGHT_GRAY]/100";
  StringBuilder divineFavorBar = new StringBuilder("[LIGHT_GRAY]DF [[");

  for (int i = 0; i < MathUtils.floor(100 / 10); i++) {
    if (attributes.divineFavor < (i * 10)) {
      divineFavorBar.append("[DARK_GRAY]x");
    } else {
      divineFavorBar.append("[WHITE]x");
    }
  }

  divineFavorBar.append("[LIGHT_GRAY]]");

  return divineFavorBar + " " + divineFavorText;
}
 
Example 14
Source File: VectorField.java    From talos with Apache License 2.0 5 votes vote down vote up
public Vector2 getValue(Vector2 pos, Vector2 result) {
    float x = (((pos.x - fieldPos.x) / scale) * 0.5f + 0.5f) * xSize;
    float y = (((pos.y - fieldPos.y) / scale) * 0.5f + 0.5f) * ySize;
    int z = 0;

    if(MathUtils.floor(x) < 0 || MathUtils.ceil(x) > xSize - 1 || MathUtils.floor(y) < 0 || MathUtils.ceil(y) > ySize - 1) {
        result.set(0, 0);
        return result;
    }

    if(MathUtils.floor(x) > xSize - 1 || MathUtils.ceil(x) < 0 || MathUtils.floor(y) > ySize - 1 || MathUtils.ceil(y) < 0) {
        result.set(0, 0);
        return result;
    }

    Vector3 v11 = field[MathUtils.floor(x)][MathUtils.floor(y)][z];
    Vector3 v12 = field[MathUtils.floor(x)][MathUtils.ceil(y)][z];
    Vector3 v22 = field[MathUtils.ceil(x)][MathUtils.ceil(y)][z];
    Vector3 v21 = field[MathUtils.ceil(x)][MathUtils.floor(y)][z];

    float resX = blerp(v11.x, v12.x, v22.x, v21.x, x-(int)x, y-(int)y);
    float resY = blerp(v11.y, v12.y, v22.y, v21.y, x-(int)x, y-(int)y);

    result.set(resX*1f, resY*1f);

    return result;
}
 
Example 15
Source File: ColorUtils.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
/**
 * Converts HSV color system to RGB
 * @param h hue 0-360
 * @param s saturation 0-100
 * @param v value 0-100
 * @param targetColor color that result will be stored in
 * @return targetColor
 */
public static Color HSVtoRGB (float h, float s, float v, Color targetColor) {
	if (h == 360) h = 359;
	int r, g, b;
	int i;
	float f, p, q, t;
	h = (float) Math.max(0.0, Math.min(360.0, h));
	s = (float) Math.max(0.0, Math.min(100.0, s));
	v = (float) Math.max(0.0, Math.min(100.0, v));
	s /= 100;
	v /= 100;
	h /= 60;
	i = MathUtils.floor(h);
	f = h - i;
	p = v * (1 - s);
	q = v * (1 - s * f);
	t = v * (1 - s * (1 - f));
	switch (i) {
		case 0:
			r = MathUtils.round(255 * v);
			g = MathUtils.round(255 * t);
			b = MathUtils.round(255 * p);
			break;
		case 1:
			r = MathUtils.round(255 * q);
			g = MathUtils.round(255 * v);
			b = MathUtils.round(255 * p);
			break;
		case 2:
			r = MathUtils.round(255 * p);
			g = MathUtils.round(255 * v);
			b = MathUtils.round(255 * t);
			break;
		case 3:
			r = MathUtils.round(255 * p);
			g = MathUtils.round(255 * q);
			b = MathUtils.round(255 * v);
			break;
		case 4:
			r = MathUtils.round(255 * t);
			g = MathUtils.round(255 * p);
			b = MathUtils.round(255 * v);
			break;
		default:
			r = MathUtils.round(255 * v);
			g = MathUtils.round(255 * p);
			b = MathUtils.round(255 * q);
	}

	targetColor.set(r / 255.0f, g / 255.0f, b / 255.0f, targetColor.a);
	return targetColor;
}
 
Example 16
Source File: World.java    From Radix with MIT License 4 votes vote down vote up
@Override
public int getChunkPosition(float value) {
    int subtraction = MathUtils.floor(value) & (CHUNK_SIZE-1);
    return MathUtils.floor(value - subtraction);
}
 
Example 17
Source File: PixmapUtils.java    From libgdx-snippets with MIT License 4 votes vote down vote up
/**
 * Sets alpha for all pixels passing the RGB predicate function.
 */
public static void mask(Pixmap pixmap, float alpha, IntPredicate rgb) {

	ByteBuffer pixels = pixmap.getPixels();

	int a = MathUtils.floor(alpha * 255.0f) & 0xff;

	while (pixels.remaining() > 0) {

		int rgba = pixels.getInt();

		if (rgb.test(rgba >>> 8)) {
			pixels.position(pixels.position() - 4);
			pixels.putInt((rgba & 0xffffff00) | a);
		}
	}

	pixels.flip();
}
 
Example 18
Source File: ColorUtils.java    From typing-label with MIT License 4 votes vote down vote up
/**
 * Converts HSV color system to RGB
 *
 * @param h           hue 0-360
 * @param s           saturation 0-100
 * @param v           value 0-100
 * @param targetColor color that result will be stored in
 * @return targetColor
 */
public static Color HSVtoRGB(float h, float s, float v, Color targetColor) {
    if(h == 360) h = 359;
    int r, g, b;
    int i;
    float f, p, q, t;
    h = (float) Math.max(0.0, Math.min(360.0, h));
    s = (float) Math.max(0.0, Math.min(100.0, s));
    v = (float) Math.max(0.0, Math.min(100.0, v));
    s /= 100;
    v /= 100;
    h /= 60;
    i = MathUtils.floor(h);
    f = h - i;
    p = v * (1 - s);
    q = v * (1 - s * f);
    t = v * (1 - s * (1 - f));
    switch(i) {
        case 0:
            r = MathUtils.round(255 * v);
            g = MathUtils.round(255 * t);
            b = MathUtils.round(255 * p);
            break;
        case 1:
            r = MathUtils.round(255 * q);
            g = MathUtils.round(255 * v);
            b = MathUtils.round(255 * p);
            break;
        case 2:
            r = MathUtils.round(255 * p);
            g = MathUtils.round(255 * v);
            b = MathUtils.round(255 * t);
            break;
        case 3:
            r = MathUtils.round(255 * p);
            g = MathUtils.round(255 * q);
            b = MathUtils.round(255 * v);
            break;
        case 4:
            r = MathUtils.round(255 * t);
            g = MathUtils.round(255 * p);
            b = MathUtils.round(255 * v);
            break;
        default:
            r = MathUtils.round(255 * v);
            g = MathUtils.round(255 * p);
            b = MathUtils.round(255 * q);
    }

    targetColor.set(r / 255.0f, g / 255.0f, b / 255.0f, targetColor.a);
    return targetColor;
}
 
Example 19
Source File: GameRenderer.java    From Radix with MIT License 4 votes vote down vote up
private void createDynamicRenderers() {
    float currentHeight = 2;

    String glInfoStr = String.format("%s (%s) [%s]",
            Gdx.gl.glGetString(GL_RENDERER), Gdx.gl.glGetString(GL_VERSION), Gdx.gl.glGetString(GL_VENDOR));
    GlyphLayout glGl = glInfoRender.setText(glInfoStr, 0, 0);
    glInfoRender.setPosition((float) Gdx.graphics.getWidth() - glGl.width, (Gdx.graphics.getHeight() - currentHeight));
    currentHeight += debugTextRenderer.getLineHeight();

    String fpsStr = "FPS: " + String.valueOf(Gdx.graphics.getFramesPerSecond());
    if (RadixClient.getInstance().getSettingsManager().getVisualSettings().getNonContinuous().getValue()) {
        fpsStr = fpsStr.concat(" (NON-CONTINUOUS! INACCURATE!)");
        fpsRender.setColor(Color.RED);
    }

    GlyphLayout fpsGl = fpsRender.setText(fpsStr, 0, 0);
    fpsRender.setPosition((float) Gdx.graphics.getWidth() - fpsGl.width, (Gdx.graphics.getHeight() - currentHeight));
    currentHeight += debugTextRenderer.getLineHeight();

    DecimalFormat posFormat = new DecimalFormat("#.00");
    String coordsStr = String.format("(x,y,z): %s,%s,%s",
            posFormat.format(game.getPlayer().getPosition().getX()),
            posFormat.format(game.getPlayer().getPosition().getY()),
            posFormat.format(game.getPlayer().getPosition().getZ()));
    GlyphLayout posGl = positionRender.setText(coordsStr, 0, 0);
    positionRender.setPosition((float) Gdx.graphics.getWidth() - posGl.width, (Gdx.graphics.getHeight() - currentHeight));
    currentHeight += debugTextRenderer.getLineHeight();

    String chunk = String.format("Chunk (x,z): %s,%s",
            game.getWorld().getChunkPosition(game.getPlayer().getPosition().getX()),
            game.getWorld().getChunkPosition(game.getPlayer().getPosition().getZ()));
    GlyphLayout chunkGl = chunkposRender.setText(chunk, 0, 0);
    chunkposRender.setPosition((float) Gdx.graphics.getWidth() - chunkGl.width,
            (Gdx.graphics.getHeight() - currentHeight));
    currentHeight += debugTextRenderer.getLineHeight();

    String headingStr = String.format("(yaw,pitch): %s,%s",
            posFormat.format(game.getPlayer().getRotation().getYaw()),
            posFormat.format(game.getPlayer().getRotation().getPitch()));
    GlyphLayout headingGl = headingRender.setText(headingStr, 0, 0);
    headingRender.setPosition((float) Gdx.graphics.getWidth() - headingGl.width,
            (Gdx.graphics.getHeight() - currentHeight));
    currentHeight += debugTextRenderer.getLineHeight();

    int playerX = MathUtils.floor(game.getPlayer().getPosition().getX());
    int playerY = MathUtils.floor(game.getPlayer().getPosition().getY());
    int playerZ = MathUtils.floor(game.getPlayer().getPosition().getZ());
    IChunk playerChunk = game.getWorld().getChunk(playerX, playerZ);
    try {
        if (playerChunk != null) {
            String llStr = String.format("Light Level @ Feet: %d",
                    playerChunk.getSunlight(playerX & (game.getWorld().getChunkSize() - 1),
                            playerY, playerZ & (game.getWorld().getChunkSize() - 1)));
            GlyphLayout llGl = lightlevelRender.setText(llStr, 0, 0);
            lightlevelRender.setPosition((float) Gdx.graphics.getWidth() - llGl.width,
                    (Gdx.graphics.getHeight() - currentHeight));
            currentHeight += debugTextRenderer.getLineHeight();
        }
    } catch (BlockStorage.CoordinatesOutOfBoundsException ex) {
        ex.printStackTrace();
    }

    String threadsStr = "Active threads: " + Thread.activeCount();
    GlyphLayout threadsGl = activeThreadsRender.setText(threadsStr, 0, 0);
    activeThreadsRender.setPosition((float) Gdx.graphics.getWidth() - threadsGl.width,
            (Gdx.graphics.getHeight() - currentHeight));

    // Current looked-at block info. Draws next to the crosshair
    String currentBlockStr = "";
    Vec3i cbLoc = game.getSelectedBlock();
    if (cbLoc != null) {
        try {
            Block cbBlk = game.getWorld().getChunk(cbLoc.x, cbLoc.z).getBlock(
                    cbLoc.x & (game.getWorld().getChunkSize() - 1),
                    cbLoc.y,
                    cbLoc.z & (game.getWorld().getChunkSize() - 1)
            );
            if (cbBlk != null) {
                currentBlockStr = String.format(
                        "%s (%d)\n" + // Name (id)
                                "%d%%", // Breaking percentage
                        cbBlk.getHumanName(), cbBlk.getID(),
                        100 - Math.round(game.getPlayer().getBreakPercent() * 100));
            }
        } catch (CoordinatesOutOfBoundsException e) { // Shouldn't happen
            e.printStackTrace();
        }
    }
    selectedBlockRender.setText(currentBlockStr, 0, 0);
    selectedBlockRender.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);

    glDebugRender.setText(String.format("DC: %d, GLC: %d, VTCS: %d, TB: %d, SS: %d",
                    curDC, curGLC, curVTCS, curTB, curSS),
            0, debugTextRenderer.getLineHeight() + 45);
}
 
Example 20
Source File: PixmapUtils.java    From libgdx-snippets with MIT License 4 votes vote down vote up
/**
 * Calculates crop regions of the pixmap in up to four directions. Pixel rows/columns are subject
 * to removal if all their pixels have an alpha channel value of exact the same value as given in the parameter.
 */
public static void crop(Pixmap pixmap,
						boolean left,
						boolean bottom,
						boolean right,
						boolean top,
						float alpha,
						CropResult consumer) {

	int width = pixmap.getWidth();
	int height = pixmap.getHeight();

	int a = MathUtils.floor(alpha * 255.0f) & 0xff;

	int minX = left ? width - 1 : 0;
	int maxX = right ? 0 : width - 1;

	int minY = bottom ? height - 1 : 0;
	int maxY = top ? 0 : height - 1;

	ByteBuffer pixels = pixmap.getPixels();

	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {

			int rgba = pixels.getInt();

			if ((rgba & 0xff) != a) {

				minX = Math.min(x, minX);
				maxX = Math.max(x, maxX);

				minY = Math.min(y, minY);
				maxY = Math.max(y, maxY);
			}
		}
	}

	pixels.flip();

	consumer.accept(minX, minY, maxX, maxY);
}