7 #include "LineEquation.h"
8 #include "IException.h"
19 LineEquation::LineEquation() {
21 p_slopeDefined =
false;
22 p_interceptDefined =
false;
32 LineEquation::LineEquation(
double x1,
double y1,
double x2,
double y2) {
34 p_slopeDefined =
false;
35 p_interceptDefined =
false;
51 void LineEquation::AddPoint(
double x,
double y) {
53 std::string msg =
"Line equation is already defined with 2 points";
54 throw IException(IException::Io, msg, _FILEINFO_);
58 if(Points() == 2) p_defined =
true;
66 double LineEquation::Slope() {
68 std::string msg =
"Line equation undefined: 2 points are required";
69 throw IException(IException::Io, msg, _FILEINFO_);
71 else if(p_x[0] == p_x[1]) {
72 std::string msg =
"Points have identical independent variables -- no slope";
73 throw IException(IException::Io, msg, _FILEINFO_);
75 else if(!p_slopeDefined) {
76 p_slope = (p_y[0] - p_y[1]) / (p_x[0] - p_x[1]);
77 p_slopeDefined =
true;
87 double LineEquation::Intercept() {
89 std::string msg =
"Line equation undefined: 2 points are required";
90 throw IException(IException::Io, msg, _FILEINFO_);
92 else if(p_x[0] == p_x[1]) {
93 std::string msg =
"Points have identical independent variables -- no intercept";
94 throw IException(IException::Io, msg, _FILEINFO_);
96 else if(!p_interceptDefined) {
97 p_intercept = p_y[0] - Slope() * p_x[0];
98 p_interceptDefined =
true;