Search in sources :

Example 31 with JRubyMethod

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);
}
Also used : Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 32 with JRubyMethod

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);
}
Also used : JRender(monkstone.vecmath.JRender) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 33 with JRubyMethod

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;
}
Also used : Ruby(org.jruby.Ruby) RubyFloat(org.jruby.RubyFloat) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 34 with JRubyMethod

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) });
}
Also used : Ruby(org.jruby.Ruby) RubyFloat(org.jruby.RubyFloat) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 35 with JRubyMethod

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)) });
}
Also used : Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Aggregations

JRubyMethod (org.jruby.anno.JRubyMethod)304 Ruby (org.jruby.Ruby)157 RubyString (org.jruby.RubyString)83 IRubyObject (org.jruby.runtime.builtin.IRubyObject)77 IOException (java.io.IOException)49 RubyArray (org.jruby.RubyArray)34 Node (org.w3c.dom.Node)30 RaiseException (org.jruby.exceptions.RaiseException)27 BigInteger (java.math.BigInteger)24 GeneralSecurityException (java.security.GeneralSecurityException)24 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)24 Document (org.w3c.dom.Document)20 ByteList (org.jruby.util.ByteList)19 RubyClass (org.jruby.RubyClass)16 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)14 RubyFloat (org.jruby.RubyFloat)13 JRubyClass (org.jruby.anno.JRubyClass)13 NokogiriHelpers.clearCachedNode (nokogiri.internals.NokogiriHelpers.clearCachedNode)12 RubyFixnum (org.jruby.RubyFixnum)12 Element (org.w3c.dom.Element)12