TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
Endpoint.cpp
Go to the documentation of this file.
1/*
2 SOLID - Software Library for Interference Detection
3 Copyright (C) 1997-1998 Gino van den Bergen
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 Please send remarks, questions and bug reports to gino@win.tue.nl,
20 or write to:
21 Gino van den Bergen
22 Department of Mathematics and Computing Science
23 Eindhoven University of Technology
24 P.O. Box 513, 5600 MB Eindhoven, The Netherlands
25*/
26
27#ifdef _MSC_VER
28#pragma warning(disable:4786) // identifier was truncated to '255'
29#endif // _MSC_VER
30
31#include "Endpoint.h"
32#include "Object.h"
33#include "Encounter.h"
34
35#include <new>
36
37void addPair(ObjectPtr object1, ObjectPtr object2);
38void removePair(ObjectPtr object1, ObjectPtr object2);
39
41public:
44
46 head.succ = &tail;
47 head.pos = -INFINITY_;
48 tail.pred = &head;
49 tail.pos = INFINITY_;
50 }
51};
52
54
56 succ = p;
57 pred = p->pred;
58 succ->pred = this;
59 pred->succ = this;
60}
61
62inline bool operator<(const Endpoint& a, const Endpoint& b) {
63 return a.pos < b.pos || (a.pos == b.pos && a.side < b.side);
64}
65
66inline void update(const Endpoint& a, const Endpoint& b) {
67 if (a.side != b.side && a.objPtr != b.objPtr) {
68 if (a.side == MAX) {
69 if (intersect(a.objPtr->getBBox(), b.objPtr->getBBox()))
70 addPair(a.objPtr, b.objPtr);
71 }
72 else removePair(a.objPtr, b.objPtr);
73 }
74}
75
76Endpoint::Endpoint(int axis, Side s, const Object *obj) :
77 side(s),
78 objPtr(obj),
80{ insert(&endpointList[axis].tail); }
81
83 int sign = sgn(x - pos);
84 pos = x;
85 switch (sign) {
86 case -1:
87 if (*this < *pred) {
88 remove();
89 do update(*pred, *this);
90 while (*this < *(pred = pred->pred));
91 succ = pred->succ;
92 pred->succ = this;
93 succ->pred = this;
94 }
95 break;
96 case 1:
97 if (*succ < *this) {
98 remove();
99 do update(*this, *succ);
100 while (*(succ = succ->succ) < *this);
101 pred = succ->pred;
102 succ->pred = this;
103 pred->succ = this;
104 }
105 break;
106 }
107}
108
109
110
111
112
113
bool intersect(const BBox &a, const BBox &b)
Definition BBox.h:92
const Scalar INFINITY_
Definition Basic.h:41
int sgn(Scalar x)
Definition Basic.h:46
#define Scalar
Definition Basic.h:34
static Point p[4]
Definition Convex.cpp:54
const Object * ObjectPtr
Definition Encounter.h:37
void addPair(ObjectPtr object1, ObjectPtr object2)
Definition C-api.cpp:310
void update(const Endpoint &a, const Endpoint &b)
Definition Endpoint.cpp:66
static EndpointList endpointList[3]
Definition Endpoint.cpp:53
void removePair(ObjectPtr object1, ObjectPtr object2)
Definition C-api.cpp:314
bool operator<(const Endpoint &a, const Endpoint &b)
Definition Endpoint.cpp:62
int Side
Definition Endpoint.h:37
const T sign(const T &x)
Endpoint()
Definition Endpoint.h:49
Side side
Definition Endpoint.h:45
Endpoint * succ
Definition Endpoint.h:43
void move(Scalar x)
Definition Endpoint.cpp:82
void insert(Endpoint *p)
Definition Endpoint.cpp:55
Endpoint * pred
Definition Endpoint.h:44
void remove()
Definition Endpoint.h:57
const Object * objPtr
Definition Endpoint.h:46
Scalar pos
Definition Endpoint.h:47
Endpoint tail
Definition Endpoint.cpp:43
Endpoint head
Definition Endpoint.cpp:42
const BBox & getBBox() const
Definition Object.h:60
#define MAX(x, y)
Definition tgf.h:52