// File: 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:
subq $0x148, %rsp            # imm = 0x148
movq %rdi, 0x140(%rsp)
movq %rsi, 0x138(%rsp)
movq %rdx, 0x130(%rsp)
movq %rcx, 0x128(%rsp)
movsd %xmm0, 0x120(%rsp)
movsd %xmm1, 0x118(%rsp)
movq %r8, 0x110(%rsp)
movq 0x140(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x138(%rsp), %rax
cmpq $0x0, 0x8(%rax)
je 0x48fbd
movsd 0x118(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x48dea
jp 0x48dea
movq 0x128(%rsp), %rdi
movq 0x130(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xb3590
cmpl $0x0, %eax
jne 0x48de8
jmp 0x490e4
jmp 0x48e23
movq 0x128(%rsp), %rdi
movq 0x130(%rsp), %rsi
callq 0xc1d80
movsd %xmm0, 0x108(%rsp)
movsd 0x108(%rsp), %xmm0
ucomisd 0x118(%rsp), %xmm0
jb 0x48e21
jmp 0x490e4
jmp 0x48e23
movq 0x130(%rsp), %rsi
leaq 0xd0(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xfc930
movq 0x30(%rsp), %rdi
movq 0x138(%rsp), %rax
movsd 0x18(%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movl $0x1, %esi
callq 0x1ec30
movq %rax, %rdi
movq 0x138(%rsp), %rax
movl 0x20(%rax), %esi
callq 0x1ec70
movsd 0x28(%rsp), %xmm0
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rdx
movsd %xmm0, (%rax)
movq 0x138(%rsp), %rax
movq 0x8(%rax), %rsi
movq 0x128(%rsp), %rcx
movsd 0x120(%rsp), %xmm0
movsd 0x118(%rsp), %xmm1
movq 0x110(%rsp), %r8
callq 0x48d50
jmp 0x48ebb
movq 0x130(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0xfc930
jmp 0x48ed2
movq 0x138(%rsp), %rax
movsd 0x18(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x88(%rsp), %rdi
movq %rdi, 0x20(%rsp)
xorl %esi, %esi
callq 0x1ec30
movq %rax, %rdi
movq 0x138(%rsp), %rax
movl 0x20(%rax), %esi
callq 0x1ec70
movsd 0x18(%rsp), %xmm0
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rdx
movsd %xmm0, (%rax)
movq 0x138(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x128(%rsp), %rcx
movsd 0x120(%rsp), %xmm0
movsd 0x118(%rsp), %xmm1
movq 0x110(%rsp), %r8
callq 0x48d50
jmp 0x48f55
leaq 0x88(%rsp), %rdi
callq 0x1ec20
leaq 0xd0(%rsp), %rdi
callq 0x1ec20
jmp 0x490e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
jmp 0x48fab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc8(%rsp)
movl %eax, 0xc4(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x1ec20
leaq 0xd0(%rsp), %rdi
callq 0x1ec20
jmp 0x490ec
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
movq 0x138(%rsp), %rcx
cmpl 0x128(%rcx), %eax
jge 0x490e2
movq 0x138(%rsp), %rax
movslq 0x84(%rsp), %rcx
movq 0x28(%rax,%rcx,8), %rax
movq %rax, 0x78(%rsp)
movsd 0x118(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x4905a
jp 0x4905a
movq 0x38(%rsp), %rsi
movq 0x128(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x78(%rsp), %rdx
leaq 0x60(%rsp), %rdi
callq 0x1f850
movq 0x10(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x49100
cmpl $0x0, %eax
je 0x49058
movq 0x110(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x1f3d0
jmp 0x490ca
movq 0x38(%rsp), %rsi
movq 0x128(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x78(%rsp), %rdx
leaq 0x40(%rsp), %rdi
callq 0x1f850
movq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x47480
movsd %xmm0, 0x58(%rsp)
movsd 0x58(%rsp), %xmm0
ucomisd 0x120(%rsp), %xmm0
jb 0x490c8
movsd 0x58(%rsp), %xmm1
movsd 0x118(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x490c8
movq 0x110(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x1f3d0
jmp 0x490ca
jmp 0x490cc
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x48fc8
jmp 0x490e4
addq $0x148, %rsp            # imm = 0x148
retq
movq 0xc8(%rsp), %rdi
callq 0x16ca0
nopl (%rax)