// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3PlanarGrid.cpp
// Function: gaps::R3PlanarGrid::Reset(gaps::R3Plane const&, gaps::R3Box const&, double)
void R3PlanarGrid::
Reset(const R3Plane& plane, const R3Box& world_bbox, RNLength spacing)
{
  // Update plane and bbox
  this->plane = plane;
  this->bbox = world_bbox;

  // Determine transformation from 3D to 2D
  R3Point centroid = world_bbox.Centroid();
  centroid.Project(plane);
  RNDimension dim = plane.Normal().MinDimension();
  R3Vector zaxis = plane.Normal();
  R3Vector xaxis = R3xyz_triad[dim] % zaxis;
  xaxis.Normalize();
  R3Vector yaxis = zaxis % xaxis;
  yaxis.Normalize();
  R3Triad triad(xaxis, yaxis, zaxis);
  R3CoordSystem cs(centroid, triad);
  transformation.Reset(cs.InverseMatrix());

  // Determine 2D bounding box
  R2Box planar_bbox = R2null_box;
  for (int i = 0; i < 8; i++) {
    R3Point corner = world_bbox.Corner(i);
    corner.Transform(transformation);
    planar_bbox.Union(R2Point(corner[0], corner[1]));
  }

  // 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 $0x1c8, %rsp            # imm = 0x1C8
movsd %xmm0, 0x8(%rsp)
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
callq 0x84fe2
movsd 0x18(%rbx), %xmm0
movsd %xmm0, 0x18(%r15)
leaq 0x208(%r15), %rdi
leaq 0x8(%r14), %rsi
callq 0x8412a
leaq 0x220(%r15), %rdi
leaq 0x20(%r14), %rsi
callq 0x8412a
movq (%r14), %rax
leaq 0x30(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq *0x68(%rax)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x8414a
movq %rbx, %rdi
callq 0x849a2
movl %eax, %ebp
leaq 0x108(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x84866
movslq %ebp, %rax
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0xbe8c1(%rip), %rsi     # 0x132fb0
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rdx
callq 0x8518a
movq %rbx, %rdi
callq 0x84b6c
leaq 0xd8(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x8518a
movq %r13, %rdi
callq 0x84b6c
leaq 0x120(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x70c18
leaq 0x168(%rsp), %rbx
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movq %rbp, %rdx
callq 0x707a8
movq %r15, 0x10(%rsp)
addq $0x20, %r15
leaq 0x48(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x70856
xorl %ebp, %ebp
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x7070c
leaq 0x4c17e0(%rip), %rsi    # 0x535f68
leaq 0x48(%rsp), %rdi
callq 0x9f714
leaq 0x18(%rsp), %r13
leaq 0xc8(%rsp), %rbx
movq %r13, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x6d5d2
movq %r13, %rdi
movq %r15, %rsi
callq 0x846d8
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movq %rbx, %rdi
callq 0xa2542
movq %r12, %rdi
movq %rbx, %rsi
callq 0x9fe22
incl %ebp
cmpl $0x8, %ebp
jne 0x7479f
movsd 0x60(%rsp), %xmm0
subsd 0x50(%rsp), %xmm0
movsd 0x68(%rsp), %xmm1
subsd 0x58(%rsp), %xmm1
movsd 0x8(%rsp), %xmm3
divsd %xmm3, %xmm0
movsd 0x68931(%rip), %xmm2    # 0xdd138
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 0x10(%rsp), %rbx
addq $0x130, %rbx            # imm = 0x130
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x96588
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0x90e72
leaq 0x48(%rsp), %rdi
callq 0xa00b0
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7486f
jmp 0x7486f
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xa00b0
movq %rbx, %rdi
callq 0x138b0