// File: tomfunkhouser[P]gaps/pkgs/GSV/GSVScanline.cpp
// Function: gaps::GSVScanline::Draw(gaps::RNFlags) const
void GSVScanline::
Draw(RNFlags flags) const
{
  // Just checking
  if (NPoints() == 0) return;
  assert(points);

  // Draw scanline
  if (flags & GSV_DRAW_SCANLINES_WITH_POINT_INDEX_COLOR) {
    const int ncolors = 3;
    GLfloat color[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
    RNLength max_edge_length_squared = 1;
    RNGrfxBegin(RN_GRFX_LINES);
    R3Point prev_point = PointPosition(0);
    for (int ik = 1; ik < NPoints(); ik++) {
      const R3Point& current_point = PointPosition(ik);
      RNScalar dx = prev_point[0] - current_point[0];
      RNScalar dy = prev_point[1] - current_point[1];
      RNScalar dd = dx*dx + dy*dy;
      if (dd < max_edge_length_squared) {
        RNLoadRgb(color[(int) (0.1 * (NPoints()-ik)) % ncolors]);
        R3LoadPoint(prev_point);
        R3LoadPoint(current_point);
      }
      prev_point = current_point;
    }
    RNGrfxEnd();
  }
  else {
    // Draw points
    RNGrfxBegin(RN_GRFX_POINTS);
    LoadPoints(flags);
    RNGrfxEnd();
  }
}

// Assembly:
subq $0xc8, %rsp
movq %rsi, 0xc0(%rsp)
movq %rdi, 0xb8(%rsp)
movq 0xb8(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x3a120
cmpl $0x0, %eax
jne 0x57a63
jmp 0x57c91
leaq 0xc0(%rsp), %rdi
callq 0x38fe0
andq $0x1000, %rax           # imm = 0x1000
cmpq $0x0, %rax
je 0x57c69
movl $0x3, 0xb4(%rsp)
leaq 0x90(%rsp), %rdi
xorl %esi, %esi
movl $0x24, %edx
callq 0x295e0
movss 0x20e66d(%rip), %xmm0   # 0x266114
movss %xmm0, 0x90(%rsp)
movss 0x20e65c(%rip), %xmm0   # 0x266114
movss %xmm0, 0xa0(%rsp)
movss 0x20e64b(%rip), %xmm0   # 0x266114
movss %xmm0, 0xb0(%rsp)
movsd 0x20e536(%rip), %xmm0   # 0x266010
movsd %xmm0, 0x88(%rsp)
movl $0x1, %edi
callq 0x38d90
movq 0x20(%rsp), %rsi
leaq 0x70(%rsp), %rdi
xorl %edx, %edx
callq 0x59950
movl $0x1, 0x6c(%rsp)
movq 0x20(%rsp), %rdi
movl 0x6c(%rsp), %eax
movl %eax, 0x1c(%rsp)
callq 0x3a120
movl %eax, %ecx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
jge 0x57c62
movq 0x20(%rsp), %rsi
movl 0x6c(%rsp), %edx
leaq 0x48(%rsp), %rdi
callq 0x59950
leaq 0x48(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x70(%rsp), %rdi
xorl %esi, %esi
callq 0x44530
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x38ac0
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
leaq 0x70(%rsp), %rdi
movl $0x1, %esi
callq 0x44530
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x60(%rsp), %rdi
movl $0x1, %esi
callq 0x38ac0
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x40(%rsp), %xmm0
movsd 0x40(%rsp), %xmm2
movsd 0x38(%rsp), %xmm1
mulsd 0x38(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x30(%rsp), %xmm1
movsd 0x88(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x57c43
movq 0x20(%rsp), %rdi
callq 0x3a120
subl 0x6c(%rsp), %eax
cvtsi2sd %eax, %xmm1
movsd 0x20e498(%rip), %xmm0   # 0x2660a0
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movslq %edx, %rax
leaq 0x90(%rsp), %rdi
imulq $0xc, %rax, %rax
addq %rax, %rdi
callq 0x56760
leaq 0x70(%rsp), %rdi
callq 0x38e20
movq 0x60(%rsp), %rdi
callq 0x38e20
movq 0x60(%rsp), %rsi
leaq 0x70(%rsp), %rdi
callq 0x180420
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x57b06
callq 0x38e40
jmp 0x57c91
xorl %edi, %edi
callq 0x38d90
movq 0x20(%rsp), %rdi
movq 0xc0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rsi
callq 0x57ca0
callq 0x38e40
addq $0xc8, %rsp
retq
nopl (%rax)