2
2
* vim: ts=4 sw=4 et tw=0 wm=0
4
4
* libavoid - Fast, Incremental, Object-avoiding Line Router
5
* Copyright (C) 2004-2006 Michael Wybrow <mjwybrow@users.sourceforge.net>
6
* Copyright (C) 2004-2009 Monash University
7
8
* This library is free software; you can redistribute it and/or
8
9
* modify it under the terms of the GNU Lesser General Public
9
10
* License as published by the Free Software Foundation; either
10
11
* version 2.1 of the License, or (at your option) any later version.
12
* See the file LICENSE.LGPL distributed with the library.
14
* Licensees holding a valid commercial license may use this file in
15
* accordance with the commercial license agreement provided with the
12
18
* This library is distributed in the hope that it will be useful,
13
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22
* Author(s): Michael Wybrow <mjwybrow@users.sourceforge.net>
23
29
#include "libavoid/vertices.h"
24
30
#include "libavoid/geometry.h"
25
31
#include "libavoid/graph.h" // For alertConns
26
32
#include "libavoid/debug.h"
27
33
#include "libavoid/router.h"
34
#include "libavoid/assertions.h"
33
36
using std::ostream;
136
const int VertID::src = 1;
137
const int VertID::tar = 2;
140
const unsigned short VertID::src = 1;
141
const unsigned short VertID::tar = 2;
140
144
ostream& operator<<(ostream& os, const VertID& vID)
147
VertInf::VertInf(Router *router, const VertID& vid, const Point& vpoint)
151
VertInf::VertInf(Router *router, const VertID& vid, const Point& vpoint,
152
const bool addToRouter)
161
orthogVisListSize(0),
164
visDirections(ConnDirNone)
166
point.id = vid.objID;
171
_router->vertices.addVertex(this);
181
void VertInf::Reset(const VertID& vid, const Point& vpoint)
163
190
void VertInf::Reset(const Point& vpoint)
198
// Returns true if this vertex is not involved in any (in)visibility graphs.
199
bool VertInf::orphaned(void)
201
return (visList.empty() && invisList.empty() && orthogVisList.empty());
173
assert(!(id.isShape));
209
COLA_ASSERT(!(id.isShape));
178
212
// For each vertex.
179
EdgeInfList& visList = tmp->visList;
180
EdgeInfList::iterator finish = visList.end();
181
EdgeInfList::iterator edge;
213
EdgeInfList::const_iterator finish = visList.end();
214
EdgeInfList::const_iterator edge;
182
215
while ((edge = visList.begin()) != finish)
184
217
// Remove each visibility edge
189
EdgeInfList& invisList = tmp->invisList;
222
finish = orthogVisList.end();
223
while ((edge = orthogVisList.begin()) != finish)
225
// Remove each orthogonal visibility edge.
226
(*edge)->alertConns();
190
230
finish = invisList.end();
191
231
while ((edge = invisList.begin()) != finish)
209
249
// We better be part of the same instance of libavoid.
210
250
Router *router = src->_router;
211
assert(router == dst->_router);
251
COLA_ASSERT(router == dst->_router);
213
253
ContainsMap& contains = router->contains;
214
254
if (!(pID.isShape))
241
281
VertInfList::VertInfList()
242
: _firstShapeVert(NULL)
243
, _firstConnVert(NULL)
244
, _lastShapeVert(NULL)
245
, _lastConnVert(NULL)
282
: _firstShapeVert(NULL),
283
_firstConnVert(NULL),
284
_lastShapeVert(NULL),
252
292
#define checkVertInfListConditions() \
254
assert((!_firstConnVert && (_connVertices == 0)) || \
294
COLA_ASSERT((!_firstConnVert && (_connVertices == 0)) || \
255
295
((_firstConnVert->lstPrev == NULL) && (_connVertices > 0))); \
256
assert((!_firstShapeVert && (_shapeVertices == 0)) || \
296
COLA_ASSERT((!_firstShapeVert && (_shapeVertices == 0)) || \
257
297
((_firstShapeVert->lstPrev == NULL) && (_shapeVertices > 0))); \
258
assert(!_lastShapeVert || (_lastShapeVert->lstNext == NULL)); \
259
assert(!_lastConnVert || (_lastConnVert->lstNext == _firstShapeVert)); \
260
assert((!_firstConnVert && !_lastConnVert) || \
298
COLA_ASSERT(!_lastShapeVert || (_lastShapeVert->lstNext == NULL)); \
299
COLA_ASSERT(!_lastConnVert || (_lastConnVert->lstNext == _firstShapeVert)); \
300
COLA_ASSERT((!_firstConnVert && !_lastConnVert) || \
261
301
(_firstConnVert && _lastConnVert) ); \
262
assert((!_firstShapeVert && !_lastShapeVert) || \
302
COLA_ASSERT((!_firstShapeVert && !_lastShapeVert) || \
263
303
(_firstShapeVert && _lastShapeVert) ); \
264
assert(!_firstShapeVert || _firstShapeVert->id.isShape); \
265
assert(!_lastShapeVert || _lastShapeVert->id.isShape); \
266
assert(!_firstConnVert || !(_firstConnVert->id.isShape)); \
267
assert(!_lastConnVert || !(_lastConnVert->id.isShape)); \
304
COLA_ASSERT(!_firstShapeVert || _firstShapeVert->id.isShape); \
305
COLA_ASSERT(!_lastShapeVert || _lastShapeVert->id.isShape); \
306
COLA_ASSERT(!_firstConnVert || !(_firstConnVert->id.isShape)); \
307
COLA_ASSERT(!_lastConnVert || !(_lastConnVert->id.isShape)); \
271
311
void VertInfList::addVertex(VertInf *vert)
273
313
checkVertInfListConditions();
274
assert(vert->lstPrev == NULL);
275
assert(vert->lstNext == NULL);
314
COLA_ASSERT(vert->lstPrev == NULL);
315
COLA_ASSERT(vert->lstNext == NULL);
277
317
if (!(vert->id.isShape))
332
void VertInfList::removeVertex(VertInf *vert)
372
// Removes a vertex from the list and returns a pointer to the vertex
373
// following the removed one.
374
VertInf *VertInfList::removeVertex(VertInf *vert)
334
380
// Conditions for correct data structure
335
381
checkVertInfListConditions();
383
VertInf *following = vert->lstNext;
337
385
if (!(vert->id.isShape))
421
469
vert->lstNext = NULL;
423
471
checkVertInfListConditions();
477
VertInf *VertInfList::getVertexByID(const VertID& id)
479
VertID searchID = id;
480
if (searchID.vn == kUnassignedVertexNumber)
482
unsigned int topbit = ((unsigned int) 1) << 31;
483
if (searchID.objID & topbit)
485
searchID.objID = searchID.objID & ~topbit;
486
searchID.vn = VertID::src;
490
searchID.vn = VertID::tar;
493
VertInf *last = end();
494
for (VertInf *curr = connsBegin(); curr != last; curr = curr->lstNext)
496
if (curr->id == searchID)
505
VertInf *VertInfList::getVertexByPos(const Point& p)
507
VertInf *last = end();
508
for (VertInf *curr = shapesBegin(); curr != last; curr = curr->lstNext)
510
if (curr->point == p)