// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::SetWorldToGridTransformation(gaps::R3Point const&, gaps::R3Vector const&, gaps::R3Vector const&, double)
void R3Grid::
SetWorldToGridTransformation(const R3Point& world_origin, const R3Vector& world_axis1, const R3Vector& world_axis2, RNLength world_radius)
{
  // Just checking
  if (grid_size == 0) return;

  // Compute grid origin
  R3Vector grid_diagonal(XResolution()-1, YResolution()-1, ZResolution()-1);
  R3Vector grid_origin = 0.5 * grid_diagonal;
  RNScalar grid_radius = grid_origin[0];
  if (grid_origin[1] < grid_radius) grid_radius = grid_origin[1];
  if (grid_origin[2] < grid_radius) grid_radius = grid_origin[2];

  // Compute scale
  if (RNIsZero(world_radius)) return;
  if (RNIsZero(grid_radius)) return;
  RNScalar scale = grid_radius / world_radius;

  // Compute rotation
  R3Triad world_triad(world_axis1, world_axis2);
  R3Affine rotation(world_triad.InverseMatrix());

  // Compute world-to-grid transformation
  R3Affine affine(R3identity_affine);
  affine.Translate(grid_origin);
  affine.Transform(rotation);
  affine.Scale(scale);
  affine.Translate(-(world_origin.Vector()));

  // Set transformations
  SetWorldToGridTransformation(affine);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2d8, %rsp            # imm = 0x2D8
cmpl $0x0, 0x24c(%rdi)
je 0x319f4
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
movl 0x238(%rdi), %eax
decl %eax
movsd %xmm0, (%rsp)
cvtsi2sd %eax, %xmm0
movl 0x23c(%rdi), %eax
decl %eax
cvtsi2sd %eax, %xmm1
movl 0x240(%rdi), %eax
decl %eax
cvtsi2sd %eax, %xmm2
leaq 0x58(%rsp), %r13
movq %r13, %rdi
callq 0x3830c
leaq 0x40(%rsp), %rbp
movsd 0x6174d(%rip), %xmm0    # 0x93010
movq %rbp, %rdi
movq %r13, %rsi
callq 0x38a02
movsd 0x8(%rbp), %xmm1
movsd 0x10(%rbp), %xmm3
minsd (%rbp), %xmm1
leaq 0xa92c4(%rip), %rax     # 0xdaba8
movsd (%rax), %xmm0
movapd 0x61740(%rip), %xmm2    # 0x93030
xorpd %xmm0, %xmm2
movsd (%rsp), %xmm4
ucomisd %xmm2, %xmm4
jb 0x3190a
ucomisd (%rsp), %xmm0
jae 0x319f4
minsd %xmm1, %xmm3
movsd %xmm3, 0x8(%rsp)
ucomisd %xmm2, %xmm3
jb 0x31926
ucomisd 0x8(%rsp), %xmm0
jae 0x319f4
leaq 0x290(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x28264
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x28386
leaq 0x180(%rsp), %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x276a0
leaq 0xa96ab(%rip), %rsi     # 0xdb010
leaq 0x70(%rsp), %rdi
callq 0x21282
leaq 0x70(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x212e2
leaq 0x70(%rsp), %rdi
leaq 0x180(%rsp), %rsi
callq 0x2785a
movsd 0x8(%rsp), %xmm0
divsd (%rsp), %xmm0
leaq 0x70(%rsp), %rdi
callq 0x21314
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x212f8
leaq 0x28(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x38c72
leaq 0x70(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x212e2
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
callq 0x2f570
leaq 0x70(%rsp), %rdi
callq 0x276ee
leaq 0x180(%rsp), %rdi
callq 0x276ee
addq $0x2d8, %rsp            # imm = 0x2D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x31a1a
jmp 0x31a0d
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x276ee
leaq 0x180(%rsp), %rdi
callq 0x276ee
movq %rbx, %rdi
callq 0xe810
nop