// File: tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Polyline.cpp
// Function: gaps::R3Polyline::IsPlanar() const
const RNBoolean R3Polyline::
IsPlanar(void) const
{
  // Return whether spline lies on one line
  if (nvertices == 0) return FALSE;
  if (nvertices <= 3) return TRUE;

  // Check if vertices all line on same plane
  R3Plane plane;
  int plane_npositions = 0;
  R3Point plane_positions[3];
  for (int i = 0; i < nvertices; i++) {
    if (plane_npositions == 0) {
      plane_positions[plane_npositions++] = vertex_positions[i];
    }
    else if ((plane_npositions == 1) &&
             !R3Contains(plane_positions[0], vertex_positions[i])) {
      plane_positions[plane_npositions++] = vertex_positions[i];
    }
    else if ((plane_npositions == 2) &&
             !R3Contains(plane_positions[0], vertex_positions[i]) &&
             !R3Contains(plane_positions[1], vertex_positions[i])) {
      plane_positions[plane_npositions++] = vertex_positions[i];
      R3Vector v1 = plane_positions[1] - plane_positions[0];
      R3Vector v2 = plane_positions[2] - plane_positions[0];
      R3Vector normal = v1 % v2; normal.Normalize();
      plane.Reset(plane_positions[0], normal);
    }
    else if (!R3Contains(plane, vertex_positions[i])) {
      return FALSE;
    }
  }

  // All vertices are on same plane
  return TRUE;
}

// Assembly:
subq $0xf8, %rsp
movq %rdi, 0xe8(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x20(%rax)
jne 0x92c12
movl $0x0, 0xf4(%rsp)
jmp 0x92ead
movq 0x18(%rsp), %rax
cmpl $0x3, 0x20(%rax)
jg 0x92c2d
movl $0x1, 0xf4(%rsp)
jmp 0x92ead
leaq 0xc8(%rsp), %rdi
callq 0x6c130
movl $0x0, 0xc4(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, %rcx
addq $0x48, %rcx
movq %rcx, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x6eb40
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, 0x10(%rsp)
jne 0x92c5b
movl $0x0, 0x6c(%rsp)
movq 0x18(%rsp), %rcx
movl 0x6c(%rsp), %eax
cmpl 0x20(%rcx), %eax
jge 0x92ea2
cmpl $0x0, 0xc4(%rsp)
jne 0x92ce4
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rsi
movslq 0x6c(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rsi
movl 0xc4(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0xc4(%rsp)
cltq
leaq 0x70(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x6f1e0
jmp 0x92e90
cmpl $0x1, 0xc4(%rsp)
jne 0x92d52
movq 0x18(%rsp), %rax
leaq 0x70(%rsp), %rdi
movq 0x8(%rax), %rsi
movslq 0x6c(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rsi
callq 0x82180
cmpl $0x0, %eax
jne 0x92d52
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rsi
movslq 0x6c(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rsi
movl 0xc4(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0xc4(%rsp)
cltq
leaq 0x70(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x6f1e0
jmp 0x92e8e
cmpl $0x2, 0xc4(%rsp)
jne 0x92e56
movq 0x18(%rsp), %rax
leaq 0x70(%rsp), %rdi
movq 0x8(%rax), %rsi
movslq 0x6c(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rsi
callq 0x82180
cmpl $0x0, %eax
jne 0x92e56
movq 0x18(%rsp), %rax
leaq 0x70(%rsp), %rdi
addq $0x18, %rdi
movq 0x8(%rax), %rsi
movslq 0x6c(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rsi
callq 0x82180
cmpl $0x0, %eax
jne 0x92e56
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rsi
movslq 0x6c(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rsi
movl 0xc4(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0xc4(%rsp)
cltq
leaq 0x70(%rsp), %rdi
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x6f1e0
leaq 0x70(%rsp), %rsi
addq $0x18, %rsi
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rdi
callq 0x6eeb0
leaq 0x70(%rsp), %rsi
addq $0x30, %rsi
leaq 0x70(%rsp), %rdx
leaq 0x38(%rsp), %rdi
callq 0x6eeb0
leaq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x38(%rsp), %rdx
callq 0x70af0
leaq 0x20(%rsp), %rdi
callq 0x70410
leaq 0x70(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x6d2e0
jmp 0x92e8c
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rsi
movslq 0x6c(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rsi
leaq 0xc8(%rsp), %rdi
callq 0x83240
cmpl $0x0, %eax
jne 0x92e8a
movl $0x0, 0xf4(%rsp)
jmp 0x92ead
jmp 0x92e8c
jmp 0x92e8e
jmp 0x92e90
jmp 0x92e92
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x92c88
movl $0x1, 0xf4(%rsp)
movl 0xf4(%rsp), %eax
addq $0xf8, %rsp
retq
nopl (%rax)