Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <a href="http://www.savarese.com/software/libssrckdtree-j/api/com/savarese/spatial/NearestNeighbors.html#get%28com.savarese.spatial.KDTree,%20P,%20int,%20boolean%29" rel="nofollow">api documentation for NearestNeighbor#get()</a> indicates that the method takes four arguments of types KDTree, P, int, boolean, which are all Java types.</p> <p>Your error message indicates that you passed in KDTree, RubyArray, RubyFixnum, RubyBoolean. So, KDTree looks ok. I believe JRuby will automatically coerce Fixnum and Boolean to the appropriate Java types. That leaves the second arg where you are passing RubyArray where the method expects P.</p> <p>The documentation of NearestNeighbors indicates that P is a generic type, <code>P extends Point&lt;Coord&gt;</code>. <code>Point</code> is an interface. <code>GenericPoint</code> implements that interface. So instead of passing <code>[1,1]</code>, try passing <code>Java::com.savarese.spatial.GenericPoint.new(1,1)</code></p> <p>edit:</p> <p>Looking a bit further, <code>GenericPoint</code> must be created with <code>Coord</code>, another generic type <code>Coord extends java.lang.Comparable&lt;? super Coord&gt;</code>. In Java, there are two kinds of ints, the primitive type <code>int</code> (fast), and the "boxed" object <code>java.lang.Integer</code>. <code>Integer</code> implements the <code>Comparable</code> interface, which is required by <code>GenericPoint</code>. I did not get any errors running the following:</p> <pre><code>require 'java' require 'libssrckdtree-j-1.0.2.jar' GenericPoint = Java::com.savarese.spatial.GenericPoint KDTree = Java::com.savarese.spatial.KDTree NearestNeighbors = Java::com.savarese.spatial.NearestNeighbors def box(i) java.lang.Integer.new(i) end tree = KDTree.new def generate_points(tree, size) size.times do x = box(rand(100)) y = box(rand(100)) point = GenericPoint.new(x, y) tree.put(point, point.to_s) end end generate_points(tree, 20000) nearest = NearestNeighbors.new() point = GenericPoint.new(box(1), box(1)) nearest.get(tree, point, 1, false) </code></pre> <p>A note about the above, normally in Java to create a boxed <code>Integer</code>, one uses <a href="http://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html#valueOf%28int%29" rel="nofollow"><code>java.lang.Integer.valueOf(int)</code></a>. For reasons beyond me, this resulted in the same error one gets when using <code>int</code>: <code>NativeException: java.lang.ClassCastException: org.jruby.RubyFixnum cannot be cast to java.lang.Number</code>. So I instead used the constructor, <code>java.lang.Integer.new</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload