4 /*****************************************************************************\
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 1992-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 //! Represents a multi-sided geometric figure made of line segments.
20 The polygon is a list of points that are assumed to be connected. It will
21 have as many sides as its point count minus one. Thus there is no valid
22 polygon with less than three points. A function that tests whether a point
23 is inside or outside the polygon is provided.
26 #include "cartesian_objects.h"
28 #include <basis/array.h>
30 //hmmm: it might be nice to structuralize this.
31 //hmmm: also deriving from an array of points is not so great.
35 class polygon : public basis::array<geometric::cartesian_point>
41 void add(const cartesian_point &to_add);
42 //!< adds a new point to the list that represents the polygon's sides.
44 int points() const { return length(); }
45 int sides() const { return points() - 1; }
47 cartesian_point &operator [] (int index);
48 //!< retrieves the index-th point in the list.
49 /*!< this is valid for indices between zero and points() - 1. */
51 bool inside(const cartesian_point &to_check);
52 //!< Returns true if the point "to_check" is inside of this polygon.
53 /*!< This function assumes that the polygon is closed when performing