/******************************************************************************
 *
 * 9998sketch/geomio.c
 *
 * (c) Eugene K. Ressler, Jr. 2004, 2005
 *
 * A program related to the book
 *
 * Fundamentals of Virtual World Simulation
 * by Eugene K. Ressler, Jr.
 *
 * No warranty of correctness or capability of any kind is expressed or implied.
 *
 * The author grants free use of this code for any purpose as long any text,
 * executable program, library file, or source code distributed to others 
 * and employing any portion of this code clearly cites the book named above.
 *
 ******************************************************************************/

#include "geomio.h"

void print_pt_2d(FILE *f, POINT_2D pt)
{
  fprintf(f, "(%.3f,%.3f)", pt[X], pt[Y]);
}

void print_pt_3d(FILE *f, POINT_3D pt)
{
  fprintf(f, "(%.3f,%.3f,%.3f)", pt[X], pt[Y], pt[Z]);
}

void print_polyline_3d(FILE *f, POLYLINE_3D *polyline)
{
  int i;

  fprintf(f, "\\line");
  for (i = 0; i < polyline->n_vertices; i++)
    print_pt_3d(f, polyline->v[i]);
  fprintf(f, "\n");
}

void print_polygon_2d(FILE *f, POLYGON_2D *polygon)
{
  int i;

  fprintf(f, "\\polygon");
  for (i = 0; i < polygon->n_sides; i++)
    print_pt_2d(f, polygon->v[i]);
  fprintf(f, "\n");
}

void print_polygon_3d(FILE *f, POLYGON_3D *polygon)
{
  int i;

  fprintf(f, "\\polygon");
  for (i = 0; i < polygon->n_sides; i++)
    print_pt_3d(f, polygon->v[i]);
  fprintf(f, "\n");
}

void print_plane(FILE *f, PLANE *plane)
{
  fprintf(f, "\\plane[n=%.3f %.3f %.3f,p=%.3f %.3f %.3f,c=%.3f]\n",
    plane->n[X], plane->n[Y], plane->n[Z],
    plane->p[X], plane->p[Y], plane->p[Z],
    plane->c);
}
