// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::VertexLaplacianVector(gaps::R3MeshVertex const*) const
R3Vector R3Mesh::
VertexLaplacianVector(const R3MeshVertex *v1) const
{
  // Compute vector from vertex to cotan weighed average of neighbors 
  // From http://www.mpi-inf.mpg.de/~ag4-gm/handouts/06gm_surf3.pdf
  R3Vector laplacian = R3zero_vector;
  const R3Point& p1 = VertexPosition(v1);
  for (int j = 0; j < VertexValence(v1); j++) {
    R3MeshEdge *e = EdgeOnVertex(v1, j);
    R3MeshVertex *v2 = VertexAcrossEdge(e, v1);
    const R3Point& p2 = VertexPosition(v2);

    // Compute cotan weight
    double weight = 0;
    for (int k = 0; k < 2; k++) {
      R3MeshFace *f = FaceOnEdge(e, k);
      if (!f) continue;
      R3MeshVertex *v3 = VertexAcrossFace(f, e);
      const R3Point& p3 = VertexPosition(v3);
      R3Vector vec1 = p1 - p3; vec1.Normalize();
      R3Vector vec2 = p2 - p3; vec2.Normalize();
      RNAngle angle = R3InteriorAngle(vec1, vec2);
      if (angle == 0) continue; 
      double tan_angle = tan(angle);
      if (tan_angle == 0) continue; 
      weight += 1.0 / tan_angle;
    }

    // Add weighted position
    laplacian += weight * (p2 - p1);
  }

  // Normalize by area (maybe should be 3X -- i.e., for face areas, not vertex area)
  laplacian /= 4 * VertexArea(v1);

  // Return laplacian vector
  return laplacian;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %rbx
movq %rsi, 0x20(%rsp)
leaq 0x95719(%rip), %rsi     # 0xa86e0
movq %rdi, (%rsp)
callq 0x3cfd6
cmpl $0x0, 0x14(%rbx)
jle 0x1314a
leaq 0x18(%rbx), %rax
movq %rax, 0x8(%rsp)
xorl %ecx, %ecx
leaq 0x38(%rsp), %r13
leaq 0x50(%rsp), %rbp
movq %rbx, 0x28(%rsp)
movq 0x8(%rbx), %rax
movq (%rax,%rcx,8), %r14
movq 0x8(%r14), %r15
cmpq %rbx, %r15
jne 0x13009
movq 0x10(%r14), %r15
movq %rcx, 0x30(%rsp)
addq $0x18, %r15
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movb $0x1, %r12b
xorl %eax, %eax
movq 0x18(%r14,%rax,8), %rax
testq %rax, %rax
je 0x130ee
movq 0x8(%rax), %rbx
movq 0x8(%r14), %rcx
cmpq %rbx, %rcx
je 0x13042
cmpq %rbx, 0x10(%r14)
jne 0x1306b
movq 0x10(%rax), %rbx
cmpq %rbx, %rcx
je 0x13051
cmpq %rbx, 0x10(%r14)
jne 0x1306b
movq 0x18(%rax), %rax
cmpq %rax, %rcx
je 0x13069
cmpq %rax, 0x10(%r14)
movl $0x0, %ebx
cmovneq %rax, %rbx
jmp 0x1306b
xorl %ebx, %ebx
addq $0x18, %rbx
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x3c78e
movq %rbp, %rdi
callq 0x3d2dc
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x3c78e
movq %r13, %rdi
callq 0x3d2dc
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4bc63
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x130b4
jnp 0x130ee
callq 0xe290
movsd 0x8ef77(%rip), %xmm1    # 0xa2038
divsd %xmm0, %xmm1
movapd 0x10(%rsp), %xmm3
addsd %xmm3, %xmm1
cmpeqsd 0x8f110(%rip), %xmm0    # 0xa21e8
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
andpd %xmm3, %xmm0
orpd %xmm2, %xmm0
movapd %xmm0, 0x10(%rsp)
movl $0x1, %eax
testb $0x1, %r12b
movl $0x0, %r12d
jne 0x13021
movq %r13, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0x3c78e
movq %rbp, %rdi
movq %r13, %rsi
movapd 0x10(%rsp), %xmm0
callq 0x3d962
movq (%rsp), %rdi
movq %rbp, %rsi
callq 0x3d984
movq 0x30(%rsp), %rcx
incq %rcx
movq 0x28(%rsp), %rbx
movslq 0x14(%rbx), %rax
cmpq %rax, %rcx
jl 0x12ff4
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x12cc2
mulsd 0x8f091(%rip), %xmm0    # 0xa21f0
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x3db98
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop