// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::CreateSphere(gaps::R3Sphere const&, double)
void R3Mesh::
CreateSphere(const R3Sphere& sphere, RNLength vertex_spacing)
{
  // Create mesh elements for a sphere and add to mesh
  R3Point c = sphere.Centroid();
  RNLength r = sphere.Radius();
  if (vertex_spacing == 0) vertex_spacing = r/5.0;
  if (RNIsZero(vertex_spacing)) return;
  
  // Start with an icosahedron
  R3Mesh tmp;
  tmp.CreateIcosahedron(R3unit_sphere);

  // Iteratively refine until reach vertex spacing
  while (tmp.AverageEdgeLength() > vertex_spacing) {
    // Subdivide
    tmp.SubdivideFaces();

    // Push vertices to unit sphere
    for (int i = 0; i < tmp.NVertices(); i++) {
      R3MeshVertex *v = tmp.Vertex(i);
      R3Point p = tmp.VertexPosition(v);
      RNLength d = p.Vector().Length();
      if (RNIsPositive(d)) p /= d;
      tmp.SetVertexPosition(v, p);
    }
  }

  // Map vertices from unit sphere to specified sphere
  for (int i = 0; i < tmp.NVertices(); i++) {
    R3MeshVertex *v = tmp.Vertex(i);
    R3Point p = tmp.VertexPosition(v);
    RNLength d = p.Vector().Length();
    if (RNIsPositive(d)) p = c+(r/d)*p;
    tmp.SetVertexPosition(v, p);
  }

  // Copy into this mesh
  CreateCopy(tmp);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movaps %xmm0, 0x20(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq (%rsi), %rax
leaq 0x60(%rsp), %rdi
callq *0x68(%rax)
movsd 0x20(%rbx), %xmm0
movsd %xmm0, 0x40(%rsp)
divsd 0x845b2(%rip), %xmm0    # 0xa2258
xorpd %xmm2, %xmm2
movapd 0x20(%rsp), %xmm3
cmpeqsd %xmm3, %xmm2
movapd %xmm2, %xmm1
andnpd %xmm3, %xmm1
andpd %xmm0, %xmm2
orpd %xmm1, %xmm2
leaq 0xc7ecc(%rip), %rbp     # 0xe5b98
movsd (%rbp), %xmm0
movapd 0x84347(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jb 0x1dced
ucomisd %xmm2, %xmm0
jae 0x1de99
movapd %xmm2, 0x20(%rsp)
movq %r14, 0x38(%rsp)
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
callq 0x11578
leaq 0xc8081(%rip), %rsi     # 0xe5d90
movq %rbx, %rdi
callq 0x1d72e
leaq 0x90(%rsp), %r14
leaq 0x8(%rsp), %r15
leaq 0x48(%rsp), %r12
movq %r14, %rdi
callq 0x11ec2
ucomisd 0x20(%rsp), %xmm0
jbe 0x1ddbe
movq %r14, %rdi
callq 0x172dc
cmpl $0x0, 0xa4(%rsp)
jle 0x1dd29
xorl %r13d, %r13d
movq 0x98(%rsp), %rax
movq (%rax,%r13,8), %rbx
leaq 0x18(%rbx), %rsi
movq %r15, %rdi
callq 0x3ca36
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movq %r12, %rdi
callq 0x3d4be
movq %r12, %rdi
callq 0x3d5c4
ucomisd (%rbp), %xmm0
jbe 0x1dd9b
movq %r15, %rdi
callq 0x3d3e4
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x13808
incq %r13
movslq 0xa4(%rsp), %rax
cmpq %rax, %r13
jl 0x1dd52
jmp 0x1dd29
cmpl $0x0, 0xa4(%rsp)
jle 0x1de7a
xorl %r12d, %r12d
leaq 0x8(%rsp), %r14
leaq 0x48(%rsp), %r15
leaq 0x78(%rsp), %r13
movq 0x98(%rsp), %rax
movq (%rax,%r12,8), %rbx
leaq 0x18(%rbx), %rsi
movq %r14, %rdi
callq 0x3ca36
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
movq %r15, %rdi
callq 0x3d4be
movq %r15, %rdi
callq 0x3d5c4
ucomisd (%rbp), %xmm0
jbe 0x1de53
movsd 0x40(%rsp), %xmm1
divsd %xmm0, %xmm1
movq %r13, %rdi
movq %r14, %rsi
movapd %xmm1, %xmm0
callq 0x3d470
movq %r15, %rdi
leaq 0x60(%rsp), %rsi
movq %r13, %rdx
callq 0x3d42a
movq %r14, %rdi
movq %r15, %rsi
callq 0x3cd94
leaq 0x90(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x13808
incq %r12
movslq 0xa4(%rsp), %rax
cmpq %rax, %r12
jl 0x1ddde
leaq 0x90(%rsp), %rsi
movq 0x38(%rsp), %rdi
callq 0x1ded4
leaq 0x90(%rsp), %rdi
callq 0x11aa6
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1debb
jmp 0x1debb
jmp 0x1debb
jmp 0x1debb
jmp 0x1debb
jmp 0x1debb
jmp 0x1debb
jmp 0x1debb
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x11aa6
movq %rbx, %rdi
callq 0xe7e0
nop