// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Grid.cpp
// Function: gaps::R2Grid::SetWorldToGridTransformation(gaps::R2Point const&, gaps::R2Vector const&, double)
void R2Grid::
SetWorldToGridTransformation(const R2Point& world_origin, const R2Vector& world_xaxis, RNLength world_radius)
{
  // Just checking
  if (grid_size == 0) return;

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

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

  // Compute rotation
  RNAngle rotation = R2InteriorAngle(world_xaxis, R2posx_vector);
  if (world_xaxis.Y() < 0.0) rotation = RN_TWO_PI - rotation;

  // Compute world-to-grid transformation
  R2Affine affine(R2identity_affine);
  affine.Translate(grid_origin);
  affine.Rotate(-rotation);
  affine.Scale(scale);
  affine.Translate(-(world_origin.Vector()));

  // Set transformations
  SetWorldToGridTransformation(affine);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd0, %rsp
cmpl $0x0, 0xcc(%rdi)
je 0x60fb6
movaps %xmm0, %xmm2
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movl 0xc0(%rdi), %eax
decl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movl 0xc4(%rdi), %eax
decl %eax
cvtsi2sd %eax, %xmm1
leaq 0xc0(%rsp), %r12
movq %r12, %rdi
movsd %xmm2, (%rsp)
callq 0x6915a
leaq 0x58(%rsp), %r13
movsd 0x411d0(%rip), %xmm0    # 0xa2030
movq %r13, %rdi
movq %r12, %rsi
callq 0x694f6
movsd (%rsp), %xmm2
movsd 0x8(%r13), %xmm3
minsd (%r13), %xmm3
leaq 0x84d15(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm0
movapd 0x41191(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jb 0x60ea3
ucomisd %xmm2, %xmm0
jae 0x60fb6
ucomisd %xmm1, %xmm3
jb 0x60eb3
ucomisd %xmm3, %xmm0
jae 0x60fb6
movsd %xmm3, 0x8(%rsp)
leaq 0x48b78(%rip), %rsi     # 0xa9a38
movq %r15, %rdi
callq 0x6de94
movapd %xmm0, 0x10(%rsp)
movsd 0x8(%r15), %xmm0
movapd %xmm0, 0x20(%rsp)
leaq 0x8360f(%rip), %rax     # 0xe44f0
addq $0x10, %rax
leaq 0x70(%rsp), %r15
movq %rax, -0x8(%r15)
leaq 0x487063(%rip), %r12    # 0x4e7f58
leaq 0x8(%r12), %rsi
movq %r15, %rdi
callq 0x66efa
movl 0x50(%r12), %eax
movl %eax, 0xb8(%rsp)
leaq 0x58(%rsp), %rsi
movq %r15, %rdi
callq 0x67606
leaq 0x490a6(%rip), %rax     # 0xa9fc8
movsd (%rax), %xmm2
movapd 0x10(%rsp), %xmm3
subsd %xmm3, %xmm2
xorpd %xmm1, %xmm1
movapd 0x20(%rsp), %xmm0
cmpltsd %xmm1, %xmm0
andpd %xmm0, %xmm2
andnpd %xmm3, %xmm0
orpd %xmm2, %xmm0
xorpd 0x410cd(%rip), %xmm0    # 0xa2020
movq %r15, %rdi
callq 0x67724
movsd 0x8(%rsp), %xmm0
divsd (%rsp), %xmm0
movq %r15, %rdi
callq 0x676cc
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
leaq 0x38(%rsp), %rdi
callq 0x6915a
leaq 0x48(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x69669
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
callq 0x67606
leaq 0x68(%rsp), %rsi
movq %rbx, %rdi
callq 0x5a060
leaq 0x68(%rsp), %rdi
callq 0x66ce4
addq $0xd0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x60fcb
jmp 0x60fcb
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x66ce4
movq %rbx, %rdi
callq 0xe7e0