// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rdi, 0x50(%rsp)
callq 0x85fc2
movsd 0x18(%r13), %xmm0
movsd %xmm0, 0x18(%rbx)
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x84d8e
movq %r14, %rdi
movq %r13, %rsi
callq 0x8510c
leaq 0x1d8(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x85826
leaq 0x1c0(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x8616a
movq %r13, %rdi
callq 0x85b38
leaq 0x1a8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x8616a
movq %r12, %rdi
callq 0x85b38
leaq 0x1f0(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x71878
leaq 0x148(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x71408
leaq 0x20(%rbx), %r12
leaq 0xb0(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x714b6
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x7136a
leaq 0x160(%rsp), %rsi
leaq 0x80(%rsp), %r15
movq %r15, %rdi
movaps 0x60(%rsp), %xmm0
callq 0x861e6
leaq 0x178(%rsp), %rsi
leaq 0x130(%rsp), %r13
movq %r13, %rdi
movaps 0x70(%rsp), %xmm0
callq 0x861e6
leaq 0x190(%rsp), %rsi
leaq 0x98(%rsp), %rdi
movsd 0x48(%rsp), %xmm0
callq 0x861e6
leaq 0x200(%rbx), %rbp
leaq 0x208(%rbx), %rdi
leaq 0xbff05(%rip), %r14     # 0x1359c8
leaq 0x8(%r14), %rsi
callq 0x850ec
leaq 0x220(%rbx), %rdi
addq $0x20, %r14
movq %r14, %rsi
callq 0x850ec
movq %rsp, %r14
movq %r14, %rdi
leaq 0x30(%rsp), %r12
movq %r12, %rsi
movq %r15, %rdx
callq 0x857a5
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x857a5
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
leaq 0x98(%rsp), %rbx
movq %rbx, %rdx
callq 0x857a5
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6e9a6
movq %rsp, %r14
movq %r14, %rdi
movq %r12, %rsi
leaq 0x80(%rsp), %rdx
callq 0x857a5
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x857a5
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x850c9
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6e9a6
movq %rsp, %r14
movq %r14, %rdi
movq %r12, %rsi
leaq 0x80(%rsp), %r12
movq %r12, %rdx
callq 0x857a5
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r13, %rbx
callq 0x850c9
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
leaq 0x98(%rsp), %r13
movq %r13, %rdx
callq 0x857a5
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6e9a6
movq %rsp, %r14
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
movq %r12, %rdx
callq 0x857a5
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %rbx, %r12
callq 0x850c9
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x850c9
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6e9a6
movq %rsp, %r14
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x80(%rsp), %rdx
movq %rdx, %rbx
callq 0x850c9
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x857a5
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x857a5
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6e9a6
movq %rsp, %r14
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
movq %rbx, %rdx
callq 0x850c9
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x857a5
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x850c9
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6e9a6
movq %rsp, %r14
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
movq %rbx, %rdx
callq 0x850c9
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x850c9
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x857a5
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6e9a6
movq %rsp, %r14
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
movq %rbx, %rdx
callq 0x850c9
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x850c9
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x850c9
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6e9a6
movaps 0x68658(%rip), %xmm1    # 0xde3a0
movaps 0x60(%rsp), %xmm2
movaps %xmm2, %xmm0
xorps %xmm1, %xmm0
movaps 0x70(%rsp), %xmm3
xorps %xmm3, %xmm1
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
callq 0xa0a64
movsd 0x18(%r14), %xmm0
subsd 0x8(%r14), %xmm0
movsd 0x20(%r14), %xmm1
subsd 0x10(%r14), %xmm1
movsd 0x58(%rsp), %xmm3
divsd %xmm3, %xmm0
movsd 0x683ab(%rip), %xmm2    # 0xde140
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %esi
divsd %xmm3, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %eax
cmpl $0x3, %esi
movl $0x2, %edx
cmovll %edx, %esi
cmpl $0x3, %eax
cmovgel %eax, %edx
movq 0x50(%rsp), %rdi
addq $0x130, %rdi            # imm = 0x130
movq %rdi, %rbx
xorl %ecx, %ecx
callq 0x977b2
leaq 0xb0(%rsp), %rsi
movq %rbx, %rdi
callq 0x91fce
leaq 0xb0(%rsp), %rdi
callq 0xa12e4
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0xa12e4
movq %rbx, %rdi
callq 0x138b0
nop