// File: /workspace/github_cpp_makefile_star2_O2/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 0x27652
leaq 0x110(%rbx), %rdi
movq %rdi, 0x18(%rsp)
callq 0x27652
movq %r13, %rdi
callq 0x257ce
testl %eax, %eax
jne 0x2b782
leaq 0xaf449(%rip), %r14     # 0xdaba8
movsd (%r14), %xmm0
movapd 0x678c4(%rip), %xmm1    # 0x93030
xorpd %xmm0, %xmm1
movapd (%rsp), %xmm2
ucomisd %xmm1, %xmm2
jb 0x2b7bb
ucomisd (%rsp), %xmm0
jb 0x2b7bb
leaq 0x38(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2b2ec
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x2baba
leaq 0x38(%rsp), %rdi
callq 0x2bc02
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 0x24b3e
testl %r12d, %r12d
jle 0x2b823
cvtsi2sd %r12d, %xmm0
mulsd (%rsp), %xmm0
leaq 0x6deca(%rip), %rsi     # 0x996a8
leaq 0x20(%rsp), %rdi
movsd %xmm0, 0x10(%rsp)
callq 0x38a02
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x381e4
leaq 0x6dea4(%rip), %rsi     # 0x996a8
leaq 0x20(%rsp), %rdi
movsd 0x10(%rsp), %xmm0
callq 0x38a02
leaq 0x58(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x37e9c
movsd (%r14), %xmm0
pushq $0x4
popq %rax
cmpq $0x7, %rax
je 0x2b85e
movsd 0x20(%rsp,%rax,8), %xmm2
movsd 0x38(%rsp,%rax,8), %xmm1
ucomisd %xmm1, %xmm2
jne 0x2b859
jp 0x2b859
subsd %xmm0, %xmm2
movsd %xmm2, 0x20(%rsp,%rax,8)
addsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp,%rax,8)
incq %rax
jmp 0x2b82b
movsd 0x40(%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
testl %r15d, %r15d
jle 0x2b8ff
movapd %xmm0, %xmm3
subsd %xmm1, %xmm3
movapd %xmm3, %xmm4
movapd (%rsp), %xmm6
divsd %xmm6, %xmm4
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 0x2b8ff
divsd %xmm2, %xmm3
movapd %xmm3, (%rsp)
testl %ebp, %ebp
jle 0x2b998
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 0x2b9b4
movapd %xmm3, %xmm1
divsd %xmm2, %xmm1
movapd %xmm1, (%rsp)
jmp 0x2b9b4
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 0x67673(%rip), %xmm0    # 0x93040
cvttpd2dq %xmm0, %xmm0
addsd 0x67637(%rip), %xmm3    # 0x93010
cvttsd2si %xmm3, %eax
movlpd %xmm0, 0x238(%rbx)
movl %eax, 0x240(%rbx)
movd %xmm0, %ecx
movd %xmm0, 0x244(%rbx)
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %r14d
imull %ecx, %r14d
movl %r14d, 0x248(%rbx)
imull %eax, %r14d
movl %r14d, 0x24c(%rbx)
xorl %r15d, %r15d
testl %r14d, %r14d
je 0x2ba37
movslq %r14d, %rax
shlq $0x3, %rax
testl %r14d, %r14d
pushq $-0x1
popq %rdi
cmovnsq %rax, %rdi
callq 0xe030
jmp 0x2ba39
xorl %eax, %eax
movq %rax, 0x230(%rbx)
testl %r14d, %r14d
cmovlel %r15d, %r14d
cmpq %r15, %r14
je 0x2ba56
andq $0x0, (%rax,%r15,8)
incq %r15
jmp 0x2ba47
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x2b4b0
leaq 0x38(%rsp), %rdi
callq 0x25832
jmp 0x2b7a9
jmp 0x2ba98
jmp 0x2ba78
jmp 0x2ba78
movq %rax, %r15
leaq 0x38(%rsp), %rdi
callq 0x25832
jmp 0x2ba9b
movq %rax, %r15
leaq 0x38(%rsp), %rdi
callq 0x2bc02
jmp 0x2ba9b
jmp 0x2ba98
movq %rax, %r15
movq 0x18(%rsp), %rdi
callq 0x276ee
jmp 0x2baaa
movq %rax, %r15
movq %rbx, %rdi
callq 0x276ee
movq %r15, %rdi
callq 0xe810