Isis 3 Programmer Reference
LineEquation.cpp
Go to the documentation of this file.
1 
23 #include "LineEquation.h"
24 #include "IException.h"
25 #include "IString.h"
26 #include <iostream>
27 #include <iomanip>
28 
29 using namespace std;
30 
31 namespace Isis {
35  LineEquation::LineEquation() {
36  p_defined = false;
37  p_slopeDefined = false;
38  p_interceptDefined = false;
39  }
40 
48  LineEquation::LineEquation(double x1, double y1, double x2, double y2) {
49  p_defined = false;
50  p_slopeDefined = false;
51  p_interceptDefined = false;
52  AddPoint(x1, y1);
53  AddPoint(x2, y2);
54  p_defined = true;
55  p_slope = Slope();
56  p_intercept = Intercept();
57  }
58 
67  void LineEquation::AddPoint(double x, double y) {
68  if(p_defined) {
69  std::string msg = "Line equation is already defined with 2 points";
70  throw IException(IException::Io, msg, _FILEINFO_);
71  }
72  p_x.push_back(x);
73  p_y.push_back(y);
74  if(Points() == 2) p_defined = true;
75  }
76 
82  double LineEquation::Slope() {
83  if(!p_defined) {
84  std::string msg = "Line equation undefined: 2 points are required";
85  throw IException(IException::Io, msg, _FILEINFO_);
86  }
87  else if(p_x[0] == p_x[1]) {
88  std::string msg = "Points have identical independent variables -- no slope";
89  throw IException(IException::Io, msg, _FILEINFO_);
90  }
91  else if(!p_slopeDefined) {
92  p_slope = (p_y[0] - p_y[1]) / (p_x[0] - p_x[1]);
93  p_slopeDefined = true;
94  }
95  return p_slope;
96  }
97 
103  double LineEquation::Intercept() {
104  if(!p_defined) {
105  std::string msg = "Line equation undefined: 2 points are required";
106  throw IException(IException::Io, msg, _FILEINFO_);
107  }
108  else if(p_x[0] == p_x[1]) {
109  std::string msg = "Points have identical independent variables -- no intercept";
110  throw IException(IException::Io, msg, _FILEINFO_);
111  }
112  else if(!p_interceptDefined) {
113  p_intercept = p_y[0] - Slope() * p_x[0];
114  p_interceptDefined = true;
115  }
116 
117  return p_intercept;
118  }
119 
120 }
Namespace for the standard library.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
Container for a intercept condition.
Definition: Intercept.h:51
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31