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


26.15 Querying

const function: bool is_on_free_store (void)

Returns true, if the Path was dynamically allocated on the free store, otherwise false.

const virtual function: bool is_planar ([const bool verbose = false, [string text = ""]])

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.

const function: bool is_linear ([const bool verbose = false, [string text = ""]])

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.

— Inline const function: bool is_cycle (void)

Returns true if the Path is cyclical, i.e., cycle_switch = true, otherwise false. Only cyclical Paths are fillable.

— Inline function: int size (void)

Returns the number of Points on points, i.e., points.size().

— Inline const function: bool get_line_switch (void)

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.

— Function: real slope ([char a = 'x', [char b = 'y']])

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.

const function: Path subpath (size_t start, size_t end, [const bool cycle = false, [const string connector = ""]])

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 function: const Point& get_point (const unsigned short a)

Returns the Point *points[a], if a < points.size() and the Path is non-empty, otherwise INVALID_POINT.

const function: const Point& get_last_point (void)

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.

const inline virtual function: size_t get_size (void)

Returns points.size().

const function: Line get_line (void)

Returns a Line corresponding to the Path, if the latter is linear. Otherwise, INVALID_LINE is returned. See Line Reference.

const virtual function: Point get_normal (void)

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!

const virtual function: Plane get_plane (void)

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.

— Function: void set_cycle ([const bool c = true])

Sets cycle_switch to c.

— Function: Path reverse (bool assign)
const function: Path reverse (void)

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.