// File: /workspace/github_cpp_makefile_star2_O1/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 0x95757(%rip), %rsi     # 0xa86e0
movq %rdi, (%rsp)
callq 0x3d4ce
cmpl $0x0, 0x14(%rbx)
jle 0x13102
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 0x12fcb
movq 0x10(%r14), %r15
movq %rcx, 0x30(%rsp)
addq $0x18, %r15
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
xorl %r12d, %r12d
movq 0x18(%r14,%r12,8), %rax
testq %rax, %rax
je 0x130ae
movq 0x8(%rax), %rbx
movq 0x8(%r14), %rcx
cmpq %rbx, %rcx
je 0x13002
cmpq %rbx, 0x10(%r14)
jne 0x1302b
movq 0x10(%rax), %rbx
cmpq %rbx, %rcx
je 0x13011
cmpq %rbx, 0x10(%r14)
jne 0x1302b
movq 0x18(%rax), %rax
cmpq %rax, %rcx
je 0x13029
cmpq %rax, 0x10(%r14)
movl $0x0, %ebx
cmovneq %rax, %rbx
jmp 0x1302b
xorl %ebx, %ebx
addq $0x18, %rbx
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
callq 0x3cc88
movq %rbp, %rdi
callq 0x3d7e0
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x3cc88
movq %r13, %rdi
callq 0x3d7e0
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4c77b
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x13074
jnp 0x130ae
callq 0xe290
movsd 0x8efb7(%rip), %xmm1    # 0xa2038
divsd %xmm0, %xmm1
movapd 0x10(%rsp), %xmm3
addsd %xmm3, %xmm1
cmpeqsd 0x8f150(%rip), %xmm0    # 0xa21e8
movapd %xmm0, %xmm2
andnpd %xmm1, %xmm2
andpd %xmm3, %xmm0
orpd %xmm2, %xmm0
movapd %xmm0, 0x10(%rsp)
incq %r12
cmpq $0x1, %r12
je 0x12fe1
movq %r13, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rdx
callq 0x3cc88
movq %rbp, %rdi
movq %r13, %rsi
movapd 0x10(%rsp), %xmm0
callq 0x3de8e
movq (%rsp), %rdi
movq %rbp, %rsi
callq 0x3deb0
movq 0x30(%rsp), %rcx
incq %rcx
movq 0x28(%rsp), %rbx
movslq 0x14(%rbx), %rax
cmpq %rax, %rcx
jl 0x12fb6
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x12c5e
mulsd 0x8f0d9(%rip), %xmm0    # 0xa21f0
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x3e0ec
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop