/** * @param displayHeight the height of the window * @return the height of the screenshot */ public int getHeight(int displayHeight) { if (multiplier == 0) { return height; } else { return TeraMath.floorToInt(displayHeight * multiplier); } }
public void setChunkSize(Vector3i chunkSize) { this.chunkFilterSize = new Vector3i(TeraMath.ceilPowerOfTwo(chunkSize.x) - 1, TeraMath.ceilPowerOfTwo(chunkSize.y) - 1, TeraMath.ceilPowerOfTwo(chunkSize.z) - 1); this.chunkPower = new Vector3i(TeraMath.sizeOfPower(chunkSize.x), TeraMath.sizeOfPower(chunkSize.y), TeraMath.sizeOfPower(chunkSize.z)); Vector3i blockMin = new Vector3i(); blockMin.sub(offset); blockMin.mul(chunkSize.x, chunkSize.y, chunkSize.z); Vector3i blockSize = chunkRegion.size(); blockSize.mul(chunkSize.x, chunkSize.y, chunkSize.z); this.blockRegion = Region3i.createFromMinAndSize(blockMin, blockSize); }
int xInt = (int) TeraMath.fastFloor(posX) & 255; int yInt = (int) TeraMath.fastFloor(posY) & 255; int zInt = (int) TeraMath.fastFloor(posZ) & 255; float x = posX - TeraMath.fastFloor(posX); float y = posY - TeraMath.fastFloor(posY); float z = posZ - TeraMath.fastFloor(posZ); float u = TeraMath.fadePerlin(x); float v = TeraMath.fadePerlin(y); float w = TeraMath.fadePerlin(z); int a = noisePermutations[xInt] + yInt; int aa = noisePermutations[a] + zInt; float gradBB = grad(noisePermutations[bb], x - 1, y - 1, z); float val1 = TeraMath.lerp(TeraMath.lerp(gradAA, gradBA, u), TeraMath.lerp(gradAB, gradBB, u), v); float gradBB1 = grad(noisePermutations[(bb + 1)], x - 1, y - 1, z - 1); float val2 = TeraMath.lerp(TeraMath.lerp(gradAA1, gradBA1, u), TeraMath.lerp(gradAB1, gradBB1, u), v); return TeraMath.lerp(val1, val2, w);
@Override public void process(GeneratingRegion region) { SurfaceHeightFacet facet = region.getRegionFacet(SurfaceHeightFacet.class); float[] noise = riverNoise.noise(facet.getWorldRegion()); float[] surfaceHeights = facet.getInternal(); for (int i = 0; i < noise.length; ++i) { surfaceHeights[i] += configuration.maxDepth * TeraMath.clamp(7f * (TeraMath.sqrt(Math.abs(noise[i] * 2.11f)) - 0.1f) + 0.25f); } }
@Override public Vector2i getPreferredContentSize(Canvas canvas, Vector2i areaHint) { Vector2i availableSize = new Vector2i(areaHint); int numRows = TeraMath.ceilToInt((float) widgetList.size() / columns); if (numRows > 0) { availableSize.y = Math.max(1, availableSize.y - verticalSpacing * (numRows - 1)); size.x = Math.max(size.x, TeraMath.floorToInt(columnSizes[i] / columnWidths[i]));
@Override public void onMouseDrag(NUIMouseDragEvent event) { if (sliderWidth > 0) { Vector2i pos = event.getRelativeMousePosition(); int maxSlot = TeraMath.floorToInt(getRange() / getIncrement()); int slotWidth = sliderWidth / maxSlot; int nearestSlot = maxSlot * (pos.x - offset.x + slotWidth / 2) / sliderWidth; nearestSlot = TeraMath.clamp(nearestSlot, 0, maxSlot); float newValue = TeraMath.clamp(getIncrement() * nearestSlot, 0, getRange()) + getMinimum(); setValue(newValue); } } };
public static int packColor(float r, float g, float b, float a) { int iR = (int) (TeraMath.clamp(r, 0.0f, 1.0f) * 255.0f); int iG = (int) (TeraMath.clamp(g, 0.0f, 1.0f) * 255.0f); int iB = (int) (TeraMath.clamp(b, 0.0f, 1.0f) * 255.0f); int iA = (int) (TeraMath.clamp(a, 0.0f, 1.0f) * 255.0f); return iA << 24 | iB << 16 | iG << 8 | iR; } }
public static Direction inDirection(int x, int y, int z) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(y)) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(z)) { return (x > 0) ? LEFT : RIGHT; } } else if (TeraMath.fastAbs(y) > TeraMath.fastAbs(z)) { return (y > 0) ? UP : DOWN; } return (z > 0) ? FORWARD : BACKWARD; }
columnWidth = Math.max(columnWidth, maxSize.x); size.x = TeraMath.addClampAtMax(size.x, columnWidth); if (columns.hasNext()) { size.x = TeraMath.addClampAtMax(size.x, horizontalSpacing); height = Math.min(height, TeraMath.floorToInt(rowSizes[i] / rowHeights[i]));
@Override public void update(final float delta) { movingAvgDelta = TeraMath.lerp(movingAvgDelta, delta, 0.05f); for (ParticleEmitterComponent registeredParticleSystem : ImmutableList.copyOf(registeredParticleSystems)) { updateParticleSystem(registeredParticleSystem, delta); } }
/** * Calculates a standardized normal distributed value (using the polar method). * * @return The value */ public double nextGaussian() { double q = Double.MAX_VALUE; double u1 = 0; double u2; while (q >= 1d || q == 0) { u1 = nextDouble(-1.0, 1.0); u2 = nextDouble(-1.0, 1.0); q = TeraMath.pow(u1, 2) + TeraMath.pow(u2, 2); } double p = Math.sqrt(-2d * Math.log(q) / q); return u1 * p; // or u2 * p }
@Override public int getNumMipmaps() { return TeraMath.sizeOfPower(tileSize) + 1; }
@Test public void testCeilPowerOfTwo() { List<Integer> powersOfTwo = generateAllPowersOfTwo(); for (int i = 1; i < powersOfTwo.size(); i++) { //test inputs on and around powers of two. Skips tests on zero testCeilPowerOfTwo(powersOfTwo.get(i - 1), powersOfTwo.get(i)); } int largestIntegerPowerOfTwo = powersOfTwo.get(powersOfTwo.size() - 1); //test other boundary values assertEquals("0", 0, TeraMath.ceilPowerOfTwo(0)); assertEquals("-1", 0, TeraMath.ceilPowerOfTwo(0)); assertEquals("Integer.MIN_VALUE", 0, TeraMath.ceilPowerOfTwo(Integer.MIN_VALUE)); assertEquals("Integer.MAX_VALUE", 0, TeraMath.ceilPowerOfTwo(Integer.MAX_VALUE)); assertEquals("Largest integer power of two + 1", 0, TeraMath.ceilPowerOfTwo(largestIntegerPowerOfTwo + 1)); }
public Vector2i grow(org.terasology.math.geom.Vector2i size) { // Note protection against overflow return new Vector2i(TeraMath.addClampAtMax(size.x, getTotalWidth()), TeraMath.addClampAtMax(size.y, getTotalHeight())); }
@Override public Vector2i getPreferredContentSize(Canvas canvas, Vector2i areaHint) { Vector2i availableSize = new Vector2i(areaHint); int numColumns = TeraMath.ceilToInt((float) widgetList.size() / rows); if (numColumns > 0) { availableSize.x -= horizontalSpacing * (numColumns - 1); size.y = Math.max(size.y, TeraMath.floorToInt(rowSizes[i] / rowHeights[i]));
@Override public void onMouseDrag(NUIMouseDragEvent event) { if (sliderWidth > 0) { Vector2i pos = event.getRelativeMousePosition(); int maxSlot = TeraMath.floorToInt(getRange() / getIncrement()); int slotWidth = sliderWidth / maxSlot; int nearestSlot = maxSlot * (pos.x - offset.x + slotWidth / 2) / sliderWidth; nearestSlot = TeraMath.clamp(nearestSlot, 0, maxSlot); float newValue = TeraMath.clamp(getIncrement() * nearestSlot, 0, getRange()) + getMinimum(); setValueRight(newValue); } } };
/** * @param luminance the light level produced by this block */ public void setLuminance(byte luminance) { this.luminance = (byte) TeraMath.clamp(luminance, 0, ChunkConstants.MAX_LIGHT); }
public static Side inDirection(int x, int y, int z) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(y)) { if (TeraMath.fastAbs(x) > TeraMath.fastAbs(z)) { return (x > 0) ? RIGHT : LEFT; } } else if (TeraMath.fastAbs(y) > TeraMath.fastAbs(z)) { return (y > 0) ? TOP : BOTTOM; } return (z > 0) ? BACK : FRONT; }
rowHeight = Math.max(rowHeight, maxSize.y); size.y = TeraMath.addClampAtMax(size.y, rowHeight); if (rows.hasNext()) { size.y = TeraMath.addClampAtMax(size.y, verticalSpacing); width = Math.min(width, TeraMath.floorToInt(columnSizes[i] / columnWidths[i]));