// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Grid.cpp
// Function: gaps::R2Grid::R2Grid(gaps::R2Box const&, double, int, int)
R2Grid::
R2Grid(const R2Box& bbox, RNLength spacing, int min_resolution, int max_resolution)
{
  // Check for empty bounding box
  if (bbox.IsEmpty() || (RNIsZero(spacing))) { *this = R2Grid(); return; }
  
  // Enforce max resolution
  if (max_resolution > 0) {
    if (bbox.XLength() / spacing > max_resolution) spacing = bbox.XLength() / max_resolution;
    if (bbox.YLength() / spacing > max_resolution) spacing = bbox.YLength() / max_resolution;
  }

  // Compute resolution
  grid_resolution[0] = (int) (bbox.XLength() / spacing + 0.5);
  grid_resolution[1] = (int) (bbox.YLength() / spacing + 0.5);

  // Enforce min resolution
  if (min_resolution > 0) {
    if (grid_resolution[0] < min_resolution) grid_resolution[0] = min_resolution;
    if (grid_resolution[1] < min_resolution) grid_resolution[1] = min_resolution;
  }

  // Set grid resolution
  grid_row_size = grid_resolution[0];
  grid_size = grid_row_size * grid_resolution[1];

  // Allocate grid values
  if (grid_size == 0) grid_values = NULL;
  else grid_values = new RNScalar [ grid_size ];
  assert(!grid_size || grid_values);

  // Set all values to zero
  for (int i = 0; i < grid_size; i++) grid_values[i] = 0;

  // Set transformations
  SetWorldToGridTransformation(bbox);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xe0, %rsp
movl %ecx, %r12d
movl %edx, %ebp
movapd %xmm0, (%rsp)
movq %rsi, %r15
movq %rdi, %rbx
callq 0x669b0
leaq 0x58(%rbx), %r14
movq %r14, %rdi
callq 0x669b0
movupd 0x8(%r15), %xmm1
movupd 0x18(%r15), %xmm0
ucomisd %xmm0, %xmm1
movapd (%rsp), %xmm8
ja 0x5a3e5
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
movapd %xmm1, %xmm3
unpckhpd %xmm1, %xmm3            # xmm3 = xmm3[1],xmm1[1]
ucomisd %xmm2, %xmm3
ja 0x5a3e5
leaq 0x8b7d1(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm4
movapd 0x47c4d(%rip), %xmm5    # 0xa2020
xorpd %xmm4, %xmm5
ucomisd %xmm5, %xmm8
jb 0x5a40f
ucomisd %xmm8, %xmm4
jb 0x5a40f
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x59bf4
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x5a560
leaq 0x10(%rsp), %rdi
callq 0x5a814
jmp 0x5a51e
testl %r12d, %r12d
jle 0x5a469
movapd %xmm0, %xmm6
subsd %xmm1, %xmm6
movapd %xmm6, %xmm7
xorps %xmm4, %xmm4
cvtsi2sd %r12d, %xmm4
divsd %xmm8, %xmm7
divsd %xmm4, %xmm6
movapd %xmm4, %xmm5
cmpltsd %xmm7, %xmm5
andpd %xmm5, %xmm6
andnpd %xmm8, %xmm5
orpd %xmm6, %xmm5
subsd %xmm3, %xmm2
movapd %xmm2, %xmm3
divsd %xmm5, %xmm3
ucomisd %xmm4, %xmm3
jbe 0x5a464
divsd %xmm4, %xmm2
movapd %xmm2, %xmm8
jmp 0x5a469
movapd %xmm5, %xmm8
subpd %xmm1, %xmm0
unpcklpd %xmm8, %xmm8            # xmm8 = xmm8[0,0]
divpd %xmm8, %xmm0
addpd 0x47b91(%rip), %xmm0    # 0xa2010
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0xc0(%rbx)
testl %ebp, %ebp
jle 0x5a4b0
movd %xmm0, %eax
cmpl %ebp, %eax
jge 0x5a49d
movl %ebp, 0xc0(%rbx)
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %eax
cmpl %ebp, %eax
jge 0x5a4b0
movl %ebp, 0xc4(%rbx)
movslq 0xc0(%rbx), %rax
movl %eax, 0xc8(%rbx)
movslq 0xc4(%rbx), %r12
imulq %rax, %r12
movl %r12d, 0xcc(%rbx)
testl %r12d, %r12d
je 0x5a4f0
movq %r12, %rax
shlq $0x3, %rax
testl %r12d, %r12d
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0xe030
jmp 0x5a4f2
xorl %eax, %eax
movq %rax, 0xb8(%rbx)
testl %r12d, %r12d
jle 0x5a513
movq 0xb8(%rbx), %rdi
movl %r12d, %edx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0xe260
movq %rbx, %rdi
movq %r15, %rsi
callq 0x59d9a
addq $0xe0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5a53f
movq %rax, %r15
leaq 0x10(%rsp), %rdi
callq 0x5a814
jmp 0x5a542
movq %rax, %r15
movq %r14, %rdi
callq 0x66ce4
jmp 0x5a54f
movq %rax, %r15
movq %rbx, %rdi
callq 0x66ce4
movq %r15, %rdi
callq 0xe7e0
nop