// system includes
#include <math.h>
#include <iostream.h>
#include <stdlib.h>

// openGL includes
#include <GL/gl.h>
#include <GL/glu.h>

// gprims utility library: need definition of max_flt, etc.
#include "gprims/vector.H"

// local includes
#include "drawutils.H"
#include "lpsol.H"
#include "constraint.H"
#include "object.H"
#include "optfxn.H"
#include "lp.h"

/* creates a linear programming problem with 4 constraints and an
   optimization function */
Lpsol::Lpsol( Constraint *constraints, Float3 *optfxn ) {
  // initialize constraints
  _H = new Constraint[4];
  _H[0] = constraints[0];
  _H[1] = constraints[1];
  _H[2] = constraints[2];
  _H[3] = constraints[3];
  // initialize optimization function
  _c = new Optfxn(optfxn);
  // initialize solution
  _soln = new Float3(0.0,0.0,0.0);
  // initialize sphere to represent solution
  _sphere = new Sphere(); // note: insert creation arguments
  _sphere->setPosition(_soln);
  // initialize bounding box to go from -1->1 on all axes
  *_bb = new BB(-1,1,-1,1,-1,1);
}

/* draws indexed constraint within bounding box */
int
drawConstraint(int index, float r, float g, float b) {
  _H[index].draw(r,g,b,_bb);
  return 1;
}

/* draws all constraints within bounding box */
int
drawConstraints(float r, float g, float b) {
  for (int i=0; i<4; i++) {
    drawConstraint(i,r,g,b);
  }
  return 1;
}

/* draws sphere at solution point */
int
drawSolution(float r, float g, float b) {
  _soln->draw(r,g,b,_bb);
  return 1;
}

/* draws optimization function vector
   (seg from origin with sphere at arrow tip */
int
drawOptfxn() {
  _c->draw(r,g,b);
  return 1;
}

/* draws bounding box */
int
drawBB(float r, float g, float b) {
  _bb->draw();
  return 1;
}
