// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::SetWorldToGridTransformation(gaps::R3Box const&)
void R3Grid::
SetWorldToGridTransformation(const R3Box& world_box)
{
  // Just checking
  if (grid_size == 0) return;
  if (world_box.NDimensions() < 3) return;

  // Compute grid origin
  R3Vector grid_diagonal(XResolution()-1, YResolution()-1, ZResolution()-1);
  R3Vector grid_origin = 0.5 * grid_diagonal;

  // Compute world origin
  R3Vector world_diagonal(world_box.XLength(), world_box.YLength(), world_box.ZLength());
  R3Vector world_origin = world_box.Centroid().Vector();

  // Compute scale
  RNScalar scale = FLT_MAX;
  RNScalar xscale = (world_diagonal[0] > 0) ? grid_diagonal[0] / world_diagonal[0] : FLT_MAX;
  if (xscale < scale) scale = xscale;
  RNScalar yscale = (world_diagonal[1] > 0) ? grid_diagonal[1] / world_diagonal[1] : FLT_MAX;
  if (yscale < scale) scale = yscale;
  RNScalar zscale = (world_diagonal[2] > 0) ? grid_diagonal[2] / world_diagonal[2] : FLT_MAX;
  if (zscale < scale) scale = zscale;
  if (scale == FLT_MAX) scale = 1;

  // Compute world-to-grid transformation
  R3Affine affine(R3identity_affine);
  affine.Translate(grid_origin);
  if (scale != 1) affine.Scale(scale);
  affine.Translate(-world_origin);

  // Set transformations
  SetWorldToGridTransformation(affine);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e0, %rsp            # imm = 0x1E0
cmpl $0x0, 0x24c(%rdi)
je 0x2ebed
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x27662
cmpl $0x3, %eax
jl 0x2ebed
movl 0x238(%rbx), %eax
decl %eax
cvtsi2sd %eax, %xmm0
movl 0x23c(%rbx), %eax
decl %eax
cvtsi2sd %eax, %xmm1
movl 0x240(%rbx), %eax
decl %eax
cvtsi2sd %eax, %xmm2
leaq 0xb8(%rsp), %r15
movq %r15, %rdi
callq 0x3d4be
leaq 0x88(%rsp), %rdi
movsd 0x73656(%rip), %xmm0    # 0xa2030
movq %r15, %rsi
callq 0x3de8e
movsd 0x20(%r14), %xmm0
movsd 0x28(%r14), %xmm1
subsd 0x8(%r14), %xmm0
subsd 0x10(%r14), %xmm1
movsd 0x30(%r14), %xmm2
subsd 0x18(%r14), %xmm2
leaq 0xa0(%rsp), %r13
movq %r13, %rdi
callq 0x3d4be
movq (%r14), %rax
leaq 0xd0(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq *0x68(%rax)
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movsd 0x10(%r12), %xmm2
leaq 0x70(%rsp), %rdi
callq 0x3d4be
movsd (%r13), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%r13), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd (%r15), %xmm0
movaps %xmm0, 0x20(%rsp)
movsd 0x8(%r15), %xmm0
movaps %xmm0, 0x30(%rsp)
movsd 0x10(%r13), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%r15), %xmm0
movapd %xmm0, 0x40(%rsp)
leaq 0xb3654(%rip), %rax     # 0xe20e8
addq $0x10, %rax
movq %rax, (%r12)
leaq 0xd8(%rsp), %r14
leaq 0xb7555(%rip), %r15     # 0xe6000
leaq 0x8(%r15), %rsi
movq %r14, %rdi
callq 0x2c5ba
movl $0x88, %esi
addq %rsi, %r12
addq 0xb651a(%rip), %rsi     # 0xe4fe0
movq %r12, %rdi
callq 0x2c5ba
movq 0x108(%r15), %rax
movq %rax, 0x1d8(%rsp)
leaq 0x88(%rsp), %rsi
movq %r14, %rdi
callq 0x2d6f4
movapd 0x20(%rsp), %xmm3
movsd 0x8(%rsp), %xmm2
divsd %xmm2, %xmm3
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
cmpltsd %xmm2, %xmm0
andpd %xmm0, %xmm3
movsd 0x7352a(%rip), %xmm2    # 0xa2040
andnpd %xmm2, %xmm0
orpd %xmm3, %xmm0
minsd %xmm2, %xmm0
movapd 0x30(%rsp), %xmm4
movsd 0x10(%rsp), %xmm5
divsd %xmm5, %xmm4
xorpd %xmm3, %xmm3
cmpltsd %xmm5, %xmm3
andpd %xmm3, %xmm4
andnpd %xmm2, %xmm3
orpd %xmm4, %xmm3
minsd %xmm0, %xmm3
movapd 0x40(%rsp), %xmm0
movsd 0x18(%rsp), %xmm4
divsd %xmm4, %xmm0
cmpltsd %xmm4, %xmm1
andpd %xmm1, %xmm0
andnpd %xmm2, %xmm1
orpd %xmm0, %xmm1
minsd %xmm3, %xmm1
cmpeqsd %xmm1, %xmm2
movsd 0x734bb(%rip), %xmm0    # 0xa2038
andpd %xmm2, %xmm0
andnpd %xmm1, %xmm2
andb $-0x3, 0x1d8(%rsp)
orpd %xmm2, %xmm0
ucomisd 0x7349f(%rip), %xmm0    # 0xa2038
jne 0x2eb9d
jnp 0x2ebad
movq %r14, %rdi
callq 0x2d8a2
andb $-0x3, 0x1d8(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x3e154
leaq 0x58(%rsp), %rsi
movq %r14, %rdi
callq 0x2d6f4
leaq 0xd0(%rsp), %rsi
andb $-0x3, 0x108(%rsi)
movq %rbx, %rdi
callq 0x3336c
leaq 0xd0(%rsp), %rdi
callq 0x2a27c
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x2ec12
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x2a904
jmp 0x2ec22
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x2a27c
movq %rbx, %rdi
callq 0xe7e0