// File: /workspace/github_cpp_makefile_star2_O1/matthewarcus[P]mmps/image.cpp
// Function: Image::PlotLineAux(double, double, LinePlotter const&, Rgb const&, int)
void Image::PlotLineAux(double t0, double t1, 
			const LinePlotter& lineplotter,
			const Rgb& color,
			int depth)
{
  if (depth == 0) {
    return;
  }
  double x0 = 0.0, y0 = 0.0;
  double x1 = 0.0, y1 = 0.0;
  // The bools tell us if the inverse mapping is even defined
  bool defined0 = lineplotter.GetXY(t0, x0, y0);
  bool defined1 = lineplotter.GetXY(t1, x1, y1);
  // This really ought to take note of the curvature.
  if (defined0 && defined1 && fabs (x0-x1) + fabs(y0-y1) < 10) {
    long ix0 = long(ROUND(x0));
    long iy0 = long(ROUND(y0));
    long ix1 = long(ROUND(x1));
    long iy1 = long(ROUND(y1));
    DrawLine(ix0,iy0,ix1,iy1,color);
    //CheckSetRgb(ix0,iy0,Rgb(255,255,255));
    //CheckSetRgb(ix1,iy1,Rgb(255,255,255));
  } else {
    int margin = 50;
    // Consider whether to recurse
    // If both points are off to one side or above or below the image,
    // don't recurse, we assume that the line doesn't pass through.
    long sidex0 = (x0 > width + margin) ? 1 : (x0 < -margin) ? -1 : 0;
    long sidey0 = (y0 > height + margin) ? 1 : (y0 < -margin) ? -1 : 0;
    long sidex1 = (x1 > width + margin) ? 1 : (x1 < -margin) ? -1 : 0;
    long sidey1 = (y1 > height + margin) ? 1 : (y1 < -margin) ? 1 : 0;
    if ((defined0 || defined1) && sidex0 * sidex1 + sidey0 * sidey1 <= 0) {
#if 0
      double t2 = (t0 + t0 + t1) / 3;
      PlotLineAux(t0, t2, lineplotter, color, depth-1);
      double t3 = (t0 + t1 + t1) / 3;
      PlotLineAux(t2, t3, lineplotter, color, depth-1);
      PlotLineAux(t3, t1, lineplotter, color, depth-1);
#else
      double t2 = (t0 + t1) / 2;
      PlotLineAux(t0, t2, lineplotter, color, depth-1);
      PlotLineAux(t2, t1, lineplotter, color, depth-1);
#endif
    } else {
#if 0
      fprintf(stderr, "Giving up: %f %f %f %f %f %f\n",
              t0, t1, x0, y0, x1, y1);
#endif
    }
    
  }
}

// Assembly:
testl %ecx, %ecx
je 0xc634
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %ebp
movq %rsi, %r15
movq %rdi, %r14
movq %rdx, 0x20(%rsp)
xorl %eax, %eax
leaq 0x40(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x38(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x30(%rsp), %r13
movq %rax, (%r13)
leaq 0x28(%rsp), %rbx
movq %rax, (%rbx)
movq (%r15), %rax
movq %r15, %rdi
movsd %xmm0, 0x18(%rsp)
movsd %xmm1, 0x8(%rsp)
callq *(%rax)
movl %eax, %r12d
movq (%r15), %rax
movq %r15, %rdi
movsd 0x8(%rsp), %xmm0
movq %r13, %rsi
movq %rbx, %rdx
callq *(%rax)
movl %r12d, %ecx
andb %al, %cl
cmpb $0x1, %cl
jne 0xc52c
movsd 0x40(%rsp), %xmm0
movsd 0x30(%rsp), %xmm5
movapd %xmm0, %xmm1
subsd %xmm5, %xmm1
movapd 0xf8d(%rip), %xmm2      # 0xd400
andpd %xmm2, %xmm1
movsd 0x38(%rsp), %xmm6
movsd 0x28(%rsp), %xmm4
movapd %xmm6, %xmm3
subsd %xmm4, %xmm3
andpd %xmm2, %xmm3
addsd %xmm1, %xmm3
movsd 0x151d(%rip), %xmm1     # 0xd9b8
ucomisd %xmm3, %xmm1
jbe 0xc52c
addsd 0xf8b(%rip), %xmm0      # 0xd438
movsd %xmm4, 0x8(%rsp)
movsd %xmm5, 0x18(%rsp)
movsd %xmm6, 0x10(%rsp)
callq 0x4320
cvttsd2si %xmm0, %rbx
movsd 0x10(%rsp), %xmm0
addsd 0xf61(%rip), %xmm0      # 0xd438
callq 0x4320
cvttsd2si %xmm0, %r15
movsd 0x18(%rsp), %xmm0
addsd 0xf49(%rip), %xmm0      # 0xd438
callq 0x4320
cvttsd2si %xmm0, %r12
movsd 0x8(%rsp), %xmm0
addsd 0xf31(%rip), %xmm0      # 0xd438
callq 0x4320
cvttsd2si %xmm0, %r8
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
movq 0x20(%rsp), %r9
callq 0xbf1a
jmp 0xc626
orb %al, %r12b
cmpb $0x1, %r12b
jne 0xc626
movq (%r14), %rax
movq 0x8(%r14), %rcx
addq $0x32, %rcx
movsd 0x30(%rsp), %xmm2
addq $0x32, %rax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movsd 0x1462(%rip), %xmm0     # 0xd9c0
xorl %eax, %eax
ucomisd %xmm2, %xmm0
seta %al
negq %rax
ucomisd %xmm1, %xmm2
movl $0x1, %edx
cmovaq %rdx, %rax
xorps %xmm2, %xmm2
cvtsi2sd %rcx, %xmm2
movsd 0x38(%rsp), %xmm3
xorl %ecx, %ecx
ucomisd %xmm3, %xmm0
seta %cl
negq %rcx
ucomisd %xmm2, %xmm3
cmovaq %rdx, %rcx
movsd 0x40(%rsp), %xmm3
xorl %esi, %esi
ucomisd %xmm3, %xmm0
seta %sil
negq %rsi
ucomisd %xmm1, %xmm3
movsd 0x28(%rsp), %xmm1
cmovaq %rdx, %rsi
imulq %rax, %rsi
xorl %eax, %eax
ucomisd %xmm2, %xmm1
cmovaq %rcx, %rax
ucomisd %xmm1, %xmm0
cmovaq %rcx, %rax
addq %rsi, %rax
jg 0xc626
movsd 0x18(%rsp), %xmm0
movapd %xmm0, %xmm1
addsd 0x8(%rsp), %xmm1
mulsd 0xe4b(%rip), %xmm1      # 0xd438
movsd %xmm1, 0x10(%rsp)
decl %ebp
movq %r14, %rdi
movq %r15, %rsi
movq 0x20(%rsp), %rbx
movq %rbx, %rdx
movl %ebp, %ecx
callq 0xc3d8
movq %r14, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
movq %r15, %rsi
movq %rbx, %rdx
movl %ebp, %ecx
callq 0xc3d8
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop