public static double fac(RValue x) throws EvaluationException { final int n = (int) x.getValue(); if (n < 0) { return 0; } if (n >= factorials.length) { return Double.POSITIVE_INFINITY; } return factorials[n]; }
@Override public double getValue() throws EvaluationException { double ret = 0; for (RValue invokable : sequence) { ret = invokable.getValue(); } return ret; }
@Override public Double call() throws Exception { pushInstance(); try { return root.getValue(); } finally { popInstance(); } } });
private static double queryInternal(RValue type, RValue data, double typeId, double dataValue) throws EvaluationException { // Compare to input values and determine return value // -1 is a wildcard, always true final double ret = ((type.getValue() == -1 || typeId == type.getValue()) && (data.getValue() == -1 || dataValue == data.getValue())) ? 1.0 : 0.0; if (type instanceof LValue) { ((LValue) type).assign(typeId); } if (data instanceof LValue) { ((LValue) data).assign(dataValue); } return ret; }
@Dynamic public static double closest(RValue x, RValue y, RValue z, RValue index, RValue count, RValue stride) throws EvaluationException { return findClosest( Expression.getInstance().getFunctions().megabuf, x.getValue(), y.getValue(), z.getValue(), (int) index.getValue(), (int) count.getValue(), (int) stride.getValue() ); }
public static double ridgedmulti(RValue seed, RValue x, RValue y, RValue z, RValue frequency, RValue octaves) throws EvaluationException { RidgedMultiFractalNoise ridgedMulti = localRidgedMulti.get(); try { ridgedMulti.setSeed((int) seed.getValue()); ridgedMulti.setFrequency(frequency.getValue()); ridgedMulti.setOctaveCount((int) octaves.getValue()); } catch (IllegalArgumentException e) { throw new EvaluationException(0, "Ridged multi error: " + e.getMessage()); } return ridgedMulti.noise(Vector3.at(x.getValue(), y.getValue(), z.getValue())); }
public static double voronoi(RValue seed, RValue x, RValue y, RValue z, RValue frequency) throws EvaluationException { VoronoiNoise voronoi = localVoronoi.get(); try { voronoi.setSeed((int) seed.getValue()); voronoi.setFrequency(frequency.getValue()); } catch (IllegalArgumentException e) { throw new EvaluationException(0, "Voronoi error: " + e.getMessage()); } return voronoi.noise(Vector3.at(x.getValue(), y.getValue(), z.getValue())); }
public static double perlin(RValue seed, RValue x, RValue y, RValue z, RValue frequency, RValue octaves, RValue persistence) throws EvaluationException { PerlinNoise perlin = localPerlin.get(); try { perlin.setSeed((int) seed.getValue()); perlin.setFrequency(frequency.getValue()); perlin.setOctaveCount((int) octaves.getValue()); perlin.setPersistence(persistence.getValue()); } catch (IllegalArgumentException e) { throw new EvaluationException(0, "Perlin noise error: " + e.getMessage()); } return perlin.noise(Vector3.at(x.getValue(), y.getValue(), z.getValue())); }
@Dynamic public static double query(RValue x, RValue y, RValue z, RValue type, RValue data) throws EvaluationException { final double xp = x.getValue(); final double yp = y.getValue(); final double zp = z.getValue(); final ExpressionEnvironment environment = Expression.getInstance().getEnvironment(); // Read values from world final double typeId = environment.getBlockType(xp, yp, zp); final double dataValue = environment.getBlockData(xp, yp, zp); return queryInternal(type, data, typeId, dataValue); }
@Dynamic public static double queryAbs(RValue x, RValue y, RValue z, RValue type, RValue data) throws EvaluationException { final double xp = x.getValue(); final double yp = y.getValue(); final double zp = z.getValue(); final ExpressionEnvironment environment = Expression.getInstance().getEnvironment(); // Read values from world final double typeId = environment.getBlockTypeAbs(xp, yp, zp); final double dataValue = environment.getBlockDataAbs(xp, yp, zp); return queryInternal(type, data, typeId, dataValue); }
@Dynamic public static double queryRel(RValue x, RValue y, RValue z, RValue type, RValue data) throws EvaluationException { final double xp = x.getValue(); final double yp = y.getValue(); final double zp = z.getValue(); final ExpressionEnvironment environment = Expression.getInstance().getEnvironment(); // Read values from world final double typeId = environment.getBlockTypeRel(xp, yp, zp); final double dataValue = environment.getBlockDataRel(xp, yp, zp); return queryInternal(type, data, typeId, dataValue); }
@Dynamic public static double gmegabuf(RValue index, double value) throws EvaluationException { return setBufferItem(gmegabuf, (int) index.getValue(), value); }
@Dynamic public static double gmegabuf(RValue index) throws EvaluationException { return getBufferItem(gmegabuf, (int) index.getValue()); }
public static double rotate(LValue x, LValue y, RValue angle) throws EvaluationException { final double f = angle.getValue(); final double cosF = Math.cos(f); final double sinF = Math.sin(f); final double xOld = x.getValue(); final double yOld = y.getValue(); x.assign(xOld * cosF - yOld * sinF); y.assign(xOld * sinF + yOld * cosF); return 0.0; }
@Dynamic public static double megabuf(RValue index, double value) throws EvaluationException { return setBufferItem(Expression.getInstance().getFunctions().megabuf, (int) index.getValue(), value); }
@Test public void testAssign() throws ExpressionException { Expression foo = compile("{a=x} b=y; c=z", "x", "y", "z", "a", "b", "c"); foo.evaluate(2, 3, 5); assertEquals(2, foo.getVariable("a", false).getValue(), 0); assertEquals(3, foo.getVariable("b", false).getValue(), 0); assertEquals(5, foo.getVariable("c", false).getValue(), 0); }
@Override public RValue optimize() throws EvaluationException { final RValue newCondition = condition.optimize(); if (newCondition instanceof Constant) { if (newCondition.getValue() > 0) { return truePart.optimize(); } else { return falsePart == null ? new Constant(getPosition(), 0.0) : falsePart.optimize(); } } return new Conditional(getPosition(), newCondition, truePart.optimize(), falsePart == null ? null : falsePart.optimize()); }
@Override public RValue optimize() throws EvaluationException { final RValue newCondition = condition.optimize(); if (newCondition instanceof Constant && newCondition.getValue() <= 0) { // If the condition is always false, the loop can be flattened. // So we run the init part and then return 0.0. return new Sequence(getPosition(), init, new Constant(getPosition(), 0.0)).optimize(); } //return new Sequence(getPosition(), init.optimize(), new While(getPosition(), condition, new Sequence(getPosition(), body, increment), false)).optimize(); return new For(getPosition(), init.optimize(), newCondition, increment.optimize(), body.optimize()); }