first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / graphiq / library / geometric / polygon.h
1 #ifndef POLYGON_CLASS
2 #define POLYGON_CLASS
3
4 /*****************************************************************************\
5 *                                                                             *
6 *  Name   : polygon                                                           *
7 *  Author : Chris Koeritz                                                     *
8 *                                                                             *
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 \*****************************************************************************/
17
18 //! Represents a multi-sided geometric figure made of line segments.
19 /*!
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.
24 */
25
26 #include "cartesian_objects.h"
27
28 #include <basis/array.h>
29
30 //hmmm: it might be nice to structuralize this.
31 //hmmm: also deriving from an array of points is not so great.
32
33 namespace geometric {
34
35 class polygon : public basis::array<geometric::cartesian_point>
36 {
37 public:
38   polygon() {}
39   ~polygon() {}
40
41   void add(const cartesian_point &to_add);
42     //!< adds a new point to the list that represents the polygon's sides.
43
44   int points() const { return length(); }
45   int sides() const { return points() - 1; }
46   
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. */
50
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
54     the check. */
55 };
56
57 } // namespace.
58
59 #endif
60