// File: /workspace/github_cpp_makefile_star2_O3/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 0x65c28
leaq 0x58(%rbx), %r14
movq %r14, %rdi
callq 0x65c28
movsd 0x8(%r15), %xmm3
movsd 0x18(%r15), %xmm0
ucomisd %xmm0, %xmm3
movapd (%rsp), %xmm7
ja 0x596d8
movsd 0x10(%r15), %xmm2
movsd 0x20(%r15), %xmm1
ucomisd %xmm1, %xmm2
ja 0x596d8
leaq 0x8c4dc(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm4
movapd 0x48958(%rip), %xmm5    # 0xa2020
xorpd %xmm4, %xmm5
ucomisd %xmm5, %xmm7
jb 0x59702
ucomisd %xmm7, %xmm4
jb 0x59702
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x58ed8
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x5984a
leaq 0x10(%rsp), %rdi
callq 0x59b0c
jmp 0x59808
subsd %xmm3, %xmm0
testl %r12d, %r12d
jle 0x59754
movapd %xmm0, %xmm5
divsd %xmm7, %xmm5
xorps %xmm3, %xmm3
cvtsi2sd %r12d, %xmm3
movapd %xmm0, %xmm6
divsd %xmm3, %xmm6
movapd %xmm3, %xmm4
cmpltsd %xmm5, %xmm4
andpd %xmm4, %xmm6
andnpd %xmm7, %xmm4
orpd %xmm6, %xmm4
subsd %xmm2, %xmm1
movapd %xmm1, %xmm2
divsd %xmm4, %xmm2
ucomisd %xmm3, %xmm2
jbe 0x5975a
movapd %xmm1, %xmm7
divsd %xmm3, %xmm7
jmp 0x5975e
subsd %xmm2, %xmm1
jmp 0x5975e
movapd %xmm4, %xmm7
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
unpcklpd %xmm7, %xmm7            # xmm7 = xmm7[0,0]
divpd %xmm7, %xmm0
addpd 0x4889e(%rip), %xmm0    # 0xa2010
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0xc0(%rbx)
movd %xmm0, %eax
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %ecx
testl %ebp, %ebp
jle 0x597a7
cmpl %ebp, %eax
jge 0x5979b
movl %ebp, 0xc0(%rbx)
movl %ebp, %eax
cmpl %ebp, %ecx
jge 0x597a7
movl %ebp, 0xc4(%rbx)
jmp 0x597a9
movl %ecx, %ebp
movl %eax, 0xc8(%rbx)
imull %eax, %ebp
movl %ebp, 0xcc(%rbx)
testl %ebp, %ebp
je 0x597f2
movslq %ebp, %rax
shlq $0x3, %rax
testl %ebp, %ebp
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0xe030
movq %rax, 0xb8(%rbx)
testl %ebp, %ebp
jle 0x597fd
movl %ebp, %edx
shlq $0x3, %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0xe260
jmp 0x597fd
movq $0x0, 0xb8(%rbx)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x59092
addq $0xe0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x59829
movq %rax, %r15
leaq 0x10(%rsp), %rdi
callq 0x59b0c
jmp 0x5982c
movq %rax, %r15
movq %r14, %rdi
callq 0x65f5c
jmp 0x59839
movq %rax, %r15
movq %rbx, %rdi
callq 0x65f5c
movq %r15, %rdi
callq 0xe7e0
nop