HilVert  1v2
A demo of the Hilbert Curve in SVG.
HilVert.hpp
Go to the documentation of this file.
1 // FILE HilVert.hpp
2 // DATE 200922
3 // WRITTEN RAC
4 // LANGUAGE C++, XCode
5 // PURPOSE Header for the hilbert curve SVG demo. $
6 // KEYWORDS HILBERT/CURVE/DRAW/PLOT/ANIMATE
7 // PROJECT WEB
8 // TARGET Command line C++ 17
9 // CATEGORY Utility
10 //
11 #ifndef HILVERT_HPP
12 #define HILVERT_HPP
13 //
14 //
15 //
16 //
17 //
18 //
19 // Disclaimer -
20 //
21 // This bugware was misconceived by a weekend hacker with decades of
22 // experience in packing the most errors into every line of code.
23 //
24 // If it compiles it's amazing.
25 // If it runs it's a miracle.
26 // If it gives the right results it's unbelievable.
27 //
28 
37 //
38 //
39 #include <string>
40 #include <map>
41 #include <iostream>
42 #include <sstream>
43 #include <fstream>
44 
59 class HilVert {
60 
61  public:
62 
69  enum class HVenm {
70  errNone,
71  errArgc,
72  errOrder,
73  errHdng,
74  errRotat,
75  errFile,
76  errUknown,
77  right,
78  down,
79  left,
80  up,
81  stard,
82  anticlock,
83  clockwise,
84  alike,
86  };
87 
88  explicit
90  int curvOrd = 1,
91  HVenm heading = HVenm::down,
92  HVenm rotation = HVenm::clockwise,
93  std::ostream* outSink = &std::cout
94  );
95  HilVert (const HilVert& src);
96  HilVert& operator= (const HilVert& src);
97  ~HilVert (){}
98 
99  void draw();
100  HilVert::HVenm cmndLn(int argc, const char * argv[]);
101  void grfc(); // Draw complete graphic
102  std::string vers(); // The version string
103 
104  const std::string& errs(HVenm erno);
105 
106 
107  private:
108  std::ofstream ofs; // If we stream to a file
109  std::ostream* osink; // Where to send the curve
110  HVenm hdng; // Heading
114  int crvOrd;
115  void turnExe(HVenm sense);
116  void sgmnt();
117  void drawChld(HVenm flipRot);
118  static constexpr int segPx{4}; // Segment length in SVG px
119  static constexpr int linSegsCrd{20};
120  bool flush{true};
127  static const std::map<HVenm, std::string> errTyp;
128 };
129 
130 
131 
132 
133 
134 
135 //
136 // end Cartesian ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
137 //
138 //
139 #endif // #ifndef HILVERT_HPP
HilVert::draw
void draw()
Output the SVG line segments for a complete HC.
Definition: HilVert.cpp:527
HilVert::HVenm::errOrder
@ errOrder
HilVert::HVenm::errArgc
@ errArgc
HilVert::grfc
void grfc()
Output a complete HC in Scaleable Vector Graphic format.
Definition: HilVert.cpp:677
HilVert::rotn
HVenm rotn
Definition: HilVert.hpp:126
HilVert::errs
const std::string & errs(HVenm erno)
Translate an error code to a text string.
Definition: HilVert.cpp:323
HilVert::HVenm::stard
@ stard
HilVert::osink
std::ostream * osink
Definition: HilVert.hpp:109
HilVert
Generate SVG visualisations of the Hilbert Curve (HC).
Definition: HilVert.hpp:59
HilVert::HVenm::errNone
@ errNone
HilVert::segPx
static constexpr int segPx
Definition: HilVert.hpp:118
HilVert::ofs
std::ofstream ofs
Definition: HilVert.hpp:108
HilVert::errTyp
static const std::map< HVenm, std::string > errTyp
Definition: HilVert.hpp:127
HilVert::vers
std::string vers()
Generate the version number for HilVert.
Definition: HilVert.cpp:610
HilVert::HVenm
HVenm
Definition: HilVert.hpp:69
HilVert::HVenm::anticlock
@ anticlock
HilVert::linSegsCrd
static constexpr int linSegsCrd
Definition: HilVert.hpp:119
HilVert::~HilVert
~HilVert()
Definition: HilVert.hpp:97
HilVert::HVenm::up
@ up
HilVert::HVenm::clockwise
@ clockwise
HilVert::HVenm::down
@ down
HilVert::HVenm::errFile
@ errFile
HilVert::crvOrd
int crvOrd
Definition: HilVert.hpp:114
HilVert::operator=
HilVert & operator=(const HilVert &src)
HilVert::HVenm::widdershins
@ widdershins
HilVert::sgmnt
void sgmnt()
Draw a path segment.
Definition: HilVert.cpp:394
HilVert::HVenm::alike
@ alike
HilVert::HilVert
HilVert(int curvOrd=1, HVenm heading=HVenm::down, HVenm rotation=HVenm::clockwise, std::ostream *outSink=&std::cout)
HilVert::HVenm::left
@ left
HilVert::HVenm::errHdng
@ errHdng
HilVert::turnExe
void turnExe(HVenm sense)
Alter the current heading by 90 degrees.
Definition: HilVert.cpp:290
HilVert::HVenm::errUknown
@ errUknown
HilVert::flush
bool flush
Definition: HilVert.hpp:120
HilVert::HVenm::right
@ right
HilVert::cmndLn
HilVert::HVenm cmndLn(int argc, const char *argv[])
This is called by the main() function to set up the HilVert object.
Definition: HilVert.cpp:567
HilVert::hdng
HVenm hdng
Definition: HilVert.hpp:110
HilVert::drawChld
void drawChld(HVenm flipRot)
Definition: HilVert.cpp:423
HilVert::HVenm::errRotat
@ errRotat