use of org.jruby.anno.JRubyMethod in project propane by ruby-processing.
the class Vec2 method cross.
/**
* @param context ThreadContext
* @param other IRubyObject
* @return cross product IRubyObject
*/
@JRubyMethod(name = "cross", required = 1)
public IRubyObject cross(ThreadContext context, IRubyObject other) {
Vec2 b = null;
Ruby runtime = context.runtime;
if (other instanceof Vec2) {
b = (Vec2) other.toJava(Vec2.class);
} else {
throw runtime.newTypeError("argument should be Vec2D");
}
return runtime.newFloat(jx * b.jy - jy * b.jx);
}
use of org.jruby.anno.JRubyMethod in project propane by ruby-processing.
the class Vec2 method toCurveVertex.
/**
* To curve vertex
*
* @param context ThreadContext
* @param object IRubyObject vertex renderer
*/
@JRubyMethod(name = "to_curve_vertex")
public void toCurveVertex(ThreadContext context, IRubyObject object) {
JRender renderer = (JRender) object.toJava(JRender.class);
renderer.curveVertex(jx, jy);
}
use of org.jruby.anno.JRubyMethod in project propane by ruby-processing.
the class Vec2 method lerp_bang.
/**
* @param context ThreadContext
* @param args IRubyObject[]
* @return this IRubyObject
*/
@JRubyMethod(name = "lerp!", rest = true)
public IRubyObject lerp_bang(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.runtime;
if (args.length != 2) {
throw runtime.newSyntaxError("Check syntax");
}
Vec2 vec = (Vec2) args[0].toJava(Vec2.class);
double scalar = (args[1] instanceof RubyFloat) ? ((RubyFloat) args[1]).getValue() : ((RubyFixnum) args[1]).getDoubleValue();
assert (scalar >= 0 && scalar < 1.0) : "Lerp value " + scalar + " out of range 0..1.0";
jx += (vec.jx - jx) * scalar;
jy += (vec.jy - jy) * scalar;
return this;
}
use of org.jruby.anno.JRubyMethod in project propane by ruby-processing.
the class Vec2 method op_mul.
/**
* @param context ThreadContext
* @param other IRubyObject scalar
* @return new Vec2D object (ruby)
*/
@JRubyMethod(name = "*")
public IRubyObject op_mul(ThreadContext context, IRubyObject other) {
Ruby runtime = context.runtime;
double scalar = (other instanceof RubyFloat) ? ((RubyFloat) other).getValue() : ((RubyFixnum) other).getDoubleValue();
return Vec2.rbNew(context, this.getMetaClass(), new IRubyObject[] { runtime.newFloat(jx * scalar), runtime.newFloat(jy * scalar) });
}
use of org.jruby.anno.JRubyMethod in project propane by ruby-processing.
the class Vec2 method random_direction.
/**
* Example of a regular ruby class method
*
* @param context ThreadContext
* @param klazz IRubyObject
* @return new Vec2 object (ruby)
*/
@JRubyMethod(name = "random", meta = true)
public static IRubyObject random_direction(ThreadContext context, IRubyObject klazz) {
Ruby runtime = context.runtime;
double angle = Math.random() * Math.PI * 2;
return Vec2.rbNew(context, klazz, new IRubyObject[] { runtime.newFloat(Math.cos(angle)), runtime.newFloat(Math.sin(angle)) });
}
Aggregations