// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::Smooth(double)
void R3Mesh::
Smooth(RNScalar factor)
{
  // Allocate buffer for copy of vertex positions
  R3Point *positions = new R3Point [ NVertices() ];
  if (!positions) RNAbort("Unable to allocate vertex positions");
    
  // Iteratively average vertex positions
  for (int iter = 0; iter < factor; iter++) {
    // Copy vertex positions
    for (int i = 0; i < NVertices(); i++) {
      R3MeshVertex *vertex = Vertex(i);
      positions[i] = VertexPosition(vertex);
    }

    // Update vertex positions
    for (int i = 0; i < NVertices(); i++) {
      R3MeshVertex *vertex = Vertex(i);
      RNScalar weight = 1;
      R3Point position = positions[vertex->id];
      RNLength radius = VertexAverageEdgeLength(vertex);
      if (radius > 0) {
        for (int j = 0; j < VertexValence(vertex); j++) {
          R3MeshEdge *edge = EdgeOnVertex(vertex, j);
          R3MeshVertex *neighbor_vertex = VertexAcrossEdge(edge, vertex);
          const R3Point& neighbor_position = positions[neighbor_vertex->id];
          RNLength length = EdgeLength(edge);
          RNLength sigma = (length > 0) ? length / radius : 1;
          RNScalar w = exp((length * length) / (-2.0 * sigma * sigma));
          position += w * neighbor_position;
          weight += w;
        }
      
        // Update vertex position
        R3Point smooth_position = position / weight;
        SetVertexPosition(vertex, smooth_position);
      }
    }
  }
  
  // Delete copy of vertex positions
  delete [] positions;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movsd %xmm0, 0x8(%rsp)
movq %rdi, %rbx
movslq 0x14(%rdi), %r12
pushq $0x18
popq %rcx
movq %r12, %rax
mulq %rcx
pushq $-0x1
popq %r15
cmovnoq %rax, %r15
movq %r15, %rdi
callq 0xe030
movq %rax, %r14
testq %r12, %r12
je 0x133c9
imulq $0x18, %r12, %r12
xorl %r13d, %r13d
leaq (%r14,%r13), %rdi
callq 0x37b4a
addq $0x18, %r13
cmpq %r13, %r12
jne 0x133b7
xorl %eax, %eax
leaq 0x50(%rsp), %r12
cvtsi2sd %eax, %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x13557
movq %rax, 0x10(%rsp)
movq %r14, %r13
xorl %r15d, %r15d
movslq 0x14(%rbx), %rax
cmpq %rax, %r15
jge 0x13415
movq 0x8(%rbx), %rax
movq (%rax,%r15,8), %rsi
addq $0x18, %rsi
movq %r13, %rdi
callq 0x37e36
incq %r15
addq $0x18, %r13
jmp 0x133ef
xorl %r15d, %r15d
cltq
cmpq %rax, %r15
jge 0x1354b
movq 0x8(%rbx), %rax
movq (%rax,%r15,8), %r13
movslq 0x70(%r13), %rax
imulq $0x18, %rax, %rsi
addq %r14, %rsi
leaq 0x38(%rsp), %rdi
callq 0x37b5c
movq %rbx, %rdi
movq %r13, %rsi
callq 0x12380
movsd %xmm0, 0x20(%rsp)
ucomisd 0x7fd8f(%rip), %xmm0    # 0x931e8
jbe 0x13540
movq %r15, 0x18(%rsp)
xorl %r15d, %r15d
movsd 0x7fb99(%rip), %xmm0    # 0x93008
movslq 0x14(%r13), %rax
cmpq %rax, %r15
jge 0x13520
movsd %xmm0, 0x30(%rsp)
movq 0x8(%r13), %rax
movq (%rax,%r15,8), %rsi
movq 0x8(%rsi), %rax
cmpq %r13, %rax
jne 0x13497
movq 0x10(%rsi), %rax
movslq 0x70(%rax), %rax
imulq $0x18, %rax, %rbp
addq %r14, %rbp
movq %rbx, %rdi
callq 0x10db2
movapd %xmm0, %xmm1
divsd 0x20(%rsp), %xmm1
xorpd %xmm2, %xmm2
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
movsd 0x7fb3f(%rip), %xmm3    # 0x93008
andnpd %xmm3, %xmm2
orpd %xmm1, %xmm2
mulsd %xmm0, %xmm0
movapd %xmm2, %xmm1
mulsd 0x7fd1f(%rip), %xmm1    # 0x93200
mulsd %xmm2, %xmm1
divsd %xmm1, %xmm0
callq 0xe820
movsd %xmm0, 0x28(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x382c0
leaq 0x38(%rsp), %rdi
movq %r12, %rsi
callq 0x381b6
movsd 0x30(%rsp), %xmm0
addsd 0x28(%rsp), %xmm0
incq %r15
jmp 0x1346f
movq %r12, %rdi
leaq 0x38(%rsp), %rsi
callq 0x382e2
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x12ccc
movq 0x18(%rsp), %r15
incq %r15
movl 0x14(%rbx), %eax
jmp 0x13418
movq 0x10(%rsp), %rax
incl %eax
jmp 0x133d0
movq %r14, %rdi
callq 0xe5d0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r14, %rdi
movq %r15, %rsi
callq 0xe8f0
movq %rbx, %rdi
callq 0xe810