// File: /workspace/github_cpp_makefile_star2_O3/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 0x29f8c
leaq 0x110(%rbx), %r14
movq %r14, %rdi
callq 0x29f8c
movsd 0x8(%r13), %xmm0
ucomisd 0x20(%r13), %xmm0
ja 0x2e9cd
movsd 0x10(%r13), %xmm0
ucomisd 0x28(%r13), %xmm0
ja 0x2e9cd
movsd 0x18(%r13), %xmm0
ucomisd 0x30(%r13), %xmm0
ja 0x2e9cd
leaq 0xb71ed(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm0
movapd 0x73669(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
movapd (%rsp), %xmm2
ucomisd %xmm1, %xmm2
jb 0x2ea06
ucomisd (%rsp), %xmm0
jb 0x2ea06
leaq 0x38(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2e450
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x2ed12
leaq 0x38(%rsp), %rdi
callq 0x2ee9e
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 0x272d4
testl %r12d, %r12d
jle 0x2ea71
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
mulsd (%rsp), %xmm0
leaq 0x79ccc(%rip), %rsi     # 0xa86f8
leaq 0x20(%rsp), %rdi
movsd %xmm0, 0x18(%rsp)
callq 0x3d962
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3ce9a
leaq 0x79ca6(%rip), %rsi     # 0xa86f8
leaq 0x20(%rsp), %rdi
movsd 0x18(%rsp), %xmm0
callq 0x3d962
leaq 0x58(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3c914
leaq 0xb7120(%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 0x2eaa9
jp 0x2eaa9
subsd %xmm0, %xmm2
movsd %xmm2, 0x20(%rsp,%rax,8)
addsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp,%rax,8)
incq %rax
cmpq $0x7, %rax
jne 0x2ea81
movsd 0x40(%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
testl %r15d, %r15d
jle 0x2eb56
movapd %xmm0, %xmm3
subsd %xmm1, %xmm3
movapd %xmm3, %xmm4
movapd (%rsp), %xmm6
divsd %xmm6, %xmm4
xorps %xmm2, %xmm2
cvtsi2sd %r15d, %xmm2
divsd %xmm2, %xmm3
movapd %xmm2, %xmm5
cmpltsd %xmm4, %xmm5
andpd %xmm5, %xmm3
andnpd %xmm6, %xmm5
orpd %xmm3, %xmm5
movsd 0x60(%rsp), %xmm4
subsd 0x48(%rsp), %xmm4
movsd 0x68(%rsp), %xmm3
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
divsd %xmm2, %xmm4
movapd %xmm2, %xmm7
cmpltsd %xmm6, %xmm7
movapd %xmm7, %xmm6
andnpd %xmm5, %xmm6
andpd %xmm4, %xmm7
orpd %xmm6, %xmm7
subsd 0x50(%rsp), %xmm3
movapd %xmm3, %xmm4
movapd %xmm7, (%rsp)
divsd %xmm7, %xmm4
ucomisd %xmm2, %xmm4
jbe 0x2eb56
divsd %xmm2, %xmm3
movapd %xmm3, (%rsp)
testl %ebp, %ebp
jle 0x2ebf2
xorps %xmm2, %xmm2
cvtsi2sd %ebp, %xmm2
movhpd 0x60(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
movhpd 0x48(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
subpd %xmm1, %xmm0
movapd %xmm0, %xmm1
movapd (%rsp), %xmm4
divsd %xmm4, %xmm1
movapd %xmm0, %xmm3
divsd %xmm2, %xmm3
cmpltsd %xmm2, %xmm1
andpd %xmm1, %xmm3
andnpd %xmm4, %xmm1
orpd %xmm3, %xmm1
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
movapd %xmm3, %xmm5
divsd %xmm1, %xmm5
divsd %xmm2, %xmm3
cmpltsd %xmm2, %xmm5
movapd %xmm5, %xmm4
andnpd %xmm1, %xmm4
andpd %xmm3, %xmm5
orpd %xmm4, %xmm5
movsd 0x68(%rsp), %xmm3
subsd 0x50(%rsp), %xmm3
movapd %xmm3, %xmm1
movapd %xmm5, (%rsp)
divsd %xmm5, %xmm1
ucomisd %xmm1, %xmm2
jbe 0x2ec0e
movapd %xmm3, %xmm1
divsd %xmm2, %xmm1
movapd %xmm1, (%rsp)
jmp 0x2ec0e
movhpd 0x60(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
movhpd 0x48(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
movsd 0x68(%rsp), %xmm3
subpd %xmm1, %xmm0
subsd 0x50(%rsp), %xmm3
movapd (%rsp), %xmm1
divsd %xmm1, %xmm3
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
divpd %xmm1, %xmm0
addpd 0x733e9(%rip), %xmm0    # 0xa2010
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0x238(%rbx)
addsd 0x733f5(%rip), %xmm3    # 0xa2030
cvttsd2si %xmm3, %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 0x2eca6
movslq %ebp, %rax
shlq $0x3, %rax
testl %ebp, %ebp
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0xe030
movq %rax, 0x230(%rbx)
testl %ebp, %ebp
jle 0x2ecb1
movl %ebp, %edx
shlq $0x3, %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0xe260
jmp 0x2ecb1
movq $0x0, 0x230(%rbx)
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x2e67a
leaq 0x38(%rsp), %rdi
callq 0x280f4
jmp 0x2e9f4
jmp 0x2ecf1
jmp 0x2ecd3
jmp 0x2ecd3
movq %rax, %r15
leaq 0x38(%rsp), %rdi
callq 0x280f4
jmp 0x2ecf4
movq %rax, %r15
leaq 0x38(%rsp), %rdi
callq 0x2ee9e
jmp 0x2ecf4
movq %rax, %r15
movq %r14, %rdi
callq 0x2a028
jmp 0x2ed01
movq %rax, %r15
movq %rbx, %rdi
callq 0x2a028
movq %r15, %rdi
callq 0xe7e0
nop