// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movsd %xmm3, 0x58(%rsp)
movsd %xmm2, 0x48(%rsp)
movaps %xmm1, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %rbx
callq 0x2865e
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x781cc
movq %r14, %rdi
movq %r13, %rsi
callq 0x784c6
leaq 0x1d8(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x7898c
leaq 0x1c0(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x7902e
movq %r13, %rdi
callq 0x78c7e
leaq 0x1a8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x7902e
movq %r12, %rdi
callq 0x78c7e
leaq 0x1f0(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x672fa
leaq 0x148(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x66f12
leaq 0x20(%rbx), %r12
movq %rbx, 0x50(%rsp)
leaq 0x98(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x66f9c
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x66e66
leaq 0x160(%rsp), %rsi
leaq 0x130(%rsp), %r12
movq %r12, %rdi
movaps 0x60(%rsp), %xmm0
callq 0x79072
leaq 0x178(%rsp), %rsi
leaq 0x118(%rsp), %r13
movq %r13, %rdi
movaps 0x70(%rsp), %xmm0
callq 0x79072
leaq 0x190(%rsp), %rsi
leaq 0x80(%rsp), %rdi
movsd 0x48(%rsp), %xmm0
callq 0x79072
leaq 0x200(%rbx), %rbp
leaq 0xbadb3(%rip), %rsi     # 0x1259e8
movq %rbp, %rdi
callq 0x177ee
movq %rsp, %r14
movq %r14, %rdi
leaq 0x30(%rsp), %r15
movq %r15, %rsi
movq %r12, %rdx
callq 0x7890d
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x7890d
leaq 0x98(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x80(%rsp), %rdx
callq 0x7890d
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6464c
movq %rsp, %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x7890d
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x7890d
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x80(%rsp), %rdx
callq 0x78483
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x6464c
movq %rsp, %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x7890d
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x78483
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x80(%rsp), %rdx
movq %rdx, %r15
callq 0x7890d
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x6464c
movq %rsp, %rbx
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movq %r12, %rdx
callq 0x7890d
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x78483
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x78483
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x6464c
movq %rsp, %rbx
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movq %r12, %rdx
callq 0x78483
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x7890d
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x7890d
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x6464c
movq %rsp, %rbx
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movq %r12, %rdx
callq 0x78483
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x7890d
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x78483
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x6464c
movq %rsp, %rbx
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movq %r12, %rdx
callq 0x78483
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x78483
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x7890d
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x6464c
movq %rsp, %rbx
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movq %r12, %rdx
callq 0x78483
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x78483
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x78483
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x6464c
movaps 0x5d513(%rip), %xmm1    # 0xc83a0
movaps 0x60(%rsp), %xmm2
movaps %xmm2, %xmm0
xorps %xmm1, %xmm0
movaps 0x70(%rsp), %xmm3
xorps %xmm3, %xmm1
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
callq 0x9101e
movsd 0x18(%rbx), %xmm0
subsd 0x8(%rbx), %xmm0
movsd 0x20(%rbx), %xmm1
subsd 0x10(%rbx), %xmm1
movq 0x50(%rsp), %rbx
movsd 0x58(%rsp), %xmm3
divsd %xmm3, %xmm0
movsd 0x5d25d(%rip), %xmm2    # 0xc8138
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %esi
divsd %xmm3, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
cmpl $0x3, %esi
pushq $0x2
popq %rdx
cmovll %edx, %esi
cmpl $0x3, %eax
cmovgel %eax, %edx
addq $0x130, %rbx            # imm = 0x130
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x88c46
leaq 0x98(%rsp), %rsi
movq %rbx, %rdi
callq 0x83cf8
leaq 0x98(%rsp), %rdi
callq 0x91792
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x91792
movq %rbx, %rdi
callq 0x138f0