1 /* ResidualVM - A 3D game interpreter
2 *
3 * ResidualVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the AUTHORS
5 * file distributed with this source distribution.
6 *
7 * Additional copyright for this file:
8 * Copyright (C) 1999-2000 Revolution Software Ltd.
9 * This code is based on source code created by Revolution Software,
10 * used with permission.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 *
26 */
27
28 #ifndef ICB_PX2DLINE_H_INCLUDED
29 #define ICB_PX2DLINE_H_INCLUDED
30
31 #include "engines/icb/common/px_array.h"
32 #include "engines/icb/common/px_2drealpoint.h"
33
34 namespace ICB {
35
36 // Note, this header file needs somethings :
37 // e.g. PXreal, REAL_ZERO
38 #ifndef REAL_ZERO
39 #error "REAL_ZERO not defined in px2drealline.h"
40 #endif // #ifndef REAL_ZERO
41
42 // Here I define an array type for the class. This neatens syntax and also allows pxArrays of pxArrays to be declared.
43 class px2DRealLine;
44 typedef rcActArray<px2DRealLine> px2DRealLineArray;
45
46 // Holds a line on a plane as a pair of integer endpoints, and provides functions for working with them.
47 class px2DRealLine {
48 public:
49 // Definitions for this class.
50 enum IntersectionLogicVal { DONT_INTERSECT, DO_INTERSECT, COLLINEAR };
51
52 // Default constructor and destructor.
px2DRealLine()53 inline px2DRealLine() {
54 m_fX1 = REAL_ZERO;
55 m_fY1 = REAL_ZERO;
56 m_fX2 = REAL_ZERO;
57 m_fY2 = REAL_ZERO;
58 }
~px2DRealLine()59 inline ~px2DRealLine() { ; }
60
61 // Gets and sets.
GetX1()62 PXreal GetX1() const { return m_fX1; }
GetY1()63 PXreal GetY1() const { return m_fY1; }
GetX2()64 PXreal GetX2() const { return m_fX2; }
GetY2()65 PXreal GetY2() const { return m_fY2; }
66
SetX1(PXreal fX1)67 void SetX1(PXreal fX1) { m_fX1 = fX1; }
SetY1(PXreal fY1)68 void SetY1(PXreal fY1) { m_fY1 = fY1; }
SetX2(PXreal fX2)69 void SetX2(PXreal fX2) { m_fX2 = fX2; }
SetY2(PXreal fY2)70 void SetY2(PXreal fY2) { m_fY2 = fY2; }
71
72 // This determines whether this-> line intersects another.
73 IntersectionLogicVal Intersects(const px2DRealLine &oLineB, px2DRealPoint &oIntersection) const;
74
75 private:
76 PXreal m_fX1, m_fY1, m_fX2, m_fY2; // The line's endpoints.
77
78 // Functions used only by this class.
79 inline bool8 SameSigns(PXreal dA, PXreal dB) const;
80 };
81
SameSigns(PXreal fA,PXreal fB)82 inline bool8 px2DRealLine::SameSigns(PXreal fA, PXreal fB) const {
83 if (fA < REAL_ZERO) {
84 if (fB < REAL_ZERO)
85 return TRUE8;
86 else
87 return FALSE8;
88 } else {
89 if (fB < REAL_ZERO)
90 return FALSE8;
91 else
92 return TRUE8;
93 }
94 }
95
96 } // End of namespace ICB
97
98 #endif // #ifndef PX2DLINE_H_INCLUDED
99