1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*! \file src/lpoint.cpp
\brief Definition of GDSII kbLPoint type structure
\author Klaas Holwerda
Copyright: 2001-2004 (C) Klaas Holwerda
Licence: see kboollicense.txt
RCS-ID: $Id: lpoint.cpp,v 1.4 2009/09/10 17:04:09 titato Exp $
*/
#include "kbool/lpoint.h"
#include <math.h>
// Constructors
kbLPoint::kbLPoint()
{
_x = 0;
_y = 0;
}
kbLPoint::kbLPoint( B_INT const X, B_INT const Y )
{
_x = X;
_y = Y;
}
kbLPoint::kbLPoint( kbLPoint* const a_point )
{
if ( !a_point )
throw Bool_Engine_Error( "Cannot copy a NULL Point Object.\n\nCould not create a kbLPoint Object.",
"Fatal Creation Error", 0, 1 );
_x = a_point->_x;
_y = a_point->_y;
}
B_INT kbLPoint::GetX()
{
return _x;
}
B_INT kbLPoint::GetY()
{
return _y;
}
void kbLPoint::SetX( B_INT a_point_x )
{
_x = a_point_x;
}
void kbLPoint::SetY( B_INT a_point_y )
{
_y = a_point_y;
}
kbLPoint kbLPoint::GetPoint()
{
return * this;
}
void kbLPoint::Set( const B_INT X, const B_INT Y )
{
_x = X;
_y = Y;
}
void kbLPoint::Set( const kbLPoint &a_point )
{
_x = a_point._x;
_y = a_point._y;
}
bool kbLPoint::Equal( const kbLPoint a_point, B_INT Marge )
{
B_INT delta_x, delta_y;
delta_x = babs( ( _x - a_point._x ) );
delta_y = babs( ( _y - a_point._y ) );
if ( ( delta_x <= Marge ) && ( delta_y <= Marge ) )
return true;
else
return false;
}
bool kbLPoint::Equal( const B_INT X, const B_INT Y, B_INT Marge )
{
return ( bool )( ( babs( _x - X ) <= Marge ) && ( babs( _y - Y ) <= Marge ) );
}
bool kbLPoint::ShorterThan( const kbLPoint a_point, B_INT Marge )
{
double a, b;
a = ( double ) ( a_point._x - _x );
a *= a;
b = ( double ) ( a_point._y - _y );
b *= b;
return ( bool ) ( ( a + b ) <= Marge * Marge ? true : false ) ;
}
bool kbLPoint::ShorterThan( const B_INT X, const B_INT Y, B_INT Marge )
{
double a, b;
a = ( double ) ( X - _x );
a *= a;
b = ( double ) ( Y - _y );
b *= b;
return ( bool ) ( a + b <= Marge * Marge ? true : false ) ;
}
// overload the assign (=) operator
// usage : a_point = another_point;
kbLPoint &kbLPoint::operator=( const kbLPoint &other_point )
{
_x = other_point._x;
_y = other_point._y;
return *this;
}
// overload the + operator
// usage : a_point = point1 + point2;
kbLPoint &kbLPoint::operator+( const kbLPoint &other_point )
{
_x += other_point._x;
_y += other_point._y;
return *this;
}
// overload the - operator
// usage : a_point = point1 - point2;
kbLPoint &kbLPoint::operator-( const kbLPoint &other_point )
{
_x -= other_point._x;
_y -= other_point._y;
return *this;
}
// overload the * operator
// usage: a_point = point1 * 100;
kbLPoint &kbLPoint::operator*( int factor )
{
_x *= factor;
_y *= factor;
return *this;
}
// overload the / operator
// usage: a_point = point1 / 100;
kbLPoint &kbLPoint::operator/( int factor )
{
_x /= factor;
_y /= factor;
return *this;
}
// overload the compare (==) operator
// usage: if (point1 == point2) { };
int kbLPoint::operator==( const kbLPoint &other_point ) const
{
return ( ( other_point._x == _x ) && ( other_point._y == _y ) );
}
// overload the diffrent (!=) operator
// usage: if (point1 != point2) { };
int kbLPoint::operator!=( const kbLPoint &other_point ) const
{
return ( ( other_point._x != _x ) || ( other_point._y != _y ) );
}