// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::CreatePlyRangeGridFace(gaps::R3Mesh*, gaps::R3MeshVertex*, gaps::R3MeshVertex*, gaps::R3MeshVertex*, double)
static void
CreatePlyRangeGridFace(R3Mesh *mesh, 
  R3MeshVertex *v0, R3MeshVertex *v1, R3MeshVertex *v2, 
  RNScalar max_aspect_ratio = 8)
{
  // Get vertex positions
  const R3Point& p0 = mesh->VertexPosition(v0);
  const R3Point& p1 = mesh->VertexPosition(v1);
  const R3Point& p2 = mesh->VertexPosition(v2);

  // Get edge lengths
  RNScalar a = R3Distance(p0, p1);
  if (RNIsZero(a)) return;
  RNScalar b = R3Distance(p1, p2);
  if (RNIsZero(b)) return;
  RNScalar c = R3Distance(p2, p0);
  if (RNIsZero(c)) return;

  // Compute aspect ratio
  RNScalar s = (a + b + c) / 2.0;
  RNScalar da = s - a;
  if (RNIsZero(da)) return;
  RNScalar db = s - b;
  if (RNIsZero(db)) return;
  RNScalar dc = s - c;
  if (RNIsZero(dc)) return;
  RNScalar aspect = (a * b * c) / (8.0 * da * db * dc);
  if (aspect > max_aspect_ratio) return;

  // Check edge length ratios
  if (a < b) { RNScalar swap = a; a = b; b = swap; }
  if (a < c) { RNScalar swap = a; a = c; c = swap; }
  if (b < c) { RNScalar swap = b; b = c; c = swap; }
  if (a / c > max_aspect_ratio) return;

  // Create face
  mesh->CreateFace(v0, v1, v2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x8(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, 0x20(%rsp)
leaq 0x18(%rsi), %r13
leaq 0x18(%rdx), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x4321a
leaq 0xbc6f0(%rip), %rbx     # 0xdaba8
movsd (%rbx), %xmm2
movapd 0x74b6c(%rip), %xmm1    # 0x93030
xorpd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1e4d8
ucomisd %xmm0, %xmm2
jae 0x1e5ef
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %r12
movq %rbp, %rdi
movq %r12, %rsi
movsd %xmm0, 0x18(%rsp)
callq 0x4321a
movsd (%rbx), %xmm2
movapd 0x74b32(%rip), %xmm1    # 0x93030
xorpd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1e512
ucomisd %xmm0, %xmm2
jae 0x1e5ef
movq %r12, %rdi
movq %r13, %rsi
movsd %xmm0, 0x10(%rsp)
callq 0x4321a
movsd 0x10(%rsp), %xmm7
movsd 0x18(%rsp), %xmm6
movsd (%rbx), %xmm2
movapd 0x74af5(%rip), %xmm3    # 0x93030
xorpd %xmm2, %xmm3
ucomisd %xmm3, %xmm0
jb 0x1e54f
ucomisd %xmm0, %xmm2
jae 0x1e5ef
movapd %xmm6, %xmm1
addsd %xmm7, %xmm1
addsd %xmm0, %xmm1
mulsd 0x74aad(%rip), %xmm1    # 0x93010
movapd %xmm1, %xmm4
subsd %xmm6, %xmm4
ucomisd %xmm3, %xmm4
jb 0x1e577
ucomisd %xmm4, %xmm2
jae 0x1e5ef
movapd %xmm1, %xmm5
subsd %xmm7, %xmm5
ucomisd %xmm3, %xmm5
jb 0x1e58b
ucomisd %xmm5, %xmm2
jae 0x1e5ef
subsd %xmm0, %xmm1
ucomisd %xmm3, %xmm1
jb 0x1e59b
ucomisd %xmm1, %xmm2
jae 0x1e5ef
movapd %xmm6, %xmm2
mulsd %xmm7, %xmm2
mulsd %xmm0, %xmm2
movsd 0x74c49(%rip), %xmm3    # 0x931f8
mulsd %xmm3, %xmm4
mulsd %xmm4, %xmm5
mulsd %xmm5, %xmm1
divsd %xmm1, %xmm2
ucomisd %xmm3, %xmm2
ja 0x1e5ef
movapd %xmm6, %xmm1
minsd %xmm7, %xmm1
maxsd %xmm6, %xmm7
movapd %xmm7, %xmm2
minsd %xmm0, %xmm2
minsd %xmm2, %xmm1
maxsd %xmm7, %xmm0
divsd %xmm1, %xmm0
ucomisd 0x74c0b(%rip), %xmm0    # 0x931f8
jbe 0x1e5fe
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rdi
movq (%rdi), %rax
movq 0x48(%rax), %rax
movq %r15, %rsi
movq %r14, %rdx
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax