|
|
| 315 |
} |
315 |
} |
| 316 |
|
316 |
|
| 317 |
|
317 |
|
|
|
318 |
|
| 319 |
NS_OBJECT_ENSURE_REGISTERED (UniformDiscPositionAllocator); |
| 320 |
|
| 321 |
TypeId |
| 322 |
UniformDiscPositionAllocator::GetTypeId (void) |
| 323 |
{ |
| 324 |
static TypeId tid = TypeId ("ns3::UniformDiscPositionAllocator") |
| 325 |
.SetParent<PositionAllocator> () |
| 326 |
.SetGroupName ("Mobility") |
| 327 |
.AddConstructor<UniformDiscPositionAllocator> () |
| 328 |
.AddAttribute ("rho", |
| 329 |
"The radius of the disc", |
| 330 |
DoubleValue (0.0), |
| 331 |
MakeDoubleAccessor (&UniformDiscPositionAllocator::m_rho), |
| 332 |
MakeDoubleChecker<double> ()) |
| 333 |
.AddAttribute ("X", |
| 334 |
"The x coordinate of the center of the disc.", |
| 335 |
DoubleValue (0.0), |
| 336 |
MakeDoubleAccessor (&UniformDiscPositionAllocator::m_x), |
| 337 |
MakeDoubleChecker<double> ()) |
| 338 |
.AddAttribute ("Y", |
| 339 |
"The y coordinate of the center of the disc.", |
| 340 |
DoubleValue (0.0), |
| 341 |
MakeDoubleAccessor (&UniformDiscPositionAllocator::m_y), |
| 342 |
MakeDoubleChecker<double> ()) |
| 343 |
; |
| 344 |
return tid; |
| 345 |
} |
| 346 |
|
| 347 |
UniformDiscPositionAllocator::UniformDiscPositionAllocator () |
| 348 |
{} |
| 349 |
UniformDiscPositionAllocator::~UniformDiscPositionAllocator () |
| 350 |
{} |
| 351 |
|
| 352 |
void |
| 353 |
UniformDiscPositionAllocator::SetRho (double rho) |
| 354 |
{ |
| 355 |
m_rho = rho; |
| 356 |
} |
| 357 |
void |
| 358 |
UniformDiscPositionAllocator::SetX (double x) |
| 359 |
{ |
| 360 |
m_x = x; |
| 361 |
} |
| 362 |
void |
| 363 |
UniformDiscPositionAllocator::SetY (double y) |
| 364 |
{ |
| 365 |
m_y = y; |
| 366 |
} |
| 367 |
Vector |
| 368 |
UniformDiscPositionAllocator::GetNext (void) const |
| 369 |
{ |
| 370 |
UniformVariable r (-m_rho, m_rho); |
| 371 |
double x,y; |
| 372 |
do |
| 373 |
{ |
| 374 |
x = r.GetValue (); |
| 375 |
y = r.GetValue (); |
| 376 |
} |
| 377 |
while (sqrt(x*x + y*y) > m_rho); |
| 378 |
|
| 379 |
x += m_x; |
| 380 |
y += m_y; |
| 381 |
NS_LOG_DEBUG ("Disc position x=" << x << ", y=" << y); |
| 382 |
return Vector (x, y, 0.0); |
| 383 |
} |
| 384 |
|
| 385 |
|
| 318 |
} // namespace ns3 |
386 |
} // namespace ns3 |