Back to index

PHPolyLine.C

 
//--------------------------------------------------------------------------------------- 
//  
// Includes:  PHPolyLine.h 
// 
// Created by:  Jane M. Burward-Hoy and Federica Messer 
// 
// Purpose:  The constructor, destructor, copy constructor, and assignment functions are 
//           defined here for the PHPolyLine class. 
//            
// Last update:  11/12/99 
// 
//------------------------------------------------------------------------------------ 
#include "PHPoint.h" 
#include "PHVector.h" 
#include "PHPolyLine.h" 
 
PHPolyLine::PHPolyLine() 
{ 
} 
 
PHPolyLine::~PHPolyLine() 
{ 
} 
 
 
// PHPolyLine::PHPolyLine(PHPolyLine &rhs) 
// { 
//   polyline = rhs; 
// } 
 
// PHPolyLine& PHPolyLine::operator=(const PHPolyLine &rhs) 
// { 
//   polyline = rhs; 
//   return *this; 
// } 
 
ostream&  operator<< (ostream &os, PHPolyLine &rhs) 
{ 
  os << rhs << endl; 
  return os; 
} 
 
double PHPolyLine::length(const size_t n1, const size_t n2) const 
  // Calculates the total length of polyline within indices n1 an n2.  
{  
 double totalLength = 0.0; 
 size_t i, first, last; 
 PHVector segment; 
 PHPoint p1,p2, *p; 
 
if ((n2 > polyline.length()) || (n1 > polyline.length()) ) 
  { 
  cout << "ERROR in PHPolyLine::length(size_t, size_t): index greater than number of entries in list" << endl; 
  return 0.0; 
  } 
else 
  { 
    if (n2 > n1)       { first = n1; last = n2; } 
    else if (n1 > n2 ) { first = n2; last = n1; } 
 
    for (i = first; i < last+1 ; i++) 
      { 
	PHPoint p1(getPoint(i)->getX(), getPoint(i)->getY(), getPoint(i)->getZ()); 
	PHPoint p2(getPoint(i+1)->getX(), getPoint(i+1)->getY(), getPoint(i+1)->getZ()); 
	segment = p2 - p1; 
	totalLength += segment.length(); 
      } 
 
    return totalLength; 
  } 
} 
 
PHPoint* PHPolyLine::getPoint(const size_t n) const 
{ 
  return polyline[n]; 
} 
 
 
 
 
 
 

Back to index