use of org.jruby.RubyFloat in project propane by ruby-processing.
the class Vec2 method rotate.
/**
* @param context ThreadContext
* @param scalar IRubyObject
* @return a new Vec2 object rotated
*/
@JRubyMethod(name = "rotate")
public IRubyObject rotate(ThreadContext context, IRubyObject scalar) {
Ruby runtime = context.runtime;
double theta = (scalar instanceof RubyFloat) ? ((RubyFloat) scalar).getValue() : ((RubyFixnum) scalar).getDoubleValue();
IRubyObject[] ary = new IRubyObject[] { runtime.newFloat(jx * Math.cos(theta) - jy * Math.sin(theta)), runtime.newFloat(jx * Math.sin(theta) + jy * Math.cos(theta)) };
return Vec2.rbNew(context, this.getMetaClass(), ary);
}
use of org.jruby.RubyFloat in project propane by ruby-processing.
the class Vec3 method op_div.
/**
* @param context ThreadContext
* @param scalar IRubyObject
* @return new Vec3 object (ruby)
*/
@JRubyMethod(name = "/", required = 1)
public IRubyObject op_div(ThreadContext context, IRubyObject scalar) {
Ruby runtime = context.runtime;
double divisor = scalar instanceof RubyFloat ? ((RubyFloat) scalar).getValue() : ((RubyFixnum) scalar).getDoubleValue();
if (Math.abs(divisor) < Vec3.EPSILON) {
return this;
}
return Vec3.rbNew(context, this.getMetaClass(), new IRubyObject[] { runtime.newFloat(jx / divisor), runtime.newFloat(jy / divisor), runtime.newFloat(jz / divisor) });
}
use of org.jruby.RubyFloat in project propane by ruby-processing.
the class MathToolModule method constrainValue.
/**
* Provides processing constrain method as a ruby module method
*
* @param context ThreadContext
* @param recv IRubyObject
* @param args array of args must be be numeric
* @return original or limit values
*/
@JRubyMethod(name = "constrain", rest = true, module = true)
public static IRubyObject constrainValue(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
RubyFloat value = args[0].convertToFloat();
RubyFloat start = args[1].convertToFloat();
RubyFloat stop = args[2].convertToFloat();
if (value.op_ge(context, start).isTrue() && value.op_le(context, stop).isTrue()) {
return args[0];
} else if (value.op_ge(context, start).isTrue()) {
return args[2];
} else {
return args[1];
}
}
Aggregations