// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Grid.cpp
// Function: gaps::R2Grid::Resample(int, int, int)
void R2Grid::
Resample(int xresolution, int yresolution, RNBoolean nearest_point_sampling)
{
  // Resample grid values at new resolution
  RNScalar *new_grid_values = NULL;
  int new_grid_size = xresolution * yresolution;
  if (new_grid_size > 0) {
    new_grid_values = new RNScalar [ new_grid_size ];
    assert(new_grid_values);
    if (grid_values && (grid_resolution[0] > 0) && (grid_resolution[1] > 0)) {
      RNScalar *new_grid_valuesp = new_grid_values;
      RNScalar xscale = (RNScalar) (grid_resolution[0]-1) / (RNScalar) (xresolution - 1);
      RNScalar yscale = (RNScalar) (grid_resolution[1]-1) / (RNScalar) (yresolution - 1);
      for (int j = 0; j < yresolution; j++) {
        RNScalar y = (j == yresolution-1) ? grid_resolution[1]-1 : j * yscale;
        for (int i = 0; i < xresolution; i++) {
          RNScalar x = (i == xresolution-1) ? grid_resolution[0]-1 : i * xscale;
          if (!nearest_point_sampling) {
            // Sample with bilinear interpolation
            *(new_grid_valuesp++) = GridValue(x, y);
          }
          else {
            // Sample at nearest point 
            int ix = (int) (x + 0.5);
            int iy = (int) (y + 0.5);
            if (ix > grid_resolution[0]-1) ix = grid_resolution[0]-1;
            if (iy > grid_resolution[1]-1) iy = grid_resolution[1]-1;
            *(new_grid_valuesp++) = GridValue(ix, iy);
          }
        }
      }
    }
    else {
      for (int i = 0; i < new_grid_size; i++) {
        new_grid_values[i] = 0;
      }
    }
  }

  // Reset grid variables
  grid_resolution[0] = xresolution;
  grid_resolution[1] = yresolution;
  grid_row_size = xresolution;
  grid_size = grid_row_size * yresolution;
  if (grid_values) delete [] grid_values;
  grid_values = new_grid_values;

  // Reset transformations
  SetWorldToGridTransformation(WorldBox());
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %edx, %r14d
movl %esi, %r12d
movq %rdi, %rbx
movl %edx, %r13d
imull %esi, %r13d
testl %r13d, %r13d
jle 0x5f7a5
movl %ecx, %ebp
movl %r13d, %edi
shlq $0x3, %rdi
callq 0xe030
movq %rax, (%rsp)
movq 0xb8(%rbx), %rax
movq %rax, 0x70(%rsp)
testq %rax, %rax
je 0x5f784
movl 0xc0(%rbx), %eax
movq %rax, 0x30(%rsp)
testl %eax, %eax
jle 0x5f784
movl 0xc4(%rbx), %eax
movq %rax, 0x28(%rsp)
testl %eax, %eax
jle 0x5f784
testl %r14d, %r14d
jle 0x5f77e
movl %r13d, 0x1c(%rsp)
movq %rbx, 0x8(%rsp)
movq 0x30(%rsp), %rax
leal -0x1(%rax), %r13d
cvtsi2sd %r13d, %xmm2
leal -0x1(%r12), %eax
cvtsi2sd %eax, %xmm0
movq 0x28(%rsp), %rax
decl %eax
movl %eax, 0x20(%rsp)
cvtsi2sd %eax, %xmm3
movapd %xmm2, %xmm4
leal -0x1(%r14), %eax
movl %eax, 0x24(%rsp)
cvtsi2sd %eax, %xmm1
divsd %xmm0, %xmm4
movsd %xmm4, 0x68(%rsp)
movsd %xmm3, 0x40(%rsp)
divsd %xmm1, %xmm3
movsd %xmm3, 0x38(%rsp)
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movsd 0x429d1(%rip), %xmm1    # 0xa2038
movq (%rsp), %rbx
movq %r12, 0x50(%rsp)
movq %r14, 0x48(%rsp)
movsd %xmm2, 0x60(%rsp)
movsd 0x40(%rsp), %xmm3
movsd %xmm3, 0x10(%rsp)
cmpl 0x24(%rsp), %r15d
je 0x5f69e
movsd 0x38(%rsp), %xmm3
mulsd %xmm0, %xmm3
movsd %xmm3, 0x10(%rsp)
movsd %xmm0, 0x58(%rsp)
testl %r12d, %r12d
jle 0x5f754
movsd 0x10(%rsp), %xmm0
addsd 0x42975(%rip), %xmm0    # 0xa2030
cvttsd2si %xmm0, %r14d
cmpl %r14d, 0x28(%rsp)
cmovlel 0x20(%rsp), %r14d
movq 0x8(%rsp), %rax
imull 0xc8(%rax), %r14d
xorpd %xmm3, %xmm3
movapd %xmm2, %xmm0
cmpl $0x1, %r12d
je 0x5f6f0
movsd 0x68(%rsp), %xmm0
mulsd %xmm3, %xmm0
testl %ebp, %ebp
je 0x5f719
addsd 0x42934(%rip), %xmm0    # 0xa2030
cvttsd2si %xmm0, %eax
cmpl %eax, 0x30(%rsp)
cmovlel %r13d, %eax
addl %r14d, %eax
cltq
movq 0x70(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
jmp 0x5f743
movq 0x8(%rsp), %rdi
movsd 0x10(%rsp), %xmm1
movsd %xmm3, 0x78(%rsp)
callq 0x5af72
movsd 0x78(%rsp), %xmm3
movsd 0x428fb(%rip), %xmm1    # 0xa2038
movsd 0x60(%rsp), %xmm2
movsd %xmm0, (%rbx)
addq $0x8, %rbx
addsd %xmm1, %xmm3
decl %r12d
jne 0x5f6dc
movsd 0x58(%rsp), %xmm0
addsd %xmm1, %xmm0
incl %r15d
movq 0x48(%rsp), %r14
cmpl %r14d, %r15d
movq 0x50(%rsp), %r12
jne 0x5f67b
movq 0x8(%rsp), %rbx
movl 0x1c(%rsp), %r13d
movq (%rsp), %r15
jmp 0x5f7a8
cmpl $0x2, %r13d
movl $0x1, %edx
cmovgel %r13d, %edx
shlq $0x3, %rdx
movq (%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0xe260
jmp 0x5f7a8
xorl %r15d, %r15d
movl %r12d, 0xc0(%rbx)
movl %r14d, 0xc4(%rbx)
movl %r12d, 0xc8(%rbx)
movl %r13d, 0xcc(%rbx)
movq 0xb8(%rbx), %rdi
testq %rdi, %rdi
je 0x5f7d5
callq 0xe5b0
movq %r15, 0xb8(%rbx)
leaq 0xd8(%rsp), %r14
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq %r14, %rdi
callq 0x68e2e
movl 0xc0(%rbx), %eax
decl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movl 0xc4(%rbx), %eax
decl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
callq 0x68e2e
movsd (%r14), %xmm0
movsd 0x8(%r14), %xmm1
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
callq 0x68e2e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x68f42
movsd (%r15), %xmm0
movsd 0x8(%r15), %xmm1
leaq 0xa8(%rsp), %r15
movq %r15, %rdi
callq 0x68e2e
movq %r15, %rdi
movq %rbx, %rsi
callq 0x68f42
leaq 0x80(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x6604a
movq %rbx, %rdi
movq %r12, %rsi
callq 0x59d9a
leaq 0x80(%rsp), %rdi
callq 0x6699c
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x6699c
movq %rbx, %rdi
callq 0xe7e0