// File: tomfunkhouser[P]gaps/pkgs/GSV/GSVSegment.cpp
// Function: gaps::GSVSegment::Front(double) const
R3Vector GSVSegment::
Front(RNScalar timestamp) const
{
  // Interpolate panorama front vectors
  if (NPanoramas() == 0) return R3zero_vector;
  GSVPanorama *panorama0 = FindPanoramaBeforeTimestamp(timestamp);
  if (!panorama0) return R3zero_vector;
  int i0 = panorama0->SegmentIndex();
  if (i0 >= NPanoramas()-1) return panorama0->Front();
  GSVPanorama *panorama1 = Panorama(i0 + 1);
  RNScalar t0 = panorama0->Timestamp();
  RNScalar t1 = panorama1->Timestamp();
  if (t1 <= t0) return panorama0->Front();
  RNScalar t = (timestamp - t0) / (t1 - t0);
  if (t <= 0) return panorama0->Front();
  else if (t >= 1) return panorama1->Front();
  R3Vector front = (1 - t) * panorama0->Front() + t * panorama1->Front();

  // Make sure orhtogonal to positive z (up)
  front[2] = 0; front.Normalize();

  // Return front direction of the car at timestamp
  return front;
}

// Assembly:
subq $0xa8, %rsp
movq %rdi, 0x18(%rsp)
movq %rdi, %rax
movq %rax, 0x20(%rsp)
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movsd %xmm0, 0x90(%rsp)
movq 0x98(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x3a290
cmpl $0x0, %eax
jne 0x48bba
movq 0x18(%rsp), %rdi
leaq 0x6ba7e0(%rip), %rsi    # 0x703390
callq 0x180f30
jmp 0x48dc8
movq 0x28(%rsp), %rdi
movsd 0x90(%rsp), %xmm0
callq 0x48770
movq %rax, 0x88(%rsp)
cmpq $0x0, 0x88(%rsp)
jne 0x48bf6
movq 0x18(%rsp), %rdi
leaq 0x6ba7a4(%rip), %rsi    # 0x703390
callq 0x180f30
jmp 0x48dc8
movq 0x88(%rsp), %rdi
callq 0x4a680
movq 0x28(%rsp), %rdi
movl %eax, 0x84(%rsp)
movl 0x84(%rsp), %eax
movl %eax, 0x14(%rsp)
callq 0x3a290
movl %eax, %ecx
movl 0x14(%rsp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
jl 0x48c4b
movq 0x88(%rsp), %rdi
callq 0x4a6d0
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x180f30
jmp 0x48dc8
movq 0x28(%rsp), %rdi
movl 0x84(%rsp), %esi
addl $0x1, %esi
callq 0x3a2b0
movq %rax, 0x78(%rsp)
movq 0x88(%rsp), %rdi
callq 0x44d90
movsd %xmm0, 0x70(%rsp)
movq 0x78(%rsp), %rdi
callq 0x44d90
movsd %xmm0, 0x68(%rsp)
movsd 0x68(%rsp), %xmm1
movsd 0x70(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x48cb8
movq 0x88(%rsp), %rdi
callq 0x4a6d0
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x180f30
jmp 0x48dc8
movsd 0x90(%rsp), %xmm0
subsd 0x70(%rsp), %xmm0
movsd 0x68(%rsp), %xmm1
subsd 0x70(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x60(%rsp), %xmm0
jb 0x48d07
movq 0x88(%rsp), %rdi
callq 0x4a6d0
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x180f30
jmp 0x48dc8
movsd 0x60(%rsp), %xmm0
movsd 0x21d2fb(%rip), %xmm1   # 0x266010
ucomisd %xmm1, %xmm0
jb 0x48d37
movq 0x78(%rsp), %rdi
callq 0x4a6d0
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x180f30
jmp 0x48dc8
jmp 0x48d39
movsd 0x21d2cf(%rip), %xmm0   # 0x266010
subsd 0x60(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq 0x88(%rsp), %rdi
callq 0x4a6d0
movsd (%rsp), %xmm0
movq %rax, %rsi
leaq 0x48(%rsp), %rdi
callq 0x38f20
movsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x78(%rsp), %rdi
callq 0x4a6d0
movsd 0x8(%rsp), %xmm0
movq %rax, %rsi
leaq 0x30(%rsp), %rdi
callq 0x38f20
movq 0x18(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x182270
movq 0x18(%rsp), %rdi
movl $0x2, %esi
callq 0x4a710
movq 0x18(%rsp), %rdi
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
callq 0x181650
movq 0x20(%rsp), %rax
addq $0xa8, %rsp
retq
nopw %cs:(%rax,%rax)