| 146 | } |
| 147 | |
| 148 | public <T> Flann build2d(List<T> d, Function<T, Vec2> t) { |
| 149 | free(); |
| 150 | |
| 151 | FloatBuffer f = (allocated == null || allocated.capacity() != d.size() * 2) ? ByteBuffer.allocateDirect( |
| 152 | 4 * d.size() * 2) |
| 153 | .order(ByteOrder.nativeOrder()) |
| 154 | .asFloatBuffer() : allocated; |
| 155 | for (T dd : d) { |
| 156 | Vec2 v = t.apply(dd); |
| 157 | f.put((float) v.x).put((float) v.y); |
| 158 | } |
| 159 | f.rewind(); |
| 160 | cloud = build2(f, d.size()); |
| 161 | is2d = true; |
| 162 | allocated = f; |
| 163 | |
| 164 | return this; |
| 165 | } |
| 166 | |
| 167 | public List<Integer> find3(Vec3 p, int n) { |
| 168 | if (cache == null || cache.capacity() < n) { |