// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::CreateEllipsoid(gaps::R3Ellipsoid const&, double)
void R3Mesh::
CreateEllipsoid(const R3Ellipsoid& ellipsoid, RNLength vertex_spacing)
{
  // Get info
  R3Vector radii = ellipsoid.Radii();
  RNLength max_radius = radii[radii.MaxDimension()];
  if (RNIsZero(max_radius)) return ;
  R3Triad axes = ellipsoid.CoordSystem().Axes();
  int saved_nvertices = NVertices();
  
  // Create mesh elements for a sphere of suitable radius
  R3Sphere sphere(R3zero_point, max_radius);
  CreateSphere(sphere, vertex_spacing);

  // Map vertices from unit sphere to ellipsoid
  for (int i = saved_nvertices; i < NVertices(); i++) {
    R3MeshVertex *v = Vertex(i);
    R3Vector p = VertexPosition(v).Vector();
    R3Point position = ellipsoid.Center();
    position += p[0]*(radii[0]/max_radius)*axes[0];
    position += p[1]*(radii[1]/max_radius)*axes[1];
    position += p[2]*(radii[2]/max_radius)*axes[2];
    SetVertexPosition(v, position);
  }
}

// Assembly:
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rdi, 0x1e0(%rsp)
movq %rsi, 0x1d8(%rsp)
movsd %xmm0, 0x1d0(%rsp)
movq 0x1e0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x1d8(%rsp), %rdi
callq 0x39f60
movq %rax, %rsi
leaq 0x1b8(%rsp), %rdi
callq 0x6fcf0
leaq 0x1b8(%rsp), %rdi
callq 0x6ffd0
movl %eax, %esi
leaq 0x1b8(%rsp), %rdi
callq 0x36c00
movsd (%rax), %xmm0
movsd %xmm0, 0x1b0(%rsp)
movsd 0x1b0(%rsp), %xmm0
leaq 0x14d19a(%rip), %rax    # 0x1784e0
movsd (%rax), %xmm1
callq 0x36b80
cmpl $0x0, %eax
je 0x2b359
jmp 0x2b71a
movq 0x1d8(%rsp), %rdi
callq 0x39f70
movq %rax, %rdi
callq 0x39f80
movq %rax, %rsi
leaq 0x168(%rsp), %rdi
callq 0x4ebe0
movq 0xa0(%rsp), %rdi
callq 0x135e0
movl %eax, 0x164(%rsp)
movsd 0x1b0(%rsp), %xmm0
leaq 0x54e10e(%rip), %rsi    # 0x5794b0
leaq 0x138(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x42070
movq 0xa0(%rsp), %rdi
movq 0x98(%rsp), %rsi
movsd 0x1d0(%rsp), %xmm0
callq 0x2a720
jmp 0x2b3d7
movl 0x164(%rsp), %eax
movl %eax, 0x128(%rsp)
movq 0xa0(%rsp), %rdi
movl 0x128(%rsp), %eax
movl %eax, 0x90(%rsp)
callq 0x135e0
movl %eax, 0x94(%rsp)
jmp 0x2b409
movl 0x90(%rsp), %eax
movl 0x94(%rsp), %ecx
cmpl %ecx, %eax
jge 0x2b70d
movq 0xa0(%rsp), %rdi
movl 0x128(%rsp), %esi
callq 0x13630
movq %rax, 0x88(%rsp)
jmp 0x2b43d
movq 0xa0(%rsp), %rdi
movq 0x88(%rsp), %rax
movq %rax, 0x120(%rsp)
movq 0x120(%rsp), %rsi
callq 0x13660
movq %rax, 0x80(%rsp)
jmp 0x2b46c
movq 0x80(%rsp), %rsi
leaq 0x108(%rsp), %rdi
callq 0x36d10
jmp 0x2b483
movq 0x1d8(%rsp), %rdi
callq 0x39f90
movq %rax, 0x78(%rsp)
jmp 0x2b497
movq 0x78(%rsp), %rsi
leaq 0xf0(%rsp), %rdi
callq 0x6eb90
jmp 0x2b4ab
leaq 0x108(%rsp), %rdi
xorl %esi, %esi
callq 0x36c00
movq %rax, 0x70(%rsp)
jmp 0x2b4c1
movq 0x70(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0x1b8(%rsp), %rdi
xorl %esi, %esi
callq 0x36c00
movq %rax, 0x68(%rsp)
jmp 0x2b4e6
movsd 0x60(%rsp), %xmm0
movq 0x68(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x1b0(%rsp), %xmm2
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
leaq 0x168(%rsp), %rdi
xorl %esi, %esi
callq 0x39fb0
movq %rax, 0x58(%rsp)
jmp 0x2b522
movq 0x58(%rsp), %rsi
movsd 0x50(%rsp), %xmm0
leaq 0xd8(%rsp), %rdi
callq 0x13800
jmp 0x2b53c
leaq 0xf0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x6f290
jmp 0x2b553
leaq 0x108(%rsp), %rdi
movl $0x1, %esi
callq 0x36c00
movq %rax, 0x48(%rsp)
jmp 0x2b56c
movq 0x48(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0x1b8(%rsp), %rdi
movl $0x1, %esi
callq 0x36c00
movq %rax, 0x40(%rsp)
jmp 0x2b594
movsd 0x38(%rsp), %xmm0
movq 0x40(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x1b0(%rsp), %xmm2
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x168(%rsp), %rdi
movl $0x1, %esi
callq 0x39fb0
movq %rax, 0x30(%rsp)
jmp 0x2b5d3
movq 0x30(%rsp), %rsi
movsd 0x28(%rsp), %xmm0
leaq 0xc0(%rsp), %rdi
callq 0x13800
jmp 0x2b5ed
leaq 0xf0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x6f290
jmp 0x2b604
leaq 0x108(%rsp), %rdi
movl $0x2, %esi
callq 0x36c00
movq %rax, 0x20(%rsp)
jmp 0x2b61d
movq 0x20(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x1b8(%rsp), %rdi
movl $0x2, %esi
callq 0x36c00
movq %rax, 0x18(%rsp)
jmp 0x2b645
movsd 0x10(%rsp), %xmm0
movq 0x18(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x1b0(%rsp), %xmm2
divsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
leaq 0x168(%rsp), %rdi
movl $0x2, %esi
callq 0x39fb0
movq %rax, 0x8(%rsp)
jmp 0x2b683
movq 0x8(%rsp), %rsi
movsd (%rsp), %xmm0
leaq 0xa8(%rsp), %rdi
callq 0x13800
jmp 0x2b69c
leaq 0xf0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x6f290
jmp 0x2b6b3
movq 0xa0(%rsp), %rdi
movq 0x120(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
callq 0x18060
jmp 0x2b6d2
jmp 0x2b6d4
movl 0x128(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x128(%rsp)
jmp 0x2b3e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x130(%rsp)
movl %eax, 0x12c(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x38e60
jmp 0x2b722
leaq 0x138(%rsp), %rdi
callq 0x38e60
addq $0x1e8, %rsp            # imm = 0x1E8
retq
movq 0x130(%rsp), %rdi
callq 0xf890
nop