// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/GSV/GSVImage.cpp
// Function: gaps::GSVImage::RayThroughUndistortedPosition(gaps::R2Point const&) const
R3Ray GSVImage::
RayThroughUndistortedPosition(const R2Point& undistorted_image_position) const
{
  // Check camera
  if (!Camera()) return R3null_ray;

  // Compute distorted image position
  R2Point distorted_image_position = DistortedPosition(undistorted_image_position);
  if (distorted_image_position == R2Point(-1,-1)) return R3null_ray;
  
  // Get column index
  int column_index = (int) (distorted_image_position.X() + 0.5);
  if (column_index < 0) column_index = 0;
  if (column_index >= Width()) column_index = Width()-1;
      
  // Get camera pose
  GSVPose pose = Pose(column_index);
  const R3Point& viewpoint = pose.Viewpoint();
  const R3Vector& towards = pose.Towards();
  const R3Vector& up = pose.Up();
  R3Vector right = towards % up;

  // Compute point on ray
  RNScalar dx = (RNScalar) (2 * (undistorted_image_position.X() - 0.5 * Width())) / (RNScalar) Width();
  RNScalar dy = (RNScalar) (2 * (undistorted_image_position.Y() - 0.5 * Height())) / (RNScalar) Height();
  R3Point world_point = viewpoint + towards;
  world_point += dx * right * tan(0.5 * Camera()->XFov());
  world_point += dy * up * tan(0.5 * Camera()->YFov());

  // Return ray through undistorted image point
  return R3Ray(viewpoint, world_point);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x110, %rsp            # imm = 0x110
movq %rdi, %rbx
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x3e248
cmpq $0x0, 0x18(%rax)
je 0x3e248
movq %rdx, %r15
movq %rsi, %r14
leaq 0xa8(%rsp), %r12
movq %r12, %rdi
callq 0x3dc72
leaq 0xb8(%rsp), %r13
movsd 0x10fe43(%rip), %xmm0   # 0x14e070
movq %r13, %rdi
movapd %xmm0, %xmm1
callq 0xf3306
movq %r12, %rdi
movq %r13, %rsi
callq 0xf35d6
testl %eax, %eax
je 0x3e26b
leaq 0x5a3161(%rip), %rsi    # 0x5e13b0
movq %rbx, %rdi
callq 0xd5a16
movq %rbx, %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movsd 0xa8(%rsp), %xmm0
addsd 0x10fd94(%rip), %xmm0   # 0x14e010
cvttsd2si %xmm0, %edx
xorl %ecx, %ecx
testl %edx, %edx
cmovlel %ecx, %edx
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x3e296
movq 0x18(%rax), %rsi
jmp 0x3e298
xorl %esi, %esi
testq %rsi, %rsi
je 0x3e2aa
movl 0x2c(%rsi), %esi
testl %esi, %esi
movl $0x790, %ecx            # imm = 0x790
cmovnsl %esi, %ecx
cmpl %ecx, %edx
jl 0x3e2d7
testq %rax, %rax
je 0x3e2b9
movq 0x18(%rax), %rax
jmp 0x3e2bb
xorl %eax, %eax
testq %rax, %rax
je 0x3e2d2
movl 0x2c(%rax), %eax
leal -0x1(%rax), %ecx
testl %eax, %eax
movl $0x78f, %edx            # imm = 0x78F
cmovnsl %ecx, %edx
jmp 0x3e2d7
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
leaq 0xb8(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x3d698
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
callq 0x455c6
leaq 0x78(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x4560c
leaq 0xf8(%rsp), %rdi
leaq 0x90(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0xd721a
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x3e335
movq 0x18(%rax), %rcx
jmp 0x3e337
xorl %ecx, %ecx
testq %rcx, %rcx
je 0x3e352
movl 0x2c(%rcx), %ecx
testl %ecx, %ecx
movl $0x790, %edx            # imm = 0x790
cmovnsl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
jmp 0x3e356
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
testq %rax, %rax
je 0x3e367
movq 0x18(%rax), %rcx
jmp 0x3e369
xorl %ecx, %ecx
testq %rcx, %rcx
je 0x3e384
movl 0x2c(%rcx), %ecx
testl %ecx, %ecx
movl $0x790, %edx            # imm = 0x790
cmovnsl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
jmp 0x3e388
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
testq %rax, %rax
je 0x3e399
movq 0x18(%rax), %rcx
jmp 0x3e39b
xorl %ecx, %ecx
testq %rcx, %rcx
je 0x3e3b6
movl 0x30(%rcx), %ecx
testl %ecx, %ecx
movl $0xa20, %edx            # imm = 0xA20
cmovnsl %ecx, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
jmp 0x3e3ba
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
testq %rax, %rax
je 0x3e3cb
movq 0x18(%rax), %rax
jmp 0x3e3cd
xorl %eax, %eax
leaq 0xc0(%rsp), %r12
testq %rax, %rax
je 0x3e3f0
movl 0x30(%rax), %eax
testl %eax, %eax
movl $0xa20, %ecx            # imm = 0xA20
cmovnsl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
jmp 0x3e3f4
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movsd (%r15), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x8(%r15), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x90(%rsp), %rdx
movq %r12, %rsi
callq 0xd6179
movsd 0x18(%rsp), %xmm0
mulsd 0x10fcbd(%rip), %xmm0   # 0x14e0f0
addsd 0x28(%rsp), %xmm0
addsd %xmm0, %xmm0
divsd 0x10(%rsp), %xmm0
leaq 0x30(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0xd7296
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x3e464
movq 0x18(%rax), %rax
jmp 0x3e466
xorl %eax, %eax
movsd 0x38(%rax), %xmm1
addsd 0x40(%rax), %xmm1
mulsd 0x10fb98(%rip), %xmm1   # 0x14e010
leaq 0x199fe9(%rip), %r15    # 0x1d8468
movsd (%r15), %xmm2
movapd 0x110824(%rip), %xmm0   # 0x14ecb0
xorpd %xmm2, %xmm0
ucomisd %xmm0, %xmm1
jb 0x3e4a0
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm2
jae 0x3e4d1
movl 0x2c(%rax), %eax
testl %eax, %eax
movl $0x790, %ecx            # imm = 0x790
cmovnsl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd 0x10fb54(%rip), %xmm0   # 0x14e010
divsd %xmm1, %xmm0
callq 0x27790
addsd %xmm0, %xmm0
mulsd 0x10fb3f(%rip), %xmm0   # 0x14e010
callq 0x274e0
leaq 0x48(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xd7296
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0xd6216
movsd 0x8(%rsp), %xmm0
mulsd 0x10fbee(%rip), %xmm0   # 0x14e0f0
addsd 0x20(%rsp), %xmm0
addsd %xmm0, %xmm0
divsd (%rsp), %xmm0
leaq 0x30(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0xd7296
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x3e52f
movq 0x18(%rax), %rax
jmp 0x3e531
xorl %eax, %eax
movsd 0x38(%rax), %xmm1
addsd 0x40(%rax), %xmm1
mulsd 0x10facd(%rip), %xmm1   # 0x14e010
movsd (%r15), %xmm2
movapd 0x110760(%rip), %xmm0   # 0x14ecb0
xorpd %xmm2, %xmm0
ucomisd %xmm0, %xmm1
jb 0x3e564
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm2
jae 0x3e595
movl 0x30(%rax), %eax
testl %eax, %eax
movl $0xa20, %ecx            # imm = 0xA20
cmovnsl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd 0x10fa90(%rip), %xmm0   # 0x14e010
divsd %xmm1, %xmm0
callq 0x27790
addsd %xmm0, %xmm0
mulsd 0x10fa7b(%rip), %xmm0   # 0x14e010
callq 0x274e0
leaq 0x48(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xd7296
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0xd6216
leaq 0x60(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xd5a22
leaq 0xb8(%rsp), %rdi
callq 0x455ba
jmp 0x3e257
jmp 0x3e5e4
jmp 0x3e5e4
jmp 0x3e5e4
jmp 0x3e5e4
jmp 0x3e5e4
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x455ba
movq %rbx, %rdi
callq 0x28160