/*
* vim: ts=4 sw=4 et tw=0 wm=0
*
* libavoid - Fast, Incremental, Object-avoiding Line Router
*
* Copyright (C) 2004-2009 Monash University
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* See the file LICENSE.LGPL distributed with the library.
*
* Licensees holding a valid commercial license may use this file in
* accordance with the commercial license agreement provided with the
* library.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* Author(s): Michael Wybrow <mjwybrow@users.sourceforge.net>
*/
#include <cmath>
#include "libavoid/connector.h"
#include "libavoid/geometry.h"
#include "libavoid/vertices.h"
#include "libavoid/assertions.h"
namespace Avoid {
_blocker(0),
_added(false),
_visible(false),
_dist(-1)
{
// Not passed NULL values.
// We are in the same instance
}
{
if (_added)
{
makeInactive();
}
}
// Gives an order value between 0 and 3 for the point c, given the last
// segment was from a to b. Returns the following value:
// 0 : Point c is directly backwards from point b.
// 1 : Point c is a left-hand 90 degree turn.
// 2 : Point c is a right-hand 90 degree turn.
// 3 : Point c is straight ahead (collinear).
//
const Point& c)
{
// We should only be calling this with orthogonal points,
COLA_ASSERT((c.x == b.x) || (c.y == b.y));
COLA_ASSERT((a.x == b.x) || (a.y == b.y));
if (direction > 0)
{
// Counterclockwise := left
return 1;
}
else if (direction < 0)
{
// Clockwise := right
return 2;
}
if (b.x == c.x)
{
if ( ((a.y < b.y) && (c.y < b.y)) ||
((a.y > b.y) && (c.y > b.y)) )
{
// Behind.
return 0;
}
}
else
{
if ( ((a.x < b.x) && (c.x < b.x)) ||
((a.x > b.x) && (c.x > b.x)) )
{
// Behind.
return 0;
}
}
// Ahead.
return 3;
}
// Returns a less than operation for a set exploration order for orthogonal
// searching. Forward, then left, then right. Or if there is no previous
// point, then the order is north, east, south, then west.
// Note: This method assumes the two Edges that share a common point.
{
{
// Effectively the same visibility edge, so they are equal.
return false;
}
// Determine common Point and the comparison point on the left- and
// the right-hand-side.
{
}
{
}
{
}
{
}
// If no lastPt, use one directly to the left;
}
{
COLA_ASSERT(_added == false);
if (_orthogonal)
{
_v1->orthogVisListSize++;
_v2->orthogVisListSize++;
}
else
{
if (_visible)
{
_v1->visListSize++;
_v2->visListSize++;
}
else // if (invisible)
{
_v1->invisListSize++;
_v2->invisListSize++;
}
}
_added = true;
}
{
COLA_ASSERT(_added == true);
if (_orthogonal)
{
_v1->orthogVisListSize--;
_v2->orthogVisListSize--;
}
else
{
if (_visible)
{
_v1->visListSize--;
_v2->visListSize--;
}
else // if (invisible)
{
_v1->invisListSize--;
_v2->invisListSize--;
}
}
_blocker = 0;
_added = false;
}
{
//COLA_ASSERT(dist != 0);
{
makeInactive();
}
if (!_added)
{
_visible = true;
makeActive();
}
_blocker = 0;
}
{
return _added;
}
{
{
*(*i) = true;
}
}
{
}
{
// Needs to be in invisibility graph.
addBlocker(-1);
}
{
{
makeInactive();
}
if (!_added)
{
_visible = false;
makeActive();
}
_dist = 0;
_blocker = b;
}
{
}
{
}
{
db_printf("Edge(");
db_printf(",");
db_printf(")\n");
}
{
{
db_printf("\tChecking visibility for existing invisibility edge..."
"\n\t\t");
db_print();
}
{
db_printf("\tChecking visibility for existing visibility edge..."
"\n\t\t");
db_print();
}
int blocker = 0;
bool cone1 = true;
bool cone2 = true;
{
}
else if (_router->IgnoreRegions == false)
{
// If Ignoring regions then this case is already caught by
// the invalid regions, so only check it when not ignoring
// regions.
{
db_printf("1: Edge of bounding shape\n");
// Don't even check this edge, it should be zero,
// since a point in a shape can't see it's corners
cone1 = false;
}
}
if (cone1)
{
// If outside the first cone, don't even bother checking.
{
}
else if (_router->IgnoreRegions == false)
{
// If Ignoring regions then this case is already caught by
// the invalid regions, so only check it when not ignoring
// regions.
{
db_printf("2: Edge of bounding shape\n");
// Don't even check this edge, it should be zero,
// since a point in a shape can't see it's corners
cone2 = false;
}
}
}
{
// if i and j see each other, add edge
db_printf("\tSetting visibility edge... \n\t\t");
db_print();
setDist(d);
}
else if (_router->InvisibilityGrph)
{
#if 0
#endif
// if i and j can't see each other, add blank edge
db_printf("\tSetting invisibility edge... \n\t\t");
db_print();
}
}
{
{
}
{
}
unsigned int lastId = 0;
bool seenIntersectionAtEndpoint = false;
{
if (k->id == dummyOrthogID)
{
// Don't include orthogonal dummy vertices.
k = k->lstNext;
continue;
}
{
{
db_printf("Endpoint is inside shape %u so ignore shape "
// One of the endpoints is inside this shape so ignore it.
{
// And skip the other vertices from this shape.
k = k->lstNext;
}
continue;
}
seenIntersectionAtEndpoint = false;
}
{
}
k = k->lstNext;
}
return 0;
}
{
{
return true;
}
return false;
}
// Returns true if this edge is a vertical or horizontal line segment.
{
}
{
{
return _v2;
}
return _v1;
}
{
// This is for polyline routing, so check we're not
// considering orthogonal vertices.
if (knownNew)
{
}
else
{
edge = existingEdge(i, j);
{
}
}
{
delete edge;
}
return edge;
}
// XXX: This function is ineffecient, and shouldn't even really be
// required.
{
// Look through poly-line visibility edges.
++edge)
{
{
return (*edge);
}
}
// Look through orthogonal visbility edges.
{
{
return (*edge);
}
}
// Look through poly-line invisbility edges.
++edge)
{
{
return (*edge);
}
}
return NULL;
}
//===========================================================================
_count(0)
{
}
{
clear();
}
{
while (_firstEdge)
{
delete _firstEdge;
}
COLA_ASSERT(_count == 0);
}
{
return _count;
}
{
if (_firstEdge == NULL)
{
_firstEdge = edge;
}
else
{
}
_count++;
}
{
{
}
{
}
{
if (edge == _firstEdge)
{
_firstEdge = NULL;
}
}
else if (edge == _firstEdge)
{
}
_count--;
}
{
return _firstEdge;
}
{
return NULL;
}
}