/*
 * Jeffrey Ladino - jnl22@ccs.neu.edu
 *
 * File: shape2d.cpp
 *
 * Change Log
 ************
 ** July 27, 1999 - Jeff Ladino
 * Created.
 *
 */

#include "shape2d.h"

#include "transforms.h"
#include <stdio.h>
#include <assert.h>

shape2d::shape2d(){
  points = 2;
  point = new vector3d[points];
  assert(point != NULL);
  point[0][2] = 1.0;
  point[1][2] = 1.0;
}

shape2d::shape2d(unsigned n){
  points = n;
  point = new vector3d[points];
  assert(point != NULL);
  for(int i=0;i<points;i++)
    point[i][2] = 1.0;
}

shape2d::shape2d(const shape2d& source){
  points = source.points;
  point = new vector3d[points];
  for(int i=0;i<points;i++)
    for(int j=0;j<3;j++)
      point[i][j] = source.point[i][j];
}

vector3d& shape2d::operator[](unsigned i){
  assert(i<points);
  return point[i];
}

void shape2d::draw(SimpleDraw& sd, matrix3d& m){
  vector3d plot1, plot2;
  for(int i=1; i<points; i++){
    plot1 = m * point[i-1];
    plot2 = m * point[i];
    if(VERBOSITY > 1){
      printf("\nShape2d.draw()\n");
      printf("plotting line from (%d, %d) to (%d, %d)\n",
	  (int)plot1[Xpt], (int)plot1[Ypt], (int)plot2[Xpt], (int)plot2[Ypt]);
    }
    sd.DrawLine((int)plot1[Xpt], (int)plot1[Ypt], 
		(int)plot2[Xpt], (int)plot2[Ypt]);
  }
  // if more than just a line, connect the last point with the first
  if(points>2){
    plot1 = m * point[points-1];
    plot2 = m * point[0];
    if(VERBOSITY > 1){
      printf("plotting line from (%d, %d) to (%d, %d)\n",
	   (int)plot1[Xpt], (int)plot1[Ypt], (int)plot2[Xpt], (int)plot2[Ypt]);
    }
    sd.DrawLine((int)plot1[Xpt], (int)plot1[Ypt], 
		(int)plot2[Xpt], (int)plot2[Ypt]);
  }
}

void shape2d::print(){
  for(int j=0; j<points; j++){
    printf("point[%d] = (%e, %e)\n", j, point[j][Xpt], point[j][Ypt]);
  }
}


