|
21 | 21 | *
|
22 | 22 | * fastAtan2 algorithm from https://github.com/libgdx/libgdx (Apache 2.0 license)
|
23 | 23 | */
|
| 24 | +import java.util.logging.Logger; |
24 | 25 | import org.jruby.Ruby;
|
25 | 26 | import org.jruby.RubyArray;
|
26 | 27 | import org.jruby.RubyClass;
|
@@ -228,19 +229,27 @@ public IRubyObject dist(ThreadContext context, IRubyObject other) {
|
228 | 229 | return runtime.newFloat(result);
|
229 | 230 | }
|
230 | 231 |
|
| 232 | + @Deprecated |
| 233 | + @JRubyMethod(name = "cross", required = 1) |
| 234 | + public IRubyObject cross(ThreadContext context, IRubyObject other) { |
| 235 | + Logger log = Logger.getGlobal(); |
| 236 | + log.warning("prefer ^ operator"); |
| 237 | + return op_wedge(context, other); |
| 238 | + } |
| 239 | + |
231 | 240 | /**
|
232 | 241 | *
|
233 | 242 | * @param context ThreadContext
|
234 | 243 | * @param other IRubyObject
|
235 |
| - * @return cross product IRubyObject |
| 244 | + * @return wedge product IRubyObject |
236 | 245 | */
|
237 |
| - @JRubyMethod(name = "cross", required = 1) |
| 246 | + @JRubyMethod(name = "^", required = 1) |
238 | 247 |
|
239 |
| - public IRubyObject cross(ThreadContext context, IRubyObject other) { |
| 248 | + public IRubyObject op_wedge(ThreadContext context, IRubyObject other) { |
240 | 249 | Vec2 b = null;
|
241 | 250 | Ruby runtime = context.runtime;
|
242 | 251 | if (other instanceof Vec2) {
|
243 |
| - b = (Vec2) other.toJava(Vec2.class); |
| 252 | + b = other.toJava(Vec2.class); |
244 | 253 | } else {
|
245 | 254 | throw runtime.newTypeError("argument should be Vec2D");
|
246 | 255 | }
|
@@ -401,7 +410,7 @@ public IRubyObject mag(ThreadContext context) {
|
401 | 410 | public IRubyObject set_mag(ThreadContext context, IRubyObject scalar, Block block) {
|
402 | 411 | double new_mag = scalar.toJava(Double.class);
|
403 | 412 | if (block.isGiven() && !block.yield(context, scalar).toJava(Boolean.class)) {
|
404 |
| - return this; |
| 413 | + return this; |
405 | 414 | }
|
406 | 415 | double current = 0;
|
407 | 416 | if (Math.abs(jx) > EPSILON && Math.abs(jy) > EPSILON) {
|
@@ -789,7 +798,7 @@ public IRubyObject op_equal(ThreadContext context, IRubyObject other) {
|
789 | 798 | double diff = jx - v.jx;
|
790 | 799 | if ((diff < 0 ? -diff : diff) > Vec2.EPSILON) {
|
791 | 800 | return runtime.newBoolean(false);
|
792 |
| - } |
| 801 | + } |
793 | 802 | diff = jy - v.jy;
|
794 | 803 | return runtime.newBoolean((diff < 0 ? -diff : diff) < Vec2.EPSILON);
|
795 | 804 | }
|
|
0 commit comments