35 LineEquation::LineEquation() {
37 p_slopeDefined =
false;
38 p_interceptDefined =
false;
48 LineEquation::LineEquation(
double x1,
double y1,
double x2,
double y2) {
50 p_slopeDefined =
false;
51 p_interceptDefined =
false;
67 void LineEquation::AddPoint(
double x,
double y) {
69 std::string msg =
"Line equation is already defined with 2 points";
74 if(Points() == 2) p_defined =
true;
82 double LineEquation::Slope() {
84 std::string msg =
"Line equation undefined: 2 points are required";
87 else if(p_x[0] == p_x[1]) {
88 std::string msg =
"Points have identical independent variables -- no slope";
91 else if(!p_slopeDefined) {
92 p_slope = (p_y[0] - p_y[1]) / (p_x[0] - p_x[1]);
102 double LineEquation::Intercept() {
104 std::string msg =
"Line equation undefined: 2 points are required";
107 else if(p_x[0] == p_x[1]) {
108 std::string msg =
"Points have identical independent variables -- no intercept";
111 else if(!p_interceptDefined) {
112 p_intercept = p_y[0] - Slope() * p_x[0];