add Rectangle class and use it.
--- a/src/core/rectangle-default-value.cc Wed Jul 18 17:06:36 2007 +0200
+++ b/src/core/rectangle-default-value.cc Wed Jul 18 17:07:15 2007 +0200
@@ -28,37 +28,29 @@
double xMin, double xMax,
double yMin, double yMax)
: DefaultValueBase (name, help),
- m_xMinDefault (xMin),
- m_xMaxDefault (xMax),
- m_yMinDefault (yMin),
- m_yMaxDefault (yMax),
- m_xMin (xMin),
- m_xMax (xMax),
- m_yMin (yMin),
- m_yMax (yMax)
+ m_default (xMin, xMax, yMin, yMax),
+ m_rectangle (xMin, xMax, yMin, yMax)
{
DefaultValueList::Add (this);
}
-double
-RectangleDefaultValue::GetMinX (void) const
+Rectangle
+RectangleDefaultValue::GetValue (void) const
{
- return m_xMin;
-}
-double
-RectangleDefaultValue::GetMinY (void) const
-{
- return m_yMin;
+ return m_rectangle;
}
-double
-RectangleDefaultValue::GetMaxX (void) const
+double
+RectangleDefaultValue::ReadDouble (std::string str, bool &ok)
{
- return m_xMax;
-}
-double
-RectangleDefaultValue::GetMaxY (void) const
-{
- return m_yMax;
+ double value;
+ std::istringstream iss;
+ iss.str (str);
+ iss >> value;
+ if (iss.bad () || iss.fail ())
+ {
+ ok = false;
+ }
+ return value;
}
bool
RectangleDefaultValue::DoParseValue (const std::string &value)
@@ -77,17 +69,12 @@
std::string yMinString = value.substr (yMinStart, yMinEnd);
std::string yMaxString = value.substr (yMaxStart, yMaxEnd);
- std::istringstream iss;
- iss.str (xMinString);
- iss >> m_xMin;
- iss.str (xMaxString);
- iss >> m_xMax;
- iss.str (yMinString);
- iss >> m_yMin;
- iss.str (yMaxString);
- iss >> m_yMax;
-
- return !iss.bad () && !iss.fail ();
+ bool ok = true;
+ m_rectangle.xMin = ReadDouble (xMinString, ok);
+ m_rectangle.yMin = ReadDouble (yMinString, ok);
+ m_rectangle.xMax = ReadDouble (xMaxString, ok);
+ m_rectangle.yMax = ReadDouble (yMaxString, ok);
+ return ok;
}
std::string
RectangleDefaultValue::DoGetType (void) const
@@ -98,7 +85,7 @@
RectangleDefaultValue::DoGetDefaultValue (void) const
{
std::ostringstream oss;
- oss << m_xMinDefault << ":" << m_xMaxDefault << ":" << m_yMinDefault << ":" << m_yMaxDefault;
+ oss << m_default.xMin << ":" << m_default.xMax << ":" << m_default.yMin << ":" << m_default.yMax;
return oss.str ();
}
--- a/src/core/rectangle-default-value.h Wed Jul 18 17:06:36 2007 +0200
+++ b/src/core/rectangle-default-value.h Wed Jul 18 17:07:15 2007 +0200
@@ -23,6 +23,7 @@
#include <string>
#include "default-value.h"
+#include "rectangle.h"
namespace ns3 {
@@ -34,23 +35,15 @@
double xMin, double xMax,
double yMin, double yMax);
- double GetMinX (void) const;
- double GetMinY (void) const;
- double GetMaxX (void) const;
- double GetMaxY (void) const;
+ Rectangle GetValue (void) const;
private:
+ double ReadDouble (std::string str, bool &ok);
virtual bool DoParseValue (const std::string &value);
virtual std::string DoGetType (void) const;
virtual std::string DoGetDefaultValue (void) const;
- double m_xMinDefault;
- double m_xMaxDefault;
- double m_yMinDefault;
- double m_yMaxDefault;
- double m_xMin;
- double m_xMax;
- double m_yMin;
- double m_yMax;
+ Rectangle m_default;
+ Rectangle m_rectangle;
};
} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/rectangle.cc Wed Jul 18 17:07:15 2007 +0200
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#include "rectangle.h"
+
+namespace ns3 {
+
+Rectangle::Rectangle (double _xMin, double _xMax,
+ double _yMin, double _yMax)
+ : xMin (_xMin),
+ xMax (_xMax),
+ yMin (_yMin),
+ yMax (_yMax)
+{}
+
+Rectangle::Rectangle ()
+ : xMin (0.0),
+ xMax (0.0),
+ yMin (0.0),
+ yMax (0.0)
+{}
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/core/rectangle.h Wed Jul 18 17:07:15 2007 +0200
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2007 INRIA
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+#ifndef RECTANGLE_H
+#define RECTANGLE_H
+
+namespace ns3 {
+
+class Rectangle
+{
+public:
+ Rectangle (double _xMin, double _xMax,
+ double _yMin, double _yMax);
+ Rectangle ();
+ double xMin;
+ double xMax;
+ double yMin;
+ double yMax;
+};
+
+} // namespace ns3
+
+#endif /* RECTANGLE_H */
--- a/src/node/position.cc Wed Jul 18 17:06:36 2007 +0200
+++ b/src/node/position.cc Wed Jul 18 17:07:15 2007 +0200
@@ -1,4 +1,5 @@
#include "position.h"
+#include "ns3/rectangle.h"
#include <cmath>
namespace ns3 {
@@ -16,6 +17,14 @@
z (0.0)
{}
+bool
+Position::IsInside (const Rectangle &rectangle) const
+{
+ return
+ x <= rectangle.xMax && x >= rectangle.xMin &&
+ y <= rectangle.yMax && y >= rectangle.yMin;
+}
+
double
CalculateDistance (const Position &a, const Position &b)
{
--- a/src/node/position.h Wed Jul 18 17:06:36 2007 +0200
+++ b/src/node/position.h Wed Jul 18 17:07:15 2007 +0200
@@ -3,11 +3,14 @@
namespace ns3 {
+class Rectangle;
+
class Position
{
public:
Position (double x, double y, double z);
Position ();
+ bool IsInside (const Rectangle &rectangle) const;
double x;
double y;
double z;