// File: tomfunkhouser[P]gaps/pkgs/R3Utils/R3Segmentation.cpp
// Function: gaps::R3SegmentationCluster::RemovePoint(gaps::R3SegmentationPoint*)
void R3SegmentationCluster::
RemovePoint(R3SegmentationPoint *point)
{
  // Just checking
  assert(point->cluster == this);
  assert(point->cluster_index >= 0);

  // Update cluster
  total_affinity -= point->cluster_affinity;
  color = (points.NEntries() > 1) ? (points.NEntries()*color - point->color) / (points.NEntries()-1) : RNblack_rgb;
  timestamp = (points.NEntries() > 1) ? (points.NEntries()*timestamp - point->timestamp) / (points.NEntries()-1) : 0;
  area -= point->area;

  // Remove point
  RNArrayEntry *entry = points.KthEntry(point->cluster_index);
  R3SegmentationPoint *tail = points.Tail();
  tail->cluster_index = point->cluster_index;
  points.EntryContents(entry) = tail;
  points.RemoveTail();

  // Update point
  point->cluster = NULL;
  point->cluster_index = -1;
  point->cluster_affinity = 0;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq 0x80(%rsp), %rdi
movq %rdi, 0x18(%rsp)
movq 0x78(%rsp), %rax
movsd 0xc8(%rax), %xmm1
movsd 0x128(%rdi), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x128(%rdi)
addq $0x8, %rdi
callq 0x1ecf0
cmpl $0x1, %eax
jle 0x3e136
movq 0x18(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
movq 0x18(%rsp), %rsi
cvtsi2sd %eax, %xmm0
addq $0xf0, %rsi
leaq 0x30(%rsp), %rdi
callq 0x3b580
movq 0x78(%rsp), %rdx
addq $0x78, %rdx
leaq 0x48(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x47800
movq 0x18(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
subl $0x1, %eax
cvtsi2sd %eax, %xmm0
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x3b5c0
jmp 0x3e147
leaq 0x60(%rsp), %rdi
leaq 0x62d50e(%rip), %rsi    # 0x66b650
callq 0x1731b0
movq 0x18(%rsp), %rdi
addq $0xf0, %rdi
leaq 0x60(%rsp), %rsi
callq 0x173370
movq 0x18(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
cmpl $0x1, %eax
jle 0x3e1e0
movq 0x18(%rsp), %rdi
addq $0x8, %rdi
callq 0x1ecf0
movq 0x18(%rsp), %rdi
cvtsi2sd %eax, %xmm0
movsd 0x108(%rdi), %xmm2
movq 0x78(%rsp), %rax
movsd 0x68(%rax), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
addq $0x8, %rdi
callq 0x1ecf0
movsd 0x8(%rsp), %xmm0
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
jmp 0x3e1eb
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
jmp 0x3e1eb
movq 0x18(%rsp), %rdi
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x108(%rdi)
movq 0x78(%rsp), %rax
movsd 0x70(%rax), %xmm1
movsd 0xe8(%rdi), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0xe8(%rdi)
addq $0x8, %rdi
movq 0x78(%rsp), %rax
movl 0xd0(%rax), %esi
callq 0x27f10
movq 0x18(%rsp), %rdi
movq %rax, 0x28(%rsp)
addq $0x8, %rdi
callq 0x476b0
movq 0x18(%rsp), %rdi
movq %rax, 0x20(%rsp)
movq 0x78(%rsp), %rax
movl 0xd0(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0xd0(%rax)
movq 0x20(%rsp), %rax
movq %rax, (%rsp)
addq $0x8, %rdi
movq 0x28(%rsp), %rsi
callq 0x47870
movq (%rsp), %rcx
movq 0x18(%rsp), %rdi
movq %rcx, (%rax)
addq $0x8, %rdi
callq 0x27f50
movq 0x78(%rsp), %rax
movq $0x0, 0xc0(%rax)
movq 0x78(%rsp), %rax
movl $0xffffffff, 0xd0(%rax) # imm = 0xFFFFFFFF
movq 0x78(%rsp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0xc8(%rax)
addq $0x88, %rsp
retq
nopw %cs:(%rax,%rax)