Skip to content

Commit

Permalink
Add unique ids to base objects in Node, use them to differentiate nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aksem committed Mar 9, 2024
1 parent 1b4a236 commit 4a71c18
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 23 deletions.
1 change: 1 addition & 0 deletions cola/libavoid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ add_library(${PROJECT_NAME}
viscluster.cpp
visibility.cpp
vpsc.cpp
uniqueid.cpp
)

if (LIBAVOID_DEBUG)
Expand Down
9 changes: 8 additions & 1 deletion cola/libavoid/obstacle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "libavoid/router.h"
#include "libavoid/connectionpin.h"
#include "libavoid/debug.h"
#include "uniqueid.h"

namespace Avoid {

Expand All @@ -36,7 +37,8 @@ Obstacle::Obstacle(Router *router, Polygon ply, const unsigned int id)
m_polygon(ply),
m_active(false),
m_first_vert(nullptr),
m_last_vert(nullptr)
m_last_vert(nullptr),
m_unique_id(getNewUniqueId())
{
COLA_ASSERT(m_router != nullptr);
m_id = m_router->assignId(id);
Expand Down Expand Up @@ -350,6 +352,11 @@ ConnRefList Obstacle::attachedConnectors(void) const
return attachedConns;
}

unsigned int Obstacle::getUniqueId(void) const
{
return m_unique_id;
}

}


2 changes: 2 additions & 0 deletions cola/libavoid/obstacle.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Obstacle
//! @brief Returns the position of this obstacle.
//! @returns A point representing the position of this obstacle.
virtual Point position(void) const = 0;
unsigned int getUniqueId(void) const;

void setNewPoly(const Polygon& poly);
VertInf *firstVert(void);
Expand Down Expand Up @@ -132,6 +133,7 @@ class Obstacle
protected:
Router *m_router;
unsigned int m_id;
const unsigned int m_unique_id;
Polygon m_polygon;
bool m_active;
ObstacleList::iterator m_router_obstacles_pos;
Expand Down
4 changes: 2 additions & 2 deletions cola/libavoid/orthogonal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1568,8 +1568,8 @@ static void processEventHori(Router *router, NodeSet& scanline,
if (it != scanline.begin())
{
Node *u = *(--it);
v->firstAbove = u;
u->firstBelow = v;
v->firstAbove = u;
u->firstBelow = v;
}
it = v->iter;
if (++it != scanline.end())
Expand Down
1 change: 1 addition & 0 deletions cola/libavoid/router.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ class AVOID_EXPORT Router {
bool SelectiveReroute;

bool PartialFeedback;
// rubber band routing works currently only in polyline mode
bool RubberBandRouting;


Expand Down
12 changes: 5 additions & 7 deletions cola/libavoid/scanline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ bool CmpNodePos::operator() (const Node* u, const Node* v) const
{
return u->pos < v->pos;
}

// Use the pointers to the base objects to differentiate them.
void *up = (u->v) ? (void *) u->v :
((u->c) ? (void *) u->c : (void *) u->ss);
void *vp = (v->v) ? (void *) v->v :
((v->c) ? (void *) v->c : (void *) v->ss);
return up < vp;

// use unique ids of base objects to differentiate nodes
unsigned int uId = u->v ? u->v->getUniqueId() : ((u->c) ? u->c->uniqueId : u->ss->uniqueId);
unsigned int vId = v->v ? v->v->getUniqueId() : (v->c ? v->c->uniqueId : v->ss->uniqueId);
return uId < vId;
}


Expand Down
4 changes: 3 additions & 1 deletion cola/libavoid/scanline.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <list>

#include "libavoid/geomtypes.h"
#include "uniqueid.h"


namespace Avoid {
Expand All @@ -45,7 +46,7 @@ class ShiftSegment
{
public:
ShiftSegment(const size_t dim)
: dimension(dim)
: dimension(dim), uniqueId(getNewUniqueId())
{
}
virtual ~ShiftSegment()
Expand All @@ -62,6 +63,7 @@ class ShiftSegment
size_t dimension;
double minSpaceLimit;
double maxSpaceLimit;
const unsigned int uniqueId;
};
typedef std::list<ShiftSegment *> ShiftSegmentList;

Expand Down
14 changes: 7 additions & 7 deletions cola/libavoid/tests/new/orthogonal/hierarchical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class HierarchicalOrthogonalRouter : public ::testing::Test {
new ShapeConnectionPin(childShape, connectionId2, 200, 56, false, 0, ConnDirRight);
}
new ShapeConnectionPin(childShape, CONNECTIONPIN_CENTRE,
ATTACH_POS_CENTRE, ATTACH_POS_CENTRE, true, 0.0, ConnDirNone);
ATTACH_POS_CENTRE, ATTACH_POS_CENTRE, true, 0.0, ConnDirAll);
return childShape;
}

