// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %rsp
movq %rdx, %r15
movq %rsi, 0x10(%rsp)
leaq 0x870b1(%rip), %rsi     # 0x99690
movq %rdi, 0x8(%rsp)
callq 0x3831c
leaq 0x18(%r15), %rax
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
leaq 0x48(%rsp), %r13
leaq 0x60(%rsp), %rbp
movq %r15, 0x38(%rsp)
movslq 0x14(%r15), %rax
cmpq %rax, %rcx
jge 0x1272b
movq 0x8(%r15), %rax
movq %rcx, 0x40(%rsp)
movq (%rax,%rcx,8), %r14
movq 0x8(%r14), %rbx
cmpq %r15, %rbx
jne 0x1262a
movq 0x10(%r14), %rbx
addq $0x18, %rbx
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
pushq $0x3
popq %r12
cmpq $0x5, %r12
je 0x126eb
movq (%r14,%r12,8), %rsi
testq %rsi, %rsi
je 0x126e3
movq 0x10(%rsp), %rdi
movq %r14, %rdx
callq 0x2136e
leaq 0x18(%rax), %r15
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
callq 0x37d29
movq %rbp, %rdi
callq 0x3860e
movq %r13, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x37d29
movq %r13, %rdi
callq 0x3860e
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4555f
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x126a9
jnp 0x126e3
callq 0xe2a0
xorpd %xmm2, %xmm2
movsd 0x8094e(%rip), %xmm1    # 0x93008
divsd %xmm0, %xmm1
movapd 0x20(%rsp), %xmm3
addsd %xmm3, %xmm1
cmpeqsd %xmm2, %xmm0
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
andpd %xmm3, %xmm0
orpd %xmm2, %xmm0
movapd %xmm0, 0x20(%rsp)
incq %r12
jmp 0x1263c
movq %r13, %rdi
movq %rbx, %rsi
movq 0x18(%rsp), %rdx
callq 0x37d29
movq %rbp, %rdi
movq %r13, %rsi
movapd 0x20(%rsp), %xmm0
callq 0x38a02
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x38a24
movq 0x40(%rsp), %rcx
incq %rcx
movq 0x38(%rsp), %r15
jmp 0x12603
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x1230a
mulsd 0x80ab0(%rip), %xmm0    # 0x931f0
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x38c0a
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop