// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3PlanarGrid.cpp
// Function: gaps::R3PlanarGrid::Reset(gaps::R3Plane const&, gaps::R3Point const&, gaps::R3Vector const&, double, double, double, double)
void R3PlanarGrid::
Reset(const R3Plane& plane, 
  const R3Point& origin, const R3Vector& up, 
  RNLength xradius, RNLength yradius, RNLength offplane_radius,
  RNLength spacing)
{
  // Set plane
  this->plane = plane;

  // Determine transformation from 3D to 2D
  R3Point centroid = origin;
  centroid.Project(plane);
  R3Vector zaxis = plane.Normal();
  R3Vector xaxis = up % zaxis;
  xaxis.Normalize();
  R3Vector yaxis = zaxis % xaxis;
  yaxis.Normalize();
  R3Triad triad(xaxis, yaxis, zaxis);
  R3CoordSystem cs(centroid, triad);
  transformation.Reset(cs.InverseMatrix());

  // Determine 3D bounding box
  R3Vector dx = xradius * cs.Axes()[RN_X];
  R3Vector dy = yradius * cs.Axes()[RN_Y];
  R3Vector dz = offplane_radius * cs.Axes()[RN_Z];
  this->bbox = R3null_box;
  bbox.Union(centroid - dx - dy - dz);
  bbox.Union(centroid - dx - dy + dz);
  bbox.Union(centroid - dx + dy - dz);
  bbox.Union(centroid - dx + dy + dz);
  bbox.Union(centroid + dx - dy - dz);
  bbox.Union(centroid + dx - dy + dz);
  bbox.Union(centroid + dx + dy - dz);
  bbox.Union(centroid + dx + dy + dz);

  // Determine 2D bounding box
  R2Box planar_bbox(-xradius, -yradius, xradius, yradius);

  // Determine grid resolution
  int xres = (int) (planar_bbox.XLength() / spacing + 0.5);
  int yres = (int) (planar_bbox.YLength() / spacing + 0.5);
  if (xres < 2) xres = 2;
  if (yres < 2) yres = 2;
  grid.Resample(xres, yres);

  // Determine transformation from 2D to grid
  grid.SetWorldToGridTransformation(planar_bbox);
}

// Assembly:
subq $0x5f8, %rsp            # imm = 0x5F8
movq %rdi, 0x5f0(%rsp)
movq %rsi, 0x5e8(%rsp)
movq %rdx, 0x5e0(%rsp)
movq %rcx, 0x5d8(%rsp)
movsd %xmm0, 0x5d0(%rsp)
movsd %xmm1, 0x5c8(%rsp)
movsd %xmm2, 0x5c0(%rsp)
movsd %xmm3, 0x5b8(%rsp)
movq 0x5f0(%rsp), %rdi
movq %rdi, 0x68(%rsp)
movq 0x5e8(%rsp), %rsi
callq 0x44240
movq 0x5e0(%rsp), %rsi
leaq 0x5a0(%rsp), %rdi
movq %rdi, 0x118(%rsp)
callq 0xf8390
movq 0x118(%rsp), %rdi
movq 0x5e8(%rsp), %rsi
callq 0xf8a20
movq 0x5e8(%rsp), %rdi
callq 0x44500
movq %rax, %rsi
leaq 0x588(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0xf94f0
movq 0x20(%rsp), %rdx
movq 0x5d8(%rsp), %rsi
leaq 0x570(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xfa2f0
movq 0x10(%rsp), %rdi
callq 0xf9c10
movq 0x10(%rsp), %rdx
movq 0x20(%rsp), %rsi
leaq 0x558(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0xfa2f0
movq 0x18(%rsp), %rdi
callq 0xf9c10
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
leaq 0x510(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0xd5c80
movq 0x28(%rsp), %rdx
movq 0x118(%rsp), %rsi
leaq 0x4b0(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0xd5570
movq 0x58(%rsp), %rsi
movq 0x68(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x30(%rsp)
leaq 0x430(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0xd5640
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
xorl %edx, %edx
movl %edx, 0x44(%rsp)
callq 0xd52b0
movq 0x58(%rsp), %rdi
movsd 0x5d0(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
callq 0x320f0
movl 0x44(%rsp), %esi
movq %rax, %rdi
callq 0x44220
movsd 0x48(%rsp), %xmm0
movq %rax, %rsi
leaq 0x418(%rsp), %rdi
movq %rdi, 0x120(%rsp)
callq 0x31980
movq 0x58(%rsp), %rdi
movsd 0x5c8(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
callq 0x320f0
movq %rax, %rdi
movl $0x1, %esi
callq 0x44220
movsd 0x50(%rsp), %xmm0
movq %rax, %rsi
leaq 0x400(%rsp), %rdi
movq %rdi, 0x130(%rsp)
callq 0x31980
movq 0x58(%rsp), %rdi
movsd 0x5c0(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
callq 0x320f0
movq %rax, %rdi
movl $0x2, %esi
callq 0x44220
movsd 0x60(%rsp), %xmm0
movq %rax, %rsi
leaq 0x3e8(%rsp), %rdi
movq %rdi, 0x140(%rsp)
callq 0x31980
movq 0x68(%rsp), %rdi
addq $0x200, %rdi            # imm = 0x200
movq %rdi, 0x148(%rsp)
leaq 0x11ffd0(%rip), %rsi    # 0x1fd308
callq 0x1bd40
movq 0x118(%rsp), %rsi
movq 0x120(%rsp), %rdx
leaq 0x3a0(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0xf92b0
movq 0x70(%rsp), %rsi
movq 0x130(%rsp), %rdx
leaq 0x3b8(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0xf92b0
movq 0x78(%rsp), %rsi
movq 0x140(%rsp), %rdx
leaq 0x3d0(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0xf92b0
movq 0x80(%rsp), %rsi
movq 0x148(%rsp), %rdi
callq 0xcb9d0
movq 0x118(%rsp), %rsi
movq 0x120(%rsp), %rdx
leaq 0x358(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0xf92b0
movq 0x88(%rsp), %rsi
movq 0x130(%rsp), %rdx
leaq 0x370(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0xf92b0
movq 0x90(%rsp), %rsi
movq 0x140(%rsp), %rdx
leaq 0x388(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0xf8910
movq 0x98(%rsp), %rsi
movq 0x148(%rsp), %rdi
callq 0xcb9d0
movq 0x118(%rsp), %rsi
movq 0x120(%rsp), %rdx
leaq 0x310(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0xf92b0
movq 0xa0(%rsp), %rsi
movq 0x130(%rsp), %rdx
leaq 0x328(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0xf8910
movq 0xa8(%rsp), %rsi
movq 0x140(%rsp), %rdx
leaq 0x340(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0xf92b0
movq 0xb0(%rsp), %rsi
movq 0x148(%rsp), %rdi
callq 0xcb9d0
movq 0x118(%rsp), %rsi
movq 0x120(%rsp), %rdx
leaq 0x2c8(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0xf92b0
movq 0xb8(%rsp), %rsi
movq 0x130(%rsp), %rdx
leaq 0x2e0(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
callq 0xf8910
movq 0xc0(%rsp), %rsi
movq 0x140(%rsp), %rdx
leaq 0x2f8(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0xf8910
movq 0xc8(%rsp), %rsi
movq 0x148(%rsp), %rdi
callq 0xcb9d0
movq 0x118(%rsp), %rsi
movq 0x120(%rsp), %rdx
leaq 0x280(%rsp), %rdi
movq %rdi, 0xd0(%rsp)
callq 0xf8910
movq 0xd0(%rsp), %rsi
movq 0x130(%rsp), %rdx
leaq 0x298(%rsp), %rdi
movq %rdi, 0xd8(%rsp)
callq 0xf92b0
movq 0xd8(%rsp), %rsi
movq 0x140(%rsp), %rdx
leaq 0x2b0(%rsp), %rdi
movq %rdi, 0xe0(%rsp)
callq 0xf92b0
movq 0xe0(%rsp), %rsi
movq 0x148(%rsp), %rdi
callq 0xcb9d0
movq 0x118(%rsp), %rsi
movq 0x120(%rsp), %rdx
leaq 0x238(%rsp), %rdi
movq %rdi, 0xe8(%rsp)
callq 0xf8910
movq 0xe8(%rsp), %rsi
movq 0x130(%rsp), %rdx
leaq 0x250(%rsp), %rdi
movq %rdi, 0xf0(%rsp)
callq 0xf92b0
movq 0xf0(%rsp), %rsi
movq 0x140(%rsp), %rdx
leaq 0x268(%rsp), %rdi
movq %rdi, 0xf8(%rsp)
callq 0xf8910
movq 0xf8(%rsp), %rsi
movq 0x148(%rsp), %rdi
callq 0xcb9d0
movq 0x118(%rsp), %rsi
movq 0x120(%rsp), %rdx
leaq 0x1f0(%rsp), %rdi
movq %rdi, 0x100(%rsp)
callq 0xf8910
movq 0x100(%rsp), %rsi
movq 0x130(%rsp), %rdx
leaq 0x208(%rsp), %rdi
movq %rdi, 0x108(%rsp)
callq 0xf8910
movq 0x108(%rsp), %rsi
movq 0x140(%rsp), %rdx
leaq 0x220(%rsp), %rdi
movq %rdi, 0x110(%rsp)
callq 0xf92b0
movq 0x110(%rsp), %rsi
movq 0x148(%rsp), %rdi
callq 0xcb9d0
movq 0x118(%rsp), %rsi
movq 0x120(%rsp), %rdx
leaq 0x1a8(%rsp), %rdi
movq %rdi, 0x128(%rsp)
callq 0xf8910
movq 0x128(%rsp), %rsi
movq 0x130(%rsp), %rdx
leaq 0x1c0(%rsp), %rdi
movq %rdi, 0x138(%rsp)
callq 0xf8910
movq 0x138(%rsp), %rsi
movq 0x140(%rsp), %rdx
leaq 0x1d8(%rsp), %rdi
movq %rdi, 0x150(%rsp)
callq 0xf8910
movq 0x148(%rsp), %rdi
movq 0x150(%rsp), %rsi
callq 0xcb9d0
movsd 0x5d0(%rsp), %xmm2
movaps %xmm2, %xmm0
movapd 0xc73bb(%rip), %xmm4    # 0x1a4b20
pxor %xmm4, %xmm0
movsd 0x5c8(%rsp), %xmm3
movaps %xmm3, %xmm1
pxor %xmm4, %xmm1
leaq 0x180(%rsp), %rdi
movq %rdi, 0x158(%rsp)
callq 0x12de70
movq 0x158(%rsp), %rdi
callq 0xdebb0
movsd %xmm0, 0x160(%rsp)
jmp 0xdd7a6
movsd 0x160(%rsp), %xmm0
movsd 0x5b8(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd 0xc6994(%rip), %xmm1    # 0x1a4158
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x17c(%rsp)
leaq 0x180(%rsp), %rdi
callq 0xdebd0
movsd %xmm0, 0x8(%rsp)
jmp 0xdd7e8
movsd 0x8(%rsp), %xmm0
divsd 0x5b8(%rsp), %xmm0
movsd 0xc6959(%rip), %xmm1    # 0x1a4158
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x168(%rsp)
cmpl $0x2, 0x17c(%rsp)
jge 0xdd848
movl $0x2, 0x17c(%rsp)
jmp 0xdd848
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
leaq 0x180(%rsp), %rdi
callq 0x54990
jmp 0xdd8b0
cmpl $0x2, 0x168(%rsp)
jge 0xdd85d
movl $0x2, 0x168(%rsp)
movq 0x68(%rsp), %rdi
addq $0x130, %rdi            # imm = 0x130
movl 0x17c(%rsp), %esi
movl 0x168(%rsp), %edx
xorl %ecx, %ecx
callq 0x11b220
jmp 0xdd880
movq 0x68(%rsp), %rdi
addq $0x130, %rdi            # imm = 0x130
leaq 0x180(%rsp), %rsi
callq 0x111610
jmp 0xdd89b
leaq 0x180(%rsp), %rdi
callq 0x54990
addq $0x5f8, %rsp            # imm = 0x5F8
retq
movq 0x170(%rsp), %rdi
callq 0x13970
nopl (%rax)