// File: /workspace/github_cpp_makefile_star2_O3/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 0x601c6
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 0x683d2
leaq 0x58(%rsp), %r13
movsd 0x41fc0(%rip), %xmm0    # 0xa2030
movq %r13, %rdi
movq %r12, %rsi
callq 0x6870c
movsd (%rsp), %xmm2
movsd 0x8(%r13), %xmm3
minsd (%r13), %xmm3
leaq 0x85b05(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm0
movapd 0x41f81(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
jb 0x600b3
ucomisd %xmm2, %xmm0
jae 0x601c6
ucomisd %xmm1, %xmm3
jb 0x600c3
ucomisd %xmm3, %xmm0
jae 0x601c6
movsd %xmm3, 0x8(%rsp)
leaq 0x49980(%rip), %rsi     # 0xa9a50
movq %r15, %rdi
callq 0x6d0b8
movapd %xmm0, 0x10(%rsp)
movsd 0x8(%r15), %xmm0
movapd %xmm0, 0x20(%rsp)
leaq 0x843ff(%rip), %rax     # 0xe44f0
addq $0x10, %rax
leaq 0x70(%rsp), %r15
movq %rax, -0x8(%r15)
leaq 0x487e53(%rip), %r12    # 0x4e7f58
leaq 0x8(%r12), %rsi
movq %r15, %rdi
callq 0x66172
movl 0x50(%r12), %eax
movl %eax, 0xb8(%rsp)
leaq 0x58(%rsp), %rsi
movq %r15, %rdi
callq 0x6687e
leaq 0x49eb6(%rip), %rax     # 0xa9fe8
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 0x41ebd(%rip), %xmm0    # 0xa2020
movq %r15, %rdi
callq 0x6699c
movsd 0x8(%rsp), %xmm0
divsd (%rsp), %xmm0
movq %r15, %rdi
callq 0x66944
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
leaq 0x38(%rsp), %rdi
callq 0x683d2
leaq 0x48(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x6887f
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
callq 0x6687e
leaq 0x68(%rsp), %rsi
movq %rbx, %rdi
callq 0x59362
leaq 0x68(%rsp), %rdi
callq 0x65f5c
addq $0xd0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x601db
jmp 0x601db
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x65f5c
movq %rbx, %rdi
callq 0xe7e0