Node: Querying Paths, Next: , Previous: Showing Paths, Up: Path Reference



Querying

bool is_on_free_store (void) const function
Returns true, if the Path was dynamically allocated on the free store, otherwise false.

bool is_planar ([const bool verbose = false, [string text = ""]]) const virtual function
Uses get_normal() to determine whether the Path is planar or not. Returns true, if it is, otherwise false. If verbose is true, text is written to standard output, or "Path:", if text is the empty string, followed by a message saying whether the Path is planar or not.

bool is_linear ([const bool verbose = false, [string text = ""]]) const function
Returns true, if line_switch is true. Otherwise, is_linear() uses get_normal() to determine whether the Path is linear. If it is, is_linear() returns true, otherwise false.

bool is_cycle (void) Inline const function
Returns true if the Path is cyclical, i.e., cycle_switch = true, otherwise false. Only cyclical Paths are fillable.

int size (void) Inline function
Returns the number of Points on points, i.e., points.size().

bool get_line_switch (void) Inline const function
Returns the value of line_switch. line_switch is only true, if the Path was created, directly or indirectly, using the constructor taking two Point arguments only. See Path Reference; Constructors and Setting Functions.

real slope ([char a = 'x', [char b = 'y']]) Function
Returns the slope of the Path in the plane indicated by the arguments, if is_linear() returns true. Otherwise, slope() issues an error message and returns INVALID_REAL.

Path subpath (size_t start, size_t end, [const bool cycle = false, [const string connector = ""]]) const function
Returns a new Path using points[start] through points[end - 1]. If cycle is true, then the new Path will be a cycle, whether *this is or not. One optional connector argument can be used. If it is, it will be the only connector. Otherwise, the appropriate connectors from *this are used.

start must be < end. It is not possible to have start > end, even if *this is a cycle.

const Point& get_point (const unsigned short a) const function
Returns the Point *points[a], if a < points.size() and the Path is non-empty, otherwise INVALID_POINT.

const Point& get_last_point (void) const function
Returns the Point pointed to by the last pointer on points. Equivalent to get_point(get_size() - 1), but more convenient to type. Returns INVALID_POINT, if the Path is empty.

size_t get_size (void) const inline virtual function
Returns points.size().

Line get_line (void) const function
Returns a Line corresponding to the Path, if the latter is linear. Otherwise, INVALID_LINE is returned. See Line Reference.

Point get_normal (void) const virtual function
Returns a Point representing a unit vector in the direction of the normal to the plane of the Path, or INVALID_POINT, if the Path is non-planar.
          Point P(1, 1, 1);
          Rectangle r(P, 4, 4, 30, 30, 30);
          Point N = r.get_normal();
          


[Figure 136. Not displayed.]

Fig. 136.

In 3DLDF, plane figures generally have constructors taking a |Point| argument for the center, a variable number of |real| arguments for the dimensions, and three |real| arguments for the rotation about the major axes. The object is first created in the x-z plane, and the Points are generated to be traversed in the counter-clockwise direction, when seen from a Point with a positive y-coordinate. If no rotation is specified, the normal will point in the direction of the positive y-axis. If non-zero arguments are used for rotation, the normal will be rotated accordingly. This direction considered to be "outside". However, according to Huw Jones, Computer Graphics Through Key Mathematics, p. 197, "outside" is considered to be the side of a plane, where the Points are meant to be traversed in the clockwise direction. I hope that no problems arise from this discrepancy!

Plane get_plane (void) const virtual function
Creates and returns a Plane p corresponding to the Path, if the latter is planar, otherwise INVALID_PLANE. If the Path is planar, p.point will be the Point pointed to by this->points[0]. See Plane Reference.
          Point P(1, 1, 1);
          Rectangle r(P, 4, 4, 45, 20, 15);
          Plane q = r.get_plane();
          q.show("q:");
          -| q:
             normal: (0.0505914, 0.745607, -0.664463)
             point: (0.0178869, -0.727258, -1.01297)
             distance == -0.131735
          


[Figure 137. Not displayed.]

Fig. 137.

void set_cycle ([const bool c = true]) Function
Sets cycle_switch to c.

Path reverse (bool assign) Function
Path reverse (void) const function
These functions return a Path with the same Points and connectors as *this, but in reversed order. reverse() can only be applied to non-cyclical Paths. If *this is a cycle, reverse() issues an error message and returns *this unreversed.

If the first version is called with assign = true, *this itself is reversed. If *this should remain unchanged, the const version without an argument should be called. If, on the other hand, the first version is called with assign = false, a warning message is issued, but the reversed Path is returned just the same, leaving *this unchanged.