File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
LineEquation.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "LineEquation.h"
8 #include "IException.h"
9 #include "IString.h"
10 #include <iostream>
11 #include <iomanip>
12 
13 using namespace std;
14 
15 namespace Isis {
19  LineEquation::LineEquation() {
20  p_defined = false;
21  p_slopeDefined = false;
22  p_interceptDefined = false;
23  }
24 
32  LineEquation::LineEquation(double x1, double y1, double x2, double y2) {
33  p_defined = false;
34  p_slopeDefined = false;
35  p_interceptDefined = false;
36  AddPoint(x1, y1);
37  AddPoint(x2, y2);
38  p_defined = true;
39  p_slope = Slope();
40  p_intercept = Intercept();
41  }
42 
51  void LineEquation::AddPoint(double x, double y) {
52  if(p_defined) {
53  std::string msg = "Line equation is already defined with 2 points";
54  throw IException(IException::Io, msg, _FILEINFO_);
55  }
56  p_x.push_back(x);
57  p_y.push_back(y);
58  if(Points() == 2) p_defined = true;
59  }
60 
66  double LineEquation::Slope() {
67  if(!p_defined) {
68  std::string msg = "Line equation undefined: 2 points are required";
69  throw IException(IException::Io, msg, _FILEINFO_);
70  }
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_);
74  }
75  else if(!p_slopeDefined) {
76  p_slope = (p_y[0] - p_y[1]) / (p_x[0] - p_x[1]);
77  p_slopeDefined = true;
78  }
79  return p_slope;
80  }
81 
87  double LineEquation::Intercept() {
88  if(!p_defined) {
89  std::string msg = "Line equation undefined: 2 points are required";
90  throw IException(IException::Io, msg, _FILEINFO_);
91  }
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_);
95  }
96  else if(!p_interceptDefined) {
97  p_intercept = p_y[0] - Slope() * p_x[0];
98  p_interceptDefined = true;
99  }
100 
101  return p_intercept;
102  }
103 
104 }
Isis::IException
Isis exception class.
Definition: IException.h:91
std
Namespace for the standard library.
Isis::Intercept
Container for a intercept condition.
Definition: Intercept.h:36
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:16:47