// File: tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Grid.cpp
// Function: gaps::R2Grid::PointSymmetryTransform(int)
void R2Grid::
PointSymmetryTransform(int radius)
{
  // Make copy of grid
  R2Grid copy(*this);
  copy.Normalize();

  // Brute force for now
  for (int j = 0; j < grid_resolution[1]; j++) {
    int y_radius = (j < grid_resolution[1]/2) ? j : grid_resolution[1]-1 - j;
    if ((radius > 0) && (y_radius > radius)) y_radius = radius;
    for (int i = 0; i < grid_resolution[0]; i++) {
      int x_radius = (i < grid_resolution[0]/2) ? i : grid_resolution[0]-1 - i;
      if ((radius > 0) && (x_radius > radius)) x_radius = radius;
      RNScalar dot = 0;
      RNScalar norm = 0;
      for (int t = -y_radius; t <= y_radius; t++) {
        for (int s = -x_radius; s <= x_radius; s++) {
          RNScalar value1 = GridValue(i-s, j-t);
          RNScalar value2 = GridValue(i+s, j+t);
          dot += 2 * value1 * value2;
          norm += value1 * value1; 
          norm += value2 * value2; 
        }
      }
      if (norm > 0) dot /= norm;
      SetGridValue(i, j, dot);
    }
  }
}

// Assembly:
subq $0x158, %rsp            # imm = 0x158
movq %rdi, 0x150(%rsp)
movl %esi, 0x14c(%rsp)
movq 0x150(%rsp), %rsi
movq %rsi, 0x20(%rsp)
leaq 0x78(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0xa73a0
movq 0x28(%rsp), %rdi
callq 0xa8bd0
jmp 0xafa5e
movl $0x0, 0x68(%rsp)
movq 0x20(%rsp), %rcx
movl 0x68(%rsp), %eax
cmpl 0xc4(%rcx), %eax
jge 0xafd26
movq 0x20(%rsp), %rax
movl 0x68(%rsp), %ecx
movl %ecx, 0x1c(%rsp)
movl 0xc4(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
jge 0xafaaa
movl 0x68(%rsp), %eax
movl %eax, 0x18(%rsp)
jmp 0xafac0
movq 0x20(%rsp), %rax
movl 0xc4(%rax), %eax
subl $0x1, %eax
subl 0x68(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x64(%rsp)
cmpl $0x0, 0x14c(%rsp)
jle 0xafb09
movl 0x64(%rsp), %eax
cmpl 0x14c(%rsp), %eax
jle 0xafb09
movl 0x14c(%rsp), %eax
movl %eax, 0x64(%rsp)
jmp 0xafb09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
leaq 0x78(%rsp), %rdi
callq 0xa7690
jmp 0xafd38
movl $0x0, 0x60(%rsp)
movq 0x20(%rsp), %rcx
movl 0x60(%rsp), %eax
cmpl 0xc0(%rcx), %eax
jge 0xafd14
movq 0x20(%rsp), %rax
movl 0x60(%rsp), %ecx
movl %ecx, 0x14(%rsp)
movl 0xc0(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
jge 0xafb55
movl 0x60(%rsp), %eax
movl %eax, 0x10(%rsp)
jmp 0xafb6b
movq 0x20(%rsp), %rax
movl 0xc0(%rax), %eax
subl $0x1, %eax
subl 0x60(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x5c(%rsp)
cmpl $0x0, 0x14c(%rsp)
jle 0xafb95
movl 0x5c(%rsp), %eax
cmpl 0x14c(%rsp), %eax
jle 0xafb95
movl 0x14c(%rsp), %eax
movl %eax, 0x5c(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x50(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rsp)
xorl %eax, %eax
subl 0x64(%rsp), %eax
movl %eax, 0x44(%rsp)
movl 0x44(%rsp), %eax
cmpl 0x64(%rsp), %eax
jg 0xafcc3
xorl %eax, %eax
subl 0x5c(%rsp), %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jg 0xafcb1
movq 0x20(%rsp), %rdi
movl 0x60(%rsp), %esi
movl 0x40(%rsp), %eax
subl %eax, %esi
movl 0x68(%rsp), %edx
movl 0x44(%rsp), %eax
subl %eax, %edx
callq 0xb92a0
movsd %xmm0, 0x8(%rsp)
jmp 0xafbfd
movq 0x20(%rsp), %rdi
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movl 0x60(%rsp), %esi
movl 0x40(%rsp), %eax
addl %eax, %esi
movl 0x68(%rsp), %edx
movl 0x44(%rsp), %eax
addl %eax, %edx
callq 0xb92a0
movsd %xmm0, (%rsp)
jmp 0xafc2e
movsd (%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x835bf(%rip), %xmm0    # 0x133200
mulsd 0x38(%rsp), %xmm0
movsd 0x30(%rsp), %xmm2
movsd 0x50(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x38(%rsp), %xmm0
movsd 0x38(%rsp), %xmm2
movsd 0x48(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x30(%rsp), %xmm0
movsd 0x30(%rsp), %xmm2
movsd 0x48(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rsp)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0xafbc9
jmp 0xafcb3
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xafbb1
movsd 0x48(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xafce8
movsd 0x48(%rsp), %xmm1
movsd 0x50(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x20(%rsp), %rdi
movl 0x60(%rsp), %esi
movl 0x68(%rsp), %edx
movsd 0x50(%rsp), %xmm0
callq 0x6bc00
jmp 0xafd02
jmp 0xafd04
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0xafb11
jmp 0xafd16
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
jmp 0xafa66
leaq 0x78(%rsp), %rdi
callq 0xa7690
addq $0x158, %rsp            # imm = 0x158
retq
movq 0x70(%rsp), %rdi
callq 0xf890
nopw %cs:(%rax,%rax)