Expand Down Expand Up @@ -106,13 +106,13 @@ TEST_F(HierarchicalOrthogonalRouter, TwoChildrenVerticallyAllWithPins) {
router->processTransaction();
router->outputDiagramSVG(IMAGE_OUTPUT_PATH "output/HierarchicalOrthogonalRouter_TwoChildrenVerticallyAllWithPins");

std::vector<Point> expectedBottomToTop = { {850, 514}, {854, 514}, {854, 350}, {850, 350} };
std::vector<Point> expectedBottomToTop = { {650, 514}, {646, 514}, {646, 350}, {650, 350} };
EXPECT_THAT(bottomToTopConn, IsEqualToRoute(expectedBottomToTop));
std::vector<Point> expectedBottomToTop2 = { {650, 556}, {646, 556}, {646, 350}, {650, 350} };
std::vector<Point> expectedBottomToTop2 = { {850, 556}, {854, 556}, {854, 350}, {850, 350} };
EXPECT_THAT(bottomToTopConn2, IsEqualToRoute(expectedBottomToTop2));
std::vector<Point> expectedTopToBottom = { {850, 214}, {858, 214}, {858, 650}, {850, 650} };
std::vector<Point> expectedTopToBottom = { {650, 214}, {642, 214}, {642, 650}, {650, 650} };
EXPECT_THAT(topToBottomConn, IsEqualToRoute(expectedTopToBottom));
std::vector<Point> expectedTopToBottom2 = { {650, 256}, {642, 256}, {642, 650}, {650, 650} };
std::vector<Point> expectedTopToBottom2 = { {850, 256}, {858, 256}, {858, 650}, {850, 650} };
EXPECT_THAT(topToBottomConn2, IsEqualToRoute(expectedTopToBottom2));
}

Expand All @@ -130,9 +130,9 @@ TEST_F(HierarchicalOrthogonalRouter, ThreeChildrenVertically) {
router->processTransaction();
router->outputDiagramSVG(IMAGE_OUTPUT_PATH "output/HierarchicalOrthogonalRouter_ThreeChildrenVertically");

std::vector<Point> expectedBottomToTop = { {800, 614}, {804, 614}, {804, 400}, {700, 400} };
std::vector<Point> expectedBottomToTop = { {600, 614}, {596, 614}, {596, 400}, {700, 400} };
EXPECT_THAT(bottomToTopConn, IsEqualToRoute(expectedBottomToTop));
std::vector<Point> expectedTopToBottom = { {800, 314}, {808, 314}, {808, 700}, {700, 700} };
std::vector<Point> expectedTopToBottom = { {800, 314}, {804, 314}, {804, 700}, {700, 700} };
EXPECT_THAT(topToBottomConn, IsEqualToRoute(expectedTopToBottom));
std::vector<Point> expectedLeftToTop = { {300, 407}, {700, 407} };
EXPECT_THAT(leftToTopConn, IsEqualToRoute(expectedLeftToTop));
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions cola/libavoid/uniqueid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Created by user on 09.03.24.
//

#include "uniqueid.h"

unsigned int getNewUniqueId() {
if (counter == (std::numeric_limits<unsigned int>::max() - 1)) {
// avoid overflow
counter = 0;
}
counter += 1;
return counter;
}
11 changes: 11 additions & 0 deletions cola/libavoid/uniqueid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef ADAPTAGRAMS_UNIQUEID_H
#define ADAPTAGRAMS_UNIQUEID_H

#include <cstdint>
#include <limits>

static unsigned int counter = 0;

unsigned int getNewUniqueId();

#endif //ADAPTAGRAMS_UNIQUEID_H
4 changes: 3 additions & 1 deletion cola/libavoid/vertices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "libavoid/router.h"
#include "libavoid/assertions.h"
#include "libavoid/connend.h"
#include "uniqueid.h"

using std::ostream;

Expand Down Expand Up @@ -169,7 +170,8 @@ VertInf::VertInf(Router *router, const VertID& vid, const Point& vpoint,
m_orthogonalPartner(nullptr),
m_treeRoot(nullptr),
visDirections(ConnDirNone),
orthogVisPropFlags(0)
orthogVisPropFlags(0),
uniqueId(getNewUniqueId())
{
point.id = vid.objID;
point.vn = vid.vn;
Expand Down
1 change: 1 addition & 0 deletions cola/libavoid/vertices.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class VertInf
EdgeInfList invisList;
unsigned int invisListSize;
VertInf *pathNext;
const unsigned int uniqueId;

// The tree root and distance value used when computing MTSTs.
// XXX: Maybe these should be allocated as a separate struct
Expand Down

0 comments on commit 4a71c18

Please sign in to comment.