Overview
The RosePoint class wraps a double[3] array of coordinate data with inline member functions for simple access and update. The C++ compiler provides copy operatiors and temp object creation, so you can use this to pass coordinates data back from your functions. The RosePoint2D class wraps a double[2] for 2D coordinate data.
It is defined in the rose_xform.h header file.
Everything is public so you can use the class with an array function by just passing the ".m" member. All calculations are done in separate C-style functions, although we usually provide overloads that take an array or a reference to a wrapper class.
There are no virtual fuctions, so the memory layout of the class is identical to the array. This lets you use a reinterpret cast to view an existing array as a class reference if needed.
double foo[3] = { 1, 2, 3 }; // view the foo array as a class RosePoint& as_a_class = *((RosePoint*)(foo)); // an actual instance of the class RosePoint actual_class (1, 2, 3);
Array Member
public: double m[3];
The class has a public array member with the coordinates. You can access the data directly whenever you want. The member functions are strictly for clearer code and better compiler checking.
RosePoint pt1 (100, 100, 3); // completely equivalent printf (My data is %g, %g, %g\n, pt1.m[0], pt1.m[1], pt1.m[2]); printf (My data is %g, %g, %g\n, pt1.x(), pt1.y(), pt1.z());
Constructor
RosePoint(); RosePoint(double x, double y, double z); RosePoint(const double src[3]); RosePoint(ListOfDouble * lst);
The RosePoint() default constructor initializes the coordinates to zero, while the other initialize the coordinates from an array, separate parameters, or a list object.
double foo[3] = { 1, 2, 3 }; // default ctor initializes as zeros RosePoint i_am_all_zero; // initialized with three arguments RosePoint pt1 (100, 100, 3); // initialized by copying contents of foo RosePoint pt2 (foo); RosePoint pt3 = foo; // same // initialized by copying another RosePoint RosePoint pt4 = pt3;
x()
double x() const; void x (double val);
The x() function gets or sets the first element of the array, which represents the x coordinate of a cartesian point.
xyz()
void xyz (double x, double y, double z);
The xyz() function sets all three elements of the array with a single call instead of three separate calls.
RosePoint pt1; // completely equivalent pt1.xyz (100, 100, 3); pt1.x (100); pt1.y (100); pt1.z (3);
y()
double y() const; void y (double val);
The y() function gets or sets the second element of the array, which represents the y coordinate of a cartesian point.
z()
double z() const; void z (double val);
The z() function gets or sets the third element of the array, which represents the z coordinate of a cartesian point.