// File: /workspace/github_cpp_makefile_star2_O3/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 0x2ec88
movq %rdx, %r13
xorpd %xmm0, %xmm0
movq %r14, %rdi
movq %rdx, %rsi
ucomisd %xmm0, %xmm1
jne 0x2ed24
jp 0x2ed24
xorl %edx, %edx
callq 0x62d96
testl %eax, %eax
jne 0x2ed34
jmp 0x2edd1
cmpl $0x0, 0x128(%r12)
jle 0x2edd1
xorl %r15d, %r15d
leaq 0x50(%rsp), %r13
movsd (%rsp), %xmm0
ucomisd 0xda3ac(%rip), %xmm0    # 0x109058
movq 0x28(%r12,%r15,8), %rbp
movq %r13, %rdi
jne 0x2ecd6
jp 0x2ecd6
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0x1abbc
movq %r13, %rdi
movq %r14, %rsi
callq 0x62521
testl %eax, %eax
jne 0x2ed01
jmp 0x2ed0f
movq 0x8(%rsp), %rsi
movq %rbp, %rdx
callq 0x1abbc
movq %r13, %rdi
movq %r14, %rsi
callq 0x69856
ucomisd 0x10(%rsp), %xmm0
jb 0x2ed0f
movsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x2ed0f
movl 0xc(%rbx), %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xc35c2
incq %r15
movslq 0x128(%r12), %rax
cmpq %rax, %r15
jl 0x2ec9f
jmp 0x2edd1
callq 0x6a49d
ucomisd (%rsp), %xmm0
jae 0x2edd1
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
callq 0x87700
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 0x2ec26
leaq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x87700
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 0x2ec26
leaq 0x18(%rsp), %rdi
callq 0x88520
leaq 0x50(%rsp), %rdi
callq 0x88520
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x88520
jmp 0x2edf7
jmp 0x2edf4
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x88520
movq %rbx, %rdi
callq 0x15ad0
nop