// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Polyline.cpp
// Function: gaps::R3Polyline::VertexDerivative(int) const
R3Vector R3Polyline::
VertexDerivative(int i) const
{
  // Return derivative of polyline at ith vertex
  if (nvertices < 2) return R3zero_vector;
  if (i == 0) {
    RNScalar denom = VertexParameter(1) - VertexParameter(0);
    if (RNIsZero(denom)) return R3zero_vector;
    else return (VertexPosition(1) - VertexPosition(0)) / denom;
  }
  else if (i == nvertices-1) {
    RNScalar denom = VertexParameter(nvertices-1) - VertexParameter(nvertices-2);
    if (RNIsZero(denom)) return R3zero_vector;
    else return (VertexPosition(nvertices-1) - VertexPosition(nvertices-2)) / denom;
  }
  else {
    assert(nvertices > 3);
    RNScalar denom = VertexParameter(i+1) - VertexParameter(i-1);
    if (RNIsZero(denom)) return R3zero_vector;
    else return (VertexPosition(i+1) - VertexPosition(i-1)) / denom;
  }

  // Should never get here
  return R3zero_vector;
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x18(%rsp)
movq %rdi, %rax
movq %rax, 0x20(%rsp)
movq %rdi, 0x130(%rsp)
movq %rsi, 0x128(%rsp)
movl %edx, 0x124(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x28(%rsp)
cmpl $0x2, 0x20(%rax)
jge 0x925c4
movq 0x18(%rsp), %rdi
leaq 0x4e6fe6(%rip), %rsi    # 0x5795a0
callq 0x6fcf0
jmp 0x92864
cmpl $0x0, 0x124(%rsp)
jne 0x926a5
movq 0x28(%rsp), %rdi
movl $0x1, %esi
callq 0x919f0
movq 0x28(%rsp), %rdi
movsd %xmm0, 0x10(%rsp)
xorl %esi, %esi
callq 0x919f0
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x118(%rsp)
movsd 0x118(%rsp), %xmm0
leaq 0xe5ec7(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm1
callq 0x36b80
cmpl $0x0, %eax
je 0x9263d
movq 0x18(%rsp), %rdi
leaq 0x4e6f6d(%rip), %rsi    # 0x5795a0
callq 0x6fcf0
jmp 0x92864
movq 0x28(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
movl $0x1, %edx
callq 0x919b0
movq 0x28(%rsp), %rsi
leaq 0xd0(%rsp), %rdi
xorl %edx, %edx
callq 0x919b0
leaq 0x100(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
callq 0x6eeb0
movq 0x18(%rsp), %rdi
movsd 0x118(%rsp), %xmm0
leaq 0x100(%rsp), %rsi
callq 0x711f0
jmp 0x92864
movq 0x28(%rsp), %rcx
movl 0x124(%rsp), %eax
movl 0x20(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x9279c
movq 0x28(%rsp), %rdi
movl 0x20(%rdi), %esi
subl $0x1, %esi
callq 0x919f0
movq 0x28(%rsp), %rdi
movsd %xmm0, 0x8(%rsp)
movl 0x20(%rdi), %esi
subl $0x2, %esi
callq 0x919f0
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0xc8(%rsp)
movsd 0xc8(%rsp), %xmm0
leaq 0xe5dd5(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm1
callq 0x36b80
cmpl $0x0, %eax
je 0x9272f
movq 0x18(%rsp), %rdi
leaq 0x4e6e7b(%rip), %rsi    # 0x5795a0
callq 0x6fcf0
jmp 0x92864
movq 0x28(%rsp), %rsi
movl 0x20(%rsi), %edx
subl $0x1, %edx
leaq 0x98(%rsp), %rdi
callq 0x919b0
movq 0x28(%rsp), %rsi
movl 0x20(%rsi), %edx
subl $0x2, %edx
leaq 0x80(%rsp), %rdi
callq 0x919b0
leaq 0xb0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
leaq 0x80(%rsp), %rdx
callq 0x6eeb0
movq 0x18(%rsp), %rdi
movsd 0xc8(%rsp), %xmm0
leaq 0xb0(%rsp), %rsi
callq 0x711f0
jmp 0x92864
movq 0x28(%rsp), %rdi
movl 0x124(%rsp), %esi
addl $0x1, %esi
callq 0x919f0
movq 0x28(%rsp), %rdi
movsd %xmm0, (%rsp)
movl 0x124(%rsp), %esi
subl $0x1, %esi
callq 0x919f0
movaps %xmm0, %xmm1
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
movsd 0x78(%rsp), %xmm0
leaq 0xe5cf8(%rip), %rax     # 0x1784e0
movsd (%rax), %xmm1
callq 0x36b80
cmpl $0x0, %eax
je 0x92809
movq 0x18(%rsp), %rdi
leaq 0x4e6d9e(%rip), %rsi    # 0x5795a0
callq 0x6fcf0
jmp 0x92864
movq 0x28(%rsp), %rsi
movl 0x124(%rsp), %edx
addl $0x1, %edx
leaq 0x48(%rsp), %rdi
callq 0x919b0
movq 0x28(%rsp), %rsi
movl 0x124(%rsp), %edx
subl $0x1, %edx
leaq 0x30(%rsp), %rdi
callq 0x919b0
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x6eeb0
movq 0x18(%rsp), %rdi
movsd 0x78(%rsp), %xmm0
leaq 0x60(%rsp), %rsi
callq 0x711f0
movq 0x20(%rsp), %rax
addq $0x138, %rsp            # imm = 0x138
retq
nopw %cs:(%rax,%rax)