rectangle.h

Go to the documentation of this file.
00001 #ifndef RECTANGLE_CLASS
00002 #define RECTANGLE_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : rectangle                                                         *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1992-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "point.h"
00019 
00020 namespace geometric {
00021 
00023 
00024 template <class numeric_type>
00025 class rectangle : public packable
00026 {
00027 public:
00028   rectangle(const point<numeric_type> &vertex_1,
00029           const point<numeric_type> &vertex_2);
00030   rectangle(numeric_type x_1 = 0, numeric_type y_1 = 0,
00031           numeric_type x_2 = 0, numeric_type y_2 = 0);
00032 
00033   numeric_type height() const;
00034   numeric_type width() const;
00035 
00036   rectangle order() const;
00038 
00042   point<numeric_type> top_left() const;
00043   point<numeric_type> bottom_left() const;
00044   point<numeric_type> top_right() const;
00045   point<numeric_type> bottom_right() const;
00047 
00052   numeric_type minimum_x() const;
00054   numeric_type minimum_y() const;
00056   numeric_type maximum_x() const;
00058   numeric_type maximum_y() const;
00060 
00061   point<numeric_type> center() const;
00063 
00064   bool inside(const point<numeric_type> &to_check) const;
00066 
00067   bool operator == (const rectangle &to_compare) const;
00069   bool operator != (const rectangle &to_compare) const;
00071 
00072   rectangle operator + (const point<numeric_type> &to_add) const;
00074   rectangle operator - (const point<numeric_type> &to_subtract) const;
00076 
00077   rectangle &operator += (const point<numeric_type> &to_add);
00079   rectangle &operator -= (const point<numeric_type> &to_subtract);
00081 
00082   void encompass(const rectangle &to_adjust_to);
00084 
00089   bool intersect(const rectangle &r2) const;
00091 
00092   bool disjoint(const rectangle &r2) const;
00094 
00095   bool join_intersecting(const rectangle &r2, rectangle &result);
00097 
00101   bool intersection(const rectangle &r2, rectangle &result);
00103 
00107   istring text_form() const;
00109 
00110   bool from_text(const istring &text);
00112 
00113   point<numeric_type> vertex_1() const;
00114   point<numeric_type> vertex_2() const;
00115 
00116   void vertex_1(const point<numeric_type> &to_set);
00117   void vertex_2(const point<numeric_type> &to_set);
00118 
00119   virtual void pack(byte_array &packed_form) const;
00120   virtual bool unpack(byte_array &packed_form);
00121 
00122 protected:
00123   point<numeric_type> _vertex_1;
00124   point<numeric_type> _vertex_2;
00125 };
00126 
00128 
00130 
00131 typedef rectangle<int> int_rectangle;
00132 
00133 } // namespace.
00134 
00135 #endif
00136 

Generated on Fri Nov 21 04:29:43 2008 for HOOPLE Libraries by  doxygen 1.5.1