ScummVM API documentation
px_2drealline.h
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  * 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 modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (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, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef ICB_PX2DLINE_H_INCLUDED
28 #define ICB_PX2DLINE_H_INCLUDED
29 
30 #include "engines/icb/common/px_array.h"
31 #include "engines/icb/common/px_2drealpoint.h"
32 
33 namespace ICB {
34 
35 // Note, this header file needs somethings :
36 // e.g. PXreal, REAL_ZERO
37 #ifndef REAL_ZERO
38 #error "REAL_ZERO not defined in px2drealline.h"
39 #endif // #ifndef REAL_ZERO
40 
41 // Here I define an array type for the class. This neatens syntax and also allows pxArrays of pxArrays to be declared.
42 class px2DRealLine;
43 typedef rcActArray<px2DRealLine> px2DRealLineArray;
44 
45 // Holds a line on a plane as a pair of integer endpoints, and provides functions for working with them.
46 class px2DRealLine {
47 public:
48  // Definitions for this class.
49  enum IntersectionLogicVal { DONT_INTERSECT, DO_INTERSECT, COLLINEAR };
50 
51  // Default constructor and destructor.
52  inline px2DRealLine() {
53  m_fX1 = REAL_ZERO;
54  m_fY1 = REAL_ZERO;
55  m_fX2 = REAL_ZERO;
56  m_fY2 = REAL_ZERO;
57  }
58  inline ~px2DRealLine() { ; }
59 
60  // Gets and sets.
61  PXreal GetX1() const { return m_fX1; }
62  PXreal GetY1() const { return m_fY1; }
63  PXreal GetX2() const { return m_fX2; }
64  PXreal GetY2() const { return m_fY2; }
65 
66  void SetX1(PXreal fX1) { m_fX1 = fX1; }
67  void SetY1(PXreal fY1) { m_fY1 = fY1; }
68  void SetX2(PXreal fX2) { m_fX2 = fX2; }
69  void SetY2(PXreal fY2) { m_fY2 = fY2; }
70 
71  // This determines whether this-> line intersects another.
72  IntersectionLogicVal Intersects(const px2DRealLine &oLineB, px2DRealPoint &oIntersection) const;
73 
74 private:
75  PXreal m_fX1, m_fY1, m_fX2, m_fY2; // The line's endpoints.
76 
77  // Functions used only by this class.
78  inline bool8 SameSigns(PXreal dA, PXreal dB) const;
79 };
80 
81 inline bool8 px2DRealLine::SameSigns(PXreal fA, PXreal fB) const {
82  if (fA < REAL_ZERO) {
83  if (fB < REAL_ZERO)
84  return TRUE8;
85  else
86  return FALSE8;
87  } else {
88  if (fB < REAL_ZERO)
89  return FALSE8;
90  else
91  return TRUE8;
92  }
93 }
94 
95 } // End of namespace ICB
96 
97 #endif // #ifndef PX2DLINE_H_INCLUDED
Definition: px_2drealline.h:46
Definition: actor.h:32
Definition: px_2drealpoint.h:36