// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::R3Grid(gaps::R3Box const&, double, int, int, int)
R3Grid::
R3Grid(const R3Box& bbox, RNLength spacing, int min_resolution, int max_resolution, int min_border)
{
  // Check for empty bounding box
  if (bbox.IsEmpty() || (RNIsZero(spacing))) { *this = R3Grid(); return; }

  // Compute inflated bbox (with room for border)
  R3Box inflated_bbox = bbox;
  if (min_border > 0) {
    inflated_bbox[0] -= spacing * min_border * R3ones_vector;
    inflated_bbox[1] += spacing * min_border * R3ones_vector;
  }

  // Compute inflated box (if would otherwise have zero volume)
  for (int i = 0; i < 3; i++) {
    if (inflated_bbox[0][i] == inflated_bbox[1][i]) {
      inflated_bbox[0][i] -= RN_EPSILON;
      inflated_bbox[1][i] += RN_EPSILON;
    }
  }
  
  // Enforce max resolution
  if (max_resolution > 0) {
    if (inflated_bbox.XLength() / spacing > max_resolution) spacing = inflated_bbox.XLength() / max_resolution;
    if (inflated_bbox.YLength() / spacing > max_resolution) spacing = inflated_bbox.YLength() / max_resolution;
    if (inflated_bbox.ZLength() / spacing > max_resolution) spacing = inflated_bbox.ZLength() / max_resolution;
  }

  // Enforce min resolution
  if (min_resolution > 0) {
    if (inflated_bbox.XLength() / spacing < min_resolution) spacing = inflated_bbox.XLength() / min_resolution;
    if (inflated_bbox.YLength() / spacing < min_resolution) spacing = inflated_bbox.YLength() / min_resolution;
    if (inflated_bbox.ZLength() / spacing < min_resolution) spacing = inflated_bbox.ZLength() / min_resolution;
  }

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

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

  // 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(inflated_bbox);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movl %r8d, %r12d
movl %ecx, %r15d
movl %edx, %ebp
movapd %xmm0, (%rsp)
movq %rsi, %r13
movq %rdi, %rbx
callq 0x2a1e0
leaq 0x110(%rbx), %r14
movq %r14, %rdi
callq 0x2a1e0
movsd 0x8(%r13), %xmm0
ucomisd 0x20(%r13), %xmm0
ja 0x2ecb5
movsd 0x10(%r13), %xmm0
ucomisd 0x28(%r13), %xmm0
ja 0x2ecb5
movsd 0x18(%r13), %xmm0
ucomisd 0x30(%r13), %xmm0
ja 0x2ecb5
leaq 0xb6f05(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm0
movapd 0x73381(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
movapd (%rsp), %xmm2
ucomisd %xmm1, %xmm2
jb 0x2ecee
ucomisd (%rsp), %xmm0
jb 0x2ecee
leaq 0x38(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2e74c
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x2efe6
leaq 0x38(%rsp), %rdi
callq 0x2f17c
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x38(%rsp), %rdi
movq %r13, %rsi
callq 0x274f0
testl %r12d, %r12d
jle 0x2ed59
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
mulsd (%rsp), %xmm0
leaq 0x799e4(%rip), %rsi     # 0xa86f8
leaq 0x20(%rsp), %rdi
movsd %xmm0, 0x18(%rsp)
callq 0x3de8e
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3d394
leaq 0x799be(%rip), %rsi     # 0xa86f8
leaq 0x20(%rsp), %rdi
movsd 0x18(%rsp), %xmm0
callq 0x3de8e
leaq 0x58(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3ce0e
leaq 0xb6e38(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm0
movl $0x4, %eax
movsd 0x20(%rsp,%rax,8), %xmm2
movsd 0x38(%rsp,%rax,8), %xmm1
ucomisd %xmm1, %xmm2
jne 0x2ed91
jp 0x2ed91
subsd %xmm0, %xmm2
movsd %xmm2, 0x20(%rsp,%rax,8)
addsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp,%rax,8)
incq %rax
cmpq $0x7, %rax
jne 0x2ed69
testl %r15d, %r15d
jle 0x2ee36
movsd 0x58(%rsp), %xmm1
movsd 0x60(%rsp), %xmm2
subsd 0x40(%rsp), %xmm1
movapd %xmm1, %xmm3
movapd (%rsp), %xmm5
divsd %xmm5, %xmm3
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
divsd %xmm0, %xmm1
movapd %xmm0, %xmm4
cmpltsd %xmm3, %xmm4
andpd %xmm4, %xmm1
andnpd %xmm5, %xmm4
orpd %xmm1, %xmm4
subsd 0x48(%rsp), %xmm2
movapd %xmm2, %xmm1
divsd %xmm4, %xmm1
divsd %xmm0, %xmm2
movapd %xmm0, %xmm3
cmpltsd %xmm1, %xmm3
movapd %xmm3, %xmm1
andnpd %xmm4, %xmm1
andpd %xmm2, %xmm3
orpd %xmm1, %xmm3
movsd 0x68(%rsp), %xmm1
subsd 0x50(%rsp), %xmm1
movapd %xmm1, %xmm2
movapd %xmm3, (%rsp)
divsd %xmm3, %xmm2
ucomisd %xmm0, %xmm2
jbe 0x2ee36
divsd %xmm0, %xmm1
movapd %xmm1, (%rsp)
testl %ebp, %ebp
jle 0x2eec8
movsd 0x58(%rsp), %xmm1
movsd 0x60(%rsp), %xmm2
subsd 0x40(%rsp), %xmm1
movapd %xmm1, %xmm3
movapd (%rsp), %xmm4
divsd %xmm4, %xmm3
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd %xmm0, %xmm1
cmpltsd %xmm0, %xmm3
andpd %xmm3, %xmm1
andnpd %xmm4, %xmm3
subsd 0x48(%rsp), %xmm2
orpd %xmm1, %xmm3
movapd %xmm2, %xmm4
divsd %xmm3, %xmm4
divsd %xmm0, %xmm2
cmpltsd %xmm0, %xmm4
movapd %xmm4, %xmm1
andnpd %xmm3, %xmm1
andpd %xmm2, %xmm4
orpd %xmm1, %xmm4
movsd 0x68(%rsp), %xmm1
subsd 0x50(%rsp), %xmm1
movapd %xmm1, %xmm2
movapd %xmm4, (%rsp)
divsd %xmm4, %xmm2
ucomisd %xmm2, %xmm0
jbe 0x2eec8
divsd %xmm0, %xmm1
movapd %xmm1, (%rsp)
movupd 0x40(%rsp), %xmm0
movupd 0x58(%rsp), %xmm1
subpd %xmm0, %xmm1
movapd (%rsp), %xmm2
movapd %xmm2, %xmm0
unpcklpd %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0]
divpd %xmm0, %xmm1
addpd 0x7311f(%rip), %xmm1    # 0xa2010
cvttpd2dq %xmm1, %xmm0
movlpd %xmm0, 0x238(%rbx)
movsd 0x68(%rsp), %xmm1
subsd 0x50(%rsp), %xmm1
divsd %xmm2, %xmm1
addsd 0x7311b(%rip), %xmm1    # 0xa2030
cvttsd2si %xmm1, %eax
movl %eax, 0x240(%rbx)
movd %xmm0, %ecx
movd %xmm0, 0x244(%rbx)
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %ebp
imull %ecx, %ebp
movl %ebp, 0x248(%rbx)
imull %eax, %ebp
movl %ebp, 0x24c(%rbx)
testl %ebp, %ebp
je 0x2ef65
movslq %ebp, %rax
shlq $0x3, %rax
testl %ebp, %ebp
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0xe030
jmp 0x2ef67
xorl %eax, %eax
movq %rax, 0x230(%rbx)
testl %ebp, %ebp
jle 0x2ef86
movq 0x230(%rbx), %rdi
movl %ebp, %edx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0xe260
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x2e962
leaq 0x38(%rsp), %rdi
callq 0x28348
jmp 0x2ecdc
jmp 0x2efc6
jmp 0x2efa8
jmp 0x2efa8
movq %rax, %r15
leaq 0x38(%rsp), %rdi
callq 0x28348
jmp 0x2efc9
movq %rax, %r15
leaq 0x38(%rsp), %rdi
callq 0x2f17c
jmp 0x2efc9
movq %rax, %r15
movq %r14, %rdi
callq 0x2a27c
jmp 0x2efd6
movq %rax, %r15
movq %rbx, %rdi
callq 0x2a27c
movq %r15, %rdi
callq 0xe7e0