1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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
34 CAreaCoords
<T
> &operator*=(float scalar
)
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) )
57 if ( p1
.Y
-point
.Y
> T(0) && p2
.Y
-point
.Y
> T(0) )
59 T xinter
= (sint32
)( p1
.X
+ (p2
.X
-p1
.X
) * ( double(point
.Y
- p1
.Y
) / double( p2
.Y
- p1
.Y
) ) );
63 if ((nNbIntersection
&1) == 1) // odd intersections so the vertex is inside
68 CAreaCoords
<T
> Vertices
[4];
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
;
112 #endif // RY_AREA_GEOMETRY_H
114 /* End of area_geometry.h */