// File: /workspace/github_cpp_makefile_star2_O2/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 $0xa8, %rsp
movl %edx, %r15d
movl %esi, %r14d
movl %edx, %r12d
imull %esi, %r12d
testl %r12d, %r12d
movq %rdi, (%rsp)
jle 0x5693c
movl %ecx, %ebp
movl %r12d, %ebx
leaq (,%rbx,8), %rdi
callq 0xe030
movq (%rsp), %rdi
movq %rax, %r13
movq 0xb8(%rdi), %rcx
testq %rcx, %rcx
je 0x5692a
movl 0xc0(%rdi), %eax
movq %rax, 0x28(%rsp)
testl %eax, %eax
jle 0x5692a
movl 0xc4(%rdi), %edx
testl %edx, %edx
jle 0x5692a
movl %r12d, 0x8(%rsp)
movq 0x28(%rsp), %rax
decl %eax
movl %eax, 0x20(%rsp)
cvtsi2sd %eax, %xmm2
leal -0x1(%r14), %esi
cvtsi2sd %esi, %xmm0
leal -0x1(%rdx), %eax
movl %eax, 0x10(%rsp)
cvtsi2sd %eax, %xmm3
movapd %xmm2, %xmm4
leal -0x1(%r15), %eax
movl %eax, 0xc(%rsp)
cvtsi2sd %eax, %xmm1
divsd %xmm0, %xmm4
movsd %xmm4, 0x70(%rsp)
movsd %xmm3, 0x50(%rsp)
divsd %xmm1, %xmm3
movsd %xmm3, 0x48(%rsp)
testl %r14d, %r14d
movl $0x0, %r8d
movq %r14, 0x40(%rsp)
cmovgl %r14d, %r8d
testl %r15d, %r15d
movl $0x0, %eax
movq %r15, 0x38(%rsp)
cmovgl %r15d, %eax
movl %eax, 0x14(%rsp)
xorl %eax, %eax
xorpd %xmm0, %xmm0
movsd 0x3c803(%rip), %xmm1    # 0x93008
movq %r13, 0x30(%rsp)
movq %r13, %r12
movsd %xmm2, 0x60(%rsp)
movl %ebp, 0x1c(%rsp)
cmpl 0x14(%rsp), %eax
je 0x56948
movsd 0x50(%rsp), %xmm3
movl %eax, 0x18(%rsp)
cmpl 0xc(%rsp), %eax
je 0x5683b
movsd 0x48(%rsp), %xmm3
mulsd %xmm0, %xmm3
movsd %xmm0, 0x58(%rsp)
movapd %xmm3, %xmm0
addsd 0x3c7c3(%rip), %xmm0    # 0x93010
cvttsd2si %xmm0, %eax
cmpl %eax, %edx
cmovlel 0x10(%rsp), %eax
imull 0xc8(%rdi), %eax
movl %eax, 0x24(%rsp)
xorl %r15d, %r15d
xorpd %xmm4, %xmm4
movsd %xmm3, 0x68(%rsp)
cmpl %r15d, %r8d
je 0x56915
movapd %xmm2, %xmm0
cmpl %r15d, %esi
je 0x5688c
movsd 0x70(%rsp), %xmm0
mulsd %xmm4, %xmm0
testl %ebp, %ebp
je 0x568b2
addsd 0x3c778(%rip), %xmm0    # 0x93010
cvttsd2si %xmm0, %eax
cmpl %eax, 0x28(%rsp)
cmovlel 0x20(%rsp), %eax
addl 0x24(%rsp), %eax
cltq
movsd (%rcx,%rax,8), %xmm0
jmp 0x568ff
movq (%rsp), %rdi
movapd %xmm3, %xmm1
movq %rcx, %rbp
movq %rdx, %rbx
movl %esi, %r14d
movl %r8d, %r13d
movsd %xmm4, 0x78(%rsp)
callq 0x52890
movsd 0x78(%rsp), %xmm4
movsd 0x68(%rsp), %xmm3
movsd 0x3c723(%rip), %xmm1    # 0x93008
movl %r13d, %r8d
movl %r14d, %esi
movsd 0x60(%rsp), %xmm2
movq %rbx, %rdx
movq %rbp, %rcx
movl 0x1c(%rsp), %ebp
movq (%rsp), %rdi
movsd %xmm0, (%r12)
addq $0x8, %r12
addsd %xmm1, %xmm4
incl %r15d
jmp 0x56870
movsd 0x58(%rsp), %xmm0
addsd %xmm1, %xmm0
movl 0x18(%rsp), %eax
incl %eax
jmp 0x56817
xorl %eax, %eax
cmpq %rax, %rbx
je 0x5695c
andq $0x0, (%r13,%rax,8)
incq %rax
jmp 0x5692c
movq 0xb8(%rdi), %rcx
xorl %r13d, %r13d
jmp 0x5695c
movq 0x40(%rsp), %r14
movq 0x38(%rsp), %r15
movl 0x8(%rsp), %r12d
movq 0x30(%rsp), %r13
movl %r14d, 0xc0(%rdi)
movl %r15d, 0xc4(%rdi)
movl %r14d, 0xc8(%rdi)
movl %r12d, 0xcc(%rdi)
testq %rcx, %rcx
je 0x56989
movq %rcx, %rdi
callq 0xe5d0
movq (%rsp), %rdi
movq %r13, 0xb8(%rdi)
leaq 0x80(%rsp), %r14
movq %rdi, %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5ac98
movq %rbx, %rdi
movq %r14, %rsi
callq 0x517bc
leaq 0x80(%rsp), %rdi
callq 0x5d2ee
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x5d2ee
movq %rbx, %rdi
callq 0xe810