37d9d788ea7a7d45b3c41feb9067226042fee9a0
[snark14.git] / tools / Display / line_real_t.cpp
1 /** @file line_real_t.cpp
2     @package snark14Display
3     @author Bruno M. Carvalho and Deniz Sarioz
4     licensed under (open-source) QPL v1.0
5     which accompanies this distribution in the file QPL
6 */
7
8 #include <exception>
9 #include <stdexcept>
10
11 #include <qstring.h>
12
13 #include "sd_line_t.hpp"
14 #include "line_real_t.hpp"
15 #include "line_real_set_t.hpp"
16
17 #include <iostream>
18
19 class line_real_set_t;
20
21 line_real_t::line_real_t(QString name) {
22   plotname = name;
23   mySetP = 0;
24 }
25
26 line_real_t::line_real_t(QString name, int fromX, int toX, double atY) { // good for phantom
27   plotname = name;
28   mySetP = 0;
29   for(int x = fromX; x <= toX; x++) {
30     add(x,atY);
31   }
32 }
33
34 bool line_real_t::empty() { return data.empty(); }
35
36 void line_real_t::add(int x, double y) {
37   point_real_t p = {x, y};
38   data.push_back(p);
39 } // --line_real_t::add()
40
41 void line_real_t::clear() { data.clear(); }
42
43 // these 4 must wait until the end of line_real_set_t def
44
45 int line_real_t::getMinX() {
46   if(0 == mySetP)
47     throw std::logic_error("line_real's set not set!");
48   return mySetP->getMinX();
49 }
50
51 int line_real_t::getMaxX() {
52   if(0 == mySetP)
53     throw std::logic_error("line_real's set not set!");
54   return mySetP->getMaxX();
55 }
56
57 double line_real_t::getMinY() {
58   if(0 == mySetP)
59     throw std::logic_error("line_real's set not set!");
60   return mySetP->getMinY();
61 }
62
63 double line_real_t::getMaxY() {
64   if(0 == mySetP)
65     throw std::logic_error("line_real's set not set!");
66   return mySetP->getMaxY();
67 }
68
69 QString line_real_t::getName() { return plotname; }
70
71 void line_real_t::setset(line_real_set_t* sp) {  mySetP = sp;  }
72
73 /** debug routine -- caller is responsible */
74 void line_real_t::show() {
75   for(data_real_t::const_iterator it = data.begin(); it != data.end(); it++) {
76     std::cerr << "(" << (it->x) << "," << (it->y) << ")" << " ";
77   }
78   std::cerr << " ##### ";
79 }