Connections

This is the meat of the connection method.

  • modules (m) are referred to as m1 and m2.
  • m1 is the sender, m2 is the receiver.
  • the delta’s are the midpoints between modules.
  • The coordinates of the corners of each module are held in an array (m1cord and m2cord).
  • Starting in the top left corner and going clockwise, the values of the array represent the x,y coordinates of the corners. For example, m1cord[0] is the x coordinate of of the top left corner of module 1 and m2cord[5] is the y coordinate of the bottom right corner of module 2.
  • ro[output] and li[input] are the y coords of the right output and left input.
  • The buffer is for when m2 is behind m1. If you move the blue module over to the left side, The buffer is the small distance that the connection comes out of the red and green before turning around.
switch(true)
{
case m2.x > m1cord[2]:
	_line.graphics.lineTo (deltaX, ro[output]);
	_line.graphics.lineTo (deltaX, li[input]);
	_line.graphics.lineTo ((m2.x), li[input]);
	break;
case m2.x <= m1cord[2] && m2cord[1] > m1cord[5]:
	_line.graphics.lineTo (m1.x + m1.width + buffer, ro[output]);
	_line.graphics.lineTo (m1.x + m1.width + buffer, ((m2.y - m1cord[5]) / 2) + m1cord[5]);
	_line.graphics.lineTo (m2.x -buffer, ((m2.y - m1cord[5]) / 2) + m1cord[5]);
	_line.graphics.lineTo (m2.x -buffer, li[input]);
	_line.graphics.lineTo (m2.x, li[input]);
	break;
case m2.x <= m1cord[2] && m2cord[5] < m1cord[1]:
	_line.graphics.lineTo (m1.x + m1.width + buffer, ro[output]);
	_line.graphics.lineTo (m1.x + m1.width + buffer, ((m1.y-m2cord[5])/2)+m2cord[5]);
	_line.graphics.lineTo (m2.x -buffer, ((m1.y-m2cord[5])/2)+m2cord[5]);
	_line.graphics.lineTo (m2.x -buffer, li[input]);
	_line.graphics.lineTo (m2.x, li[input]);
	break;
case m1.hitTestObject(m2):
	_line.graphics.lineTo(0, 0);
	break;
	default:
	trace("your mother");
}}
Posted in AS3

2 Replies to “Connections”

  1. Keeping one set of objects from collisions from other objects means evaluating the moved objects relative to all other objects. That’s not only tedious, but potentially slow. Perhaps there is any easy way (which I don’t know) to limit the object search to nearest neighbors. Each line segment might be considered an object. This could allow a segment to be selected and dragged to a new location, not just a module object.

  2. The code above is only interested in modules that are connected, not all modules. So for instance, the blue and green, and the red and gray don’t care about each other. NeatTools code only redraws the lines after you drop the module, and I don’t know how it draws it. I’d like for someone to explain it to me.
    Flash has a built in hitTestObject method for checking collision also, which I’m not doing anything with at the moment.
    I agree it’s a little tedious, but, for now, I’m just trying to duplicate the functionality. Next I will improve/optimize it.

Leave a Reply

Your email address will not be published. Required fields are marked *