The RoseDirection class wraps a double[3] array of direction vector 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 directions back from your functions. The RoseDirection2D class wraps a double[2] for 2D direction vectors.

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] = { 0, 1, 0 };

// view the foo array as a class
RoseDirection& as_a_class = *((RoseDirection*)(foo));

// an actual instance of the class
RoseDirection actual_class (1/ROSE_SQRT_2, 1/ROSE_SQRT_2, 0);

Array Member

        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.

RoseDirection dir1 (0, 1, 0);

// completely equivalent
printf ("My data is %g, %g, %g\n", dir1.m[0], dir1.m[1], dir1.m[2]);
printf ("My data is %g, %g, %g\n", dir1.i(), dir1.j(), dir1.k());


RoseDirection(double i, double j, double k);
RoseDirection(const double src[3]);
RoseDirection(ListOfDouble * lst);

The RoseDirection() default constructor initializes the direction components to zero, while the other initialize the components from an array, separate parameters, or a list object.

double foo[3] = { 0, 0, 1 };

// default ctor initializes as zeros
RoseDirection i_am_all_zero;

// initialized with three arguments
RoseDirection dir1 (1/ROSE_SQRT_2, 1/ROSE_SQRT_2, 0);

// initialized by copying contents of foo
RoseDirection pt2 (foo);
RoseDirection pt3 = foo;	// same

// initialized by copying another RoseDirection
RoseDirection pt4 = pt3;


double i() const;
void i (double val);

The i() function gets or sets the first element of the array, which represents the i component of a direction vector.


void ijk (double i, double j, double k);

The ijk() function sets all three elements of the array with a single call instead of three separate calls.

RoseDirection dir1;

// completely equivalent
dir1.ijk (1/ROSE_SQRT_2, 1/ROSE_SQRT_2, 0);

dir1.i (1/ROSE_SQRT_2);
dir1.j (1/ROSE_SQRT_2);
dir1.k (0);


double j() const;
void j (double val);

The j() function gets or sets the second element of the array, which represents the j component of a direction vector.


double k() const;
void k (double val);

The k() function gets or sets the third element of the array, which represents the k component of a direction vector.