Skip to content

Commit

Permalink
FIXED possible divisions by zero
Browse files Browse the repository at this point in the history
ADDED offset to node when dragged on top of another node
  • Loading branch information
ksterker committed Aug 3, 2010
1 parent aac109e commit ed41a92
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
14 changes: 5 additions & 9 deletions src/dlgedit/dlg_arrow.cc
Expand Up @@ -107,11 +107,6 @@ void DlgArrow::initShape ()
// calculate intersection of arrow and node shape
DlgPoint DlgArrow::getIntersection (DlgPoint &start, DlgPoint &end, DlgRect &shape)
{
if (start == end)
{
end.move (0, 40);
}

DlgPoint tl = shape.topLeft ();
DlgPoint br = shape.bottomRight ();

Expand All @@ -125,6 +120,7 @@ DlgPoint DlgArrow::getIntersection (DlgPoint &start, DlgPoint &end, DlgRect &sha

// tangens of angle between line(start, end) and x-axis
double m = x == 0 ? 1.0 : double (y) / x;
double n = y == 0 ? 1.0 : double (x) / y;

// direction where line(start, end) intersects with border of start
enum { NORTH, EAST, SOUTH, WEST };
Expand Down Expand Up @@ -179,22 +175,22 @@ DlgPoint DlgArrow::getIntersection (DlgPoint &start, DlgPoint &end, DlgRect &sha
{
case NORTH:
{
p = DlgPoint ((tl.y () - start.y ()) * x / y + start.x (), tl.y ());
p = DlgPoint ((tl.y () - start.y ()) * n + start.x (), tl.y ());
break;
}
case EAST:
{
p = DlgPoint (br.x (), start.y () + y / x * (br.x () - start.x ()));
p = DlgPoint (br.x (), start.y () + m * (br.x () - start.x ()));
break;
}
case SOUTH:
{
p = DlgPoint ((br.y () - start.y ()) * x / y + start.x (), br.y ());
p = DlgPoint ((br.y () - start.y ()) * n + start.x (), br.y ());
break;
}
case WEST:
{
p = DlgPoint (tl.x (), start.y () + y / x * (tl.x () - start.x ()));
p = DlgPoint (tl.x (), start.y () + m * (tl.x () - start.x ()));
break;
}
}
Expand Down
22 changes: 15 additions & 7 deletions src/dlgedit/gui_graph.cc
Expand Up @@ -177,7 +177,6 @@ bool GuiGraph::newArrow (DlgPoint &point)
// sanity checks
if (!start || start->type () == LINK) return false;
if (end && end->type () == LINK) return false;
if (start == end || ((DlgCircle *) start)->hasChild (end)) return false;

// if no end selected, create a new circle first
if (end == NULL)
Expand All @@ -202,6 +201,9 @@ bool GuiGraph::newArrow (DlgPoint &point)
if (end == NULL) return false;
}

// no loops and no bidirectional connections
if (start == end || ((DlgCircle *) start)->hasChild (end)) return false;

// no connection between start and end if both are PLAYER nodes
if (start->type () == PLAYER && end->type () == PLAYER) return false;

Expand Down Expand Up @@ -686,10 +688,17 @@ void GuiGraph::stopDragging (DlgPoint &point)
// if circle moved, realign it to the grid
else
{
mover->setPos (
DlgPoint (point.x () - (point.x () % CIRCLE_DIAMETER),
point.y () - (point.y () % CIRCLE_DIAMETER)));

// make sure we drop on an empty location
DlgNode *node = module->getNode (point);
while (node != NULL)
{
point.move (0, 2*CIRCLE_DIAMETER);
node = module->getNode (point);
}

mover->setPos (DlgPoint (point.x () - (point.x () % CIRCLE_DIAMETER),
point.y () - (point.y () % CIRCLE_DIAMETER)));

// also need to update arrows and reorder children and parents
for (DlgNode *a = mover->prev (FIRST); a != NULL; a = mover->prev (NEXT))
{
Expand All @@ -704,8 +713,7 @@ void GuiGraph::stopDragging (DlgPoint &point)
a->next (FIRST)->addPrev (a);
((DlgArrow *) a)->initShape ();
}
}

}
// update everything
if (mover->type() == MODULE)
deselectNode ();
Expand Down

0 comments on commit ed41a92

Please sign in to comment.