// File: /workspace/github_cpp_makefile_star2_O2/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 0xb8cb
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, %ebp
movq %rsi, %r15
movq %rdi, %r14
movq %rdx, 0x18(%rsp)
leaq 0x38(%rsp), %rsi
andq $0x0, (%rsi)
leaq 0x30(%rsp), %rdx
andq $0x0, (%rdx)
leaq 0x28(%rsp), %r13
andq $0x0, (%r13)
leaq 0x20(%rsp), %rbx
andq $0x0, (%rbx)
movq (%r15), %rax
movq %r15, %rdi
movsd %xmm0, 0x50(%rsp)
movsd %xmm1, (%rsp)
callq *(%rax)
movl %eax, %r12d
movq (%r15), %rax
movq %r15, %rdi
movsd (%rsp), %xmm0
movq %r13, %rsi
movq %rbx, %rdx
callq *(%rax)
movl %r12d, %ecx
andb %al, %cl
cmpb $0x1, %cl
jne 0xb7cd
movsd 0x38(%rsp), %xmm0
movsd 0x28(%rsp), %xmm4
movsd 0x30(%rsp), %xmm5
movsd 0x20(%rsp), %xmm3
movapd %xmm0, %xmm1
unpcklpd %xmm5, %xmm1            # xmm1 = xmm1[0],xmm5[0]
movapd %xmm4, %xmm2
unpcklpd %xmm3, %xmm2            # xmm2 = xmm2[0],xmm3[0]
subpd %xmm2, %xmm1
andpd 0xda3(%rip), %xmm1      # 0xc4d0
pshufd $0xee, %xmm1, %xmm2     # xmm2 = xmm1[2,3,2,3]
addsd %xmm1, %xmm2
movsd 0x1282(%rip), %xmm1     # 0xc9c0
ucomisd %xmm2, %xmm1
jbe 0xb7cd
addsd 0xca0(%rip), %xmm0      # 0xc3f0
movapd %xmm3, (%rsp)
movapd %xmm4, 0x50(%rsp)
movapd %xmm5, 0x40(%rsp)
callq 0x4340
cvttsd2si %xmm0, %rbx
movapd 0x40(%rsp), %xmm0
addsd 0xc77(%rip), %xmm0      # 0xc3f0
callq 0x4340
cvttsd2si %xmm0, %r15
movapd 0x50(%rsp), %xmm0
addsd 0xc5f(%rip), %xmm0      # 0xc3f0
callq 0x4340
cvttsd2si %xmm0, %r12
movapd (%rsp), %xmm0
addsd 0xc48(%rip), %xmm0      # 0xc3f0
callq 0x4340
cvttsd2si %xmm0, %r8
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
movq 0x18(%rsp), %r9
callq 0xb306
jmp 0xb8bd
orb %al, %r12b
cmpb $0x1, %r12b
jne 0xb8bd
movq (%r14), %rax
movq 0x8(%r14), %rcx
addq $0x32, %rcx
movsd 0x28(%rsp), %xmm2
addq $0x32, %rax
cvtsi2sd %rax, %xmm1
movsd 0x11cc(%rip), %xmm0     # 0xc9c8
xorl %eax, %eax
ucomisd %xmm2, %xmm0
seta %al
negq %rax
ucomisd %xmm1, %xmm2
pushq $0x1
popq %rdx
cmovaq %rdx, %rax
cvtsi2sd %rcx, %xmm2
movsd 0x30(%rsp), %xmm3
xorl %ecx, %ecx
ucomisd %xmm3, %xmm0
seta %cl
negq %rcx
ucomisd %xmm2, %xmm3
cmovaq %rdx, %rcx
movsd 0x38(%rsp), %xmm3
xorl %esi, %esi
ucomisd %xmm3, %xmm0
seta %sil
negq %rsi
ucomisd %xmm1, %xmm3
movsd 0x20(%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 0xb8bd
movsd 0x50(%rsp), %xmm0
movapd %xmm0, %xmm1
addsd (%rsp), %xmm1
mulsd 0xb6b(%rip), %xmm1      # 0xc3f0
movsd %xmm1, 0x40(%rsp)
decl %ebp
movq %r14, %rdi
movq %r15, %rsi
movq 0x18(%rsp), %rbx
movq %rbx, %rdx
movl %ebp, %ecx
callq 0xb67a
movq %r14, %rdi
movsd 0x40(%rsp), %xmm0
movsd (%rsp), %xmm1
movq %r15, %rsi
movq %rbx, %rdx
movl %ebp, %ecx
callq 0xb67a
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq