in simulation/src/point-to-point-layout/model/point-to-point-dumbbell.cc [209:324]
void PointToPointDumbbellHelper::BoundingBox (double ulx, double uly, // Upper left x/y
double lrx, double lry) // Lower right x/y
{
double xDist;
double yDist;
if (lrx > ulx)
{
xDist = lrx - ulx;
}
else
{
xDist = ulx - lrx;
}
if (lry > uly)
{
yDist = lry - uly;
}
else
{
yDist = uly - lry;
}
double xAdder = xDist / 3.0;
double thetaL = M_PI / (LeftCount () + 1.0);
double thetaR = M_PI / (RightCount () + 1.0);
// Place the left router
Ptr<Node> lr = GetLeft ();
Ptr<ConstantPositionMobilityModel> loc = lr->GetObject<ConstantPositionMobilityModel> ();
if (loc == 0)
{
loc = CreateObject<ConstantPositionMobilityModel> ();
lr->AggregateObject (loc);
}
Vector lrl (ulx + xAdder, uly + yDist/2.0, 0);
loc->SetPosition (lrl);
// Place the right router
Ptr<Node> rr = GetRight ();
loc = rr->GetObject<ConstantPositionMobilityModel> ();
if (loc == 0)
{
loc = CreateObject<ConstantPositionMobilityModel> ();
rr->AggregateObject (loc);
}
Vector rrl (ulx + xAdder * 2, uly + yDist/2.0, 0); // Right router location
loc->SetPosition (rrl);
// Place the left leaf nodes
double theta = -M_PI_2 + thetaL;
for (uint32_t l = 0; l < LeftCount (); ++l)
{
// Make them in a circular pattern to make all line lengths the same
// Special case when theta = 0, to be sure we get a straight line
if ((LeftCount () % 2) == 1)
{ // Count is odd, see if we are in middle
if (l == (LeftCount () / 2))
{
theta = 0.0;
}
}
Ptr<Node> ln = GetLeft (l);
loc = ln->GetObject<ConstantPositionMobilityModel> ();
if (loc == 0)
{
loc = CreateObject<ConstantPositionMobilityModel> ();
ln->AggregateObject (loc);
}
Vector lnl (lrl.x - std::cos (theta) * xAdder,
lrl.y + std::sin (theta) * xAdder, 0); // Left Node Location
// Insure did not exceed bounding box
if (lnl.y < uly)
{
lnl.y = uly; // Set to upper left y
}
if (lnl.y > lry)
{
lnl.y = lry; // Set to lower right y
}
loc->SetPosition (lnl);
theta += thetaL;
}
// Place the right nodes
theta = -M_PI_2 + thetaR;
for (uint32_t r = 0; r < RightCount (); ++r)
{
// Special case when theta = 0, to be sure we get a straight line
if ((RightCount () % 2) == 1)
{ // Count is odd, see if we are in middle
if (r == (RightCount () / 2))
{
theta = 0.0;
}
}
Ptr<Node> rn = GetRight (r);
loc = rn->GetObject<ConstantPositionMobilityModel> ();
if (loc == 0)
{
loc = CreateObject<ConstantPositionMobilityModel> ();
rn->AggregateObject (loc);
}
Vector rnl (rrl.x + std::cos (theta) * xAdder, // Right node location
rrl.y + std::sin (theta) * xAdder, 0);
// Insure did not exceed bounding box
if (rnl.y < uly)
{
rnl.y = uly; // Set to upper left y
}
if (rnl.y > lry)
{
rnl.y = lry; // Set to lower right y
}
loc->SetPosition (rnl);
theta += thetaR;
}
}