Add infos into target window
[ryzomcore.git] / ryzom / server / src / entities_game_service / area_geometry.h
blobdd583da0f01aae2d575f23acae4ac2dc6d21578c
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef RY_AREA_GEOMETRY_H
20 #define RY_AREA_GEOMETRY_H
24 template<class T>
25 struct CAreaCoords
27 CAreaCoords(){}
28 CAreaCoords(T x, T y)
29 :X(x),Y(y){}
30 T X;
31 T Y;
34 CAreaCoords<T> &operator*=(float scalar)
36 X = T ( scalar * X);
37 Y = T ( scalar * Y);
38 return *this;
43 template<class T>
44 class CAreaQuad
46 public:
47 bool contains( CAreaCoords<T> point )const
49 uint32 nNbIntersection = 0;
50 for (uint i = 0; i < 4; ++i)
52 const CAreaCoords<T> &p1 = Vertices[i];
53 const CAreaCoords<T> &p2 = Vertices[(i+1)%4];
55 if ( p1.Y - point.Y < T(0) && p2.Y-point.Y < T(0) )
56 continue;
57 if ( p1.Y-point.Y > T(0) && p2.Y-point.Y > T(0) )
58 continue;
59 T xinter = (sint32)( p1.X + (p2.X-p1.X) * ( double(point.Y - p1.Y) / double( p2.Y - p1.Y ) ) );
60 if (xinter > point.X)
61 ++nNbIntersection;
63 if ((nNbIntersection&1) == 1) // odd intersections so the vertex is inside
64 return true;
65 else
66 return false;
68 CAreaCoords<T> Vertices [4];
71 template<class T>
72 class CAreaRect
74 public:
75 ///from a quad : build the bounding rect
76 CAreaRect<T>( const CAreaQuad<T> & quad )
78 Point.X = quad.Vertices[0].X;
79 Point.Y = quad.Vertices[0].Y;
80 CAreaCoords<T> topRight(quad.Vertices[0].X,quad.Vertices[0].Y);
82 for ( uint i = 1; i < 3; i++ )
84 if ( Point.X > quad.Vertices[i].X )
85 Point.X = quad.Vertices[i].X;
86 else if ( topRight.X < quad.Vertices[i].X )
87 topRight.X = quad.Vertices[i].X;
89 if ( Point.Y > quad.Vertices[i].Y )
90 Point.Y = quad.Vertices[i].Y;
91 else if ( topRight.Y < quad.Vertices[i].Y )
92 topRight.Y = quad.Vertices[i].Y;
94 Width = topRight.X - Point.X;
95 Height = topRight.Y - Point.Y;
98 CAreaCoords<T> center()
100 return CAreaCoords<T> ( Point.X + Width / 2, Point.Y + Height / 2 );
103 /// bottom left point
104 CAreaCoords<T> Point;
105 ///width
106 T Width;
107 T Height;
112 #endif // RY_AREA_GEOMETRY_H
114 /* End of area_geometry.h */