// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Utils/../../pkgs/R3Shapes/R3Kdtree.cpp
// Function: void gaps::R3Kdtree<gaps::R3SegmentationPoint*>::FindAll<gaps::R3Line>(gaps::R3KdtreeNode<gaps::R3SegmentationPoint*>*, gaps::R3Box const&, gaps::R3Line const&, double, double, gaps::RNArray<gaps::R3SegmentationPoint*>&) const
void R3Kdtree<PtrType>::
FindAll(R3KdtreeNode<PtrType> *node, const R3Box& node_box, 
  const Shape& query_shape, 
  RNScalar min_distance, RNScalar max_distance, 
  RNArray<PtrType>& points) const
{
  // Check if node is interior
  if (node->children[0]) {
    assert(node->children[1]);

    // Check node box
    if (max_distance == 0) {
      if (!R3Intersects(query_shape, node_box)) return;
    }
    else {
      // Check distance from shape to node box
      RNLength distance = R3Distance(query_shape, node_box);
      if (distance >= max_distance) return;
    }

    // Search negative side 
    R3Box child_box1(node_box);
    child_box1[RN_HI][node->split_dimension] = node->split_coordinate;
    FindAll(node->children[0], child_box1, query_shape,
      min_distance, max_distance, 
      points);

    // Search positive side
    R3Box child_box2(node_box);
    child_box2[RN_LO][node->split_dimension] = node->split_coordinate;
    FindAll(node->children[1], child_box2, query_shape,
      min_distance, max_distance, 
      points);
  }
  else {
    // Search points
    for (int i = 0; i < node->npoints; i++) {
      PtrType point = node->points[i];

      if (max_distance == 0) {
        if (R3Intersects(query_shape, Position(point))) {
          points.Insert(point);
        }
      }
      else {
        RNLength distance = R3Distance(query_shape, Position(point));
        if ((distance >= min_distance) && (distance <= max_distance)) {
          points.Insert(point);
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r8, %rbx
movsd %xmm0, 0x10(%rsp)
movq %rcx, %r14
movq %rsi, %r12
movq %rdi, 0x8(%rsp)
cmpq $0x0, 0x8(%rsi)
movsd %xmm1, (%rsp)
je 0x2f138
movq %rdx, %r13
xorpd %xmm0, %xmm0
movq %r14, %rdi
movq %rdx, %rsi
ucomisd %xmm0, %xmm1
jne 0x2f1d4
jp 0x2f1d4
xorl %edx, %edx
callq 0x635da
testl %eax, %eax
jne 0x2f1e4
jmp 0x2f281
cmpl $0x0, 0x128(%r12)
jle 0x2f281
xorl %r15d, %r15d
leaq 0x50(%rsp), %r13
movsd (%rsp), %xmm0
ucomisd 0xdbefc(%rip), %xmm0    # 0x10b058
movq 0x28(%r12,%r15,8), %rbp
movq %r13, %rdi
jne 0x2f186
jp 0x2f186
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0x1ac36
movq %r13, %rdi
movq %r14, %rsi
callq 0x62d65
testl %eax, %eax
jne 0x2f1b1
jmp 0x2f1bf
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0x1ac36
movq %r13, %rdi
movq %r14, %rsi
callq 0x6a63e
ucomisd 0x10(%rsp), %xmm0
jb 0x2f1bf
movsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x2f1bf
movl 0xc(%rbx), %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xc4be6
incq %r15
movslq 0x128(%r12), %rax
cmpq %rax, %r15
jl 0x2f14f
jmp 0x2f281
callq 0x6b28d
ucomisd (%rsp), %xmm0
jae 0x2f281
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x886d8
movsd 0x18(%r12), %xmm0
movslq 0x20(%r12), %rax
movsd %xmm0, 0x70(%rsp,%rax,8)
movq 0x8(%r12), %rsi
movq 0x8(%rsp), %rdi
movq %rbp, %rdx
movq %r14, %rcx
movsd 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
movq %rbx, %r8
callq 0x2f0d6
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x886d8
movsd 0x18(%r12), %xmm0
movslq 0x20(%r12), %rax
movsd %xmm0, 0x20(%rsp,%rax,8)
movq 0x10(%r12), %rsi
leaq 0x18(%rsp), %rdx
movq 0x8(%rsp), %rdi
movq %r14, %rcx
movsd 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
movq %rbx, %r8
callq 0x2f0d6
leaq 0x18(%rsp), %rdi
callq 0x89530
leaq 0x50(%rsp), %rdi
callq 0x89530
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x89530
jmp 0x2f2a7
jmp 0x2f2a4
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x89530
movq %rbx, %rdi
callq 0x15ae0
nop