1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "common/scummsys.h"
24
25 #ifdef ENABLE_VKEYBD
26
27 #include "backends/vkeybd/polygon.h"
28
29 namespace Common {
30
contains(int16 x,int16 y) const31 bool Polygon::contains(int16 x, int16 y) const {
32 int yflag0;
33 int yflag1;
34 bool inside_flag = false;
35 unsigned int pt;
36
37 const Point *vtx0 = &_points[_points.size() - 1];
38 const Point *vtx1 = &_points[0];
39
40 yflag0 = (vtx0->y >= y);
41 for (pt = 0; pt < _points.size(); pt++, vtx1++) {
42 yflag1 = (vtx1->y >= y);
43 if (yflag0 != yflag1) {
44 if (((vtx1->y - y) * (vtx0->x - vtx1->x) >=
45 (vtx1->x - x) * (vtx0->y - vtx1->y)) == yflag1) {
46 inside_flag = !inside_flag;
47 }
48 }
49 yflag0 = yflag1;
50 vtx0 = vtx1;
51 }
52
53 return inside_flag;
54 }
55
56 } // End of namespace Common
57
58 #endif // #ifdef ENABLE_VKEYBD
59