Hex.h

Go to the documentation of this file.
00001 //**********************************************************************
00002 //
00003 //  REGCOM: Regimental Command
00004 //  Copyright (C) 2008 Randi J. Relander
00005 //    <rjrelander@users.sourceforge.net>
00006 //
00007 //  This program is free software; you can redistribute it and/or
00008 //  modify it under the terms of the GNU General Public License
00009 //  as published by the Free Software Foundation; either version 3
00010 //  of the License, or (at your option) any later version.
00011 //  
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //  
00017 //  You should have received a copy of the GNU General Public
00018 //  License along with this program.  If not, see 
00019 //  <http://www.gnu.org/licenses/>.
00020 //  
00021 //**********************************************************************
00022 
00023 #ifndef REGCOM_COMMON_HEX_H
00024 #define REGCOM_COMMON_HEX_H
00025 
00026 // NAMESPACES
00027 namespace regcom {
00028 namespace common {
00029 
00031 //  CLASS: Hex
00037 class Hex
00038 {
00039 public:
00040 
00041     // PUBLIC METHODS
00042 
00044     Hex() { m_IsEmpty = true; }
00045 
00047     Hex(int x, int y);
00048 
00050     ~Hex();
00051 
00053     Hex NeighborHex(int dir) const;
00054     
00056     int HexRange(Hex hex) const;
00057 
00059     void NextHexes(Hex h0, Hex h1,
00060         Hex prev1, Hex prev2, Hex& next1, Hex& next2) const;
00061     
00063     bool IntersectsLine(double x0, double y0, double x1, double y1) const;
00064 
00066     bool IsEmpty() const { return m_IsEmpty; }
00067     
00069     void SetEmpty() { m_IsEmpty = true; }
00070 
00072     bool operator==(const Hex& hex) const
00073         { return (!IsEmpty()) && (!hex.IsEmpty()) && (m_HexX == hex.m_HexX) && (m_HexY == hex.m_HexY); }
00074 
00076     bool operator!=(const Hex& hex) const
00077         { return (IsEmpty()) || (hex.IsEmpty()) || (m_HexX != hex.m_HexX) || (m_HexY != hex.m_HexY); }
00078 
00080     int GetHexX() { return m_HexX; }
00081     
00083     int GetHexY() { return m_HexY; }
00084 
00085 private:
00086 
00087     // MEMBER VARIABLES
00088 
00090     bool m_IsEmpty;
00091 
00093     int m_HexX;
00094 
00096     int m_HexY;
00097 
00099     double m_CenterX;
00100     
00102     double m_CenterY;
00103 
00105     double m_PointX[6];
00106     
00108     double m_PointY[6];
00109 };
00110 
00111 } // namespace common
00112 } // namespace regcom
00113 
00114 #endif