Overview

The RoseDirection2D class is a variation of the RoseDirection class for use with 2D direction vectors. It wraps a double[2] array with inline member functions for simple access and update. The RoseDirection class discusses how to use these class wrappers instead of the raw arrays.

It is defined in the rose_xform.h header file.

Array Member

public:
        double m[2];

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.

RoseDirection2D dir1 (0, 1);

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

Constructor

RoseDirection2D();
RoseDirection2D(double i, double j);
RoseDirection2D(const double src[2]);
RoseDirection2D(ListOfDouble * lst);

The RoseDirection2D() 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, 1 };

// default ctor initializes as zeros
RoseDirection2D i_am_all_zero;

// initialized with two arguments
RoseDirection2D dir1 (1/ROSE_SQRT_2, 1/ROSE_SQRT_2);

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

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

i()

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.

ij()

void ij (double i, double j);

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

RoseDirection2D dir1;

// completely equivalent
dir1.ij (1/ROSE_SQRT_2, 1/ROSE_SQRT_2);

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

j()

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.