[idlescreen] r208 committed - Started back to work on Spiral. Started adding in unit test framework...

1 view
Skip to first unread message

codesite...@google.com

unread,
Feb 7, 2010, 5:06:37 PM2/7/10
to dev-idl...@googlegroups.com
Revision: 208
Author: jeff.backus
Date: Sun Feb 7 14:05:58 2010
Log: Started back to work on Spiral. Started adding in unit test framework,
including a unit test for Point2D.

http://code.google.com/p/idlescreen/source/detail?r=208

Added:
/branches/backus_dev/src/common/unit_tests
/branches/backus_dev/src/common/unit_tests/unit_tests.pro
/branches/backus_dev/src/common/unit_tests/unit_tests_main.cpp
/branches/backus_dev/src/common/utility/unit_tests
/branches/backus_dev/src/common/utility/unit_tests/Test_Point2D.cpp
/branches/backus_dev/src/common/utility/unit_tests/Test_Point2D.h
Modified:
/branches/backus_dev/Makefile.in
/branches/backus_dev/src/SpiralLenz/project_files/SpiralLenz_glut.pro

/branches/backus_dev/src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp
/branches/backus_dev/src/common/utility/Point2D.cpp
/branches/backus_dev/src/common/utility/Point2D.h

=======================================
--- /dev/null
+++ /branches/backus_dev/src/common/unit_tests/unit_tests.pro Sun Feb 7
14:05:58 2010
@@ -0,0 +1,45 @@
+TEMPLATE = app
+CONFIG += qt qtestlib warn_on
+#win32:CONFIG +=
+unix:CONFIG += x11 release
+QT += xml
+
+DEPENDPATH += .
+INCLUDEPATH += .
+
+unix:COMMON_PATH = ..
+win32:COMMON_PATH = ..
+
+#unix:SOURCE_PATH = ../src
+#win32:SOURCE_PATH = ../../src
+
+#unix:RESOURCE_PATH = ../resource_files
+#win32:RESOURCE_PATH = ../../resource_files
+
+INCLUDEPATH = $$COMMON_PATH #$$SOURCE_PATH $$RESOURCE_PATH
+
+# Input
+SOURCES = unit_tests_main.cpp
+SOURCES += $$COMMON_PATH/utility/Point2D.cpp
+SOURCES += $$COMMON_PATH/utility/unit_tests/Test_Point2D.cpp
+#SOURCES += $$COMMON_PATH/utility/Vector2D.cpp
+#SOURCES += $$COMMON_PATH/utility/unit_tests/Test_Vector2D.cpp
+
+HEADERS = $$COMMON_PATH/utility/Point2D.h
+HEADERS += $$COMMON_PATH/utility/unit_tests/Test_Point2D.h
+#HEADERS += $$COMMON_PATH/utility/Vector2D.h
+#HEADERS += $$COMMON_PATH/utility/unit_tests/Test_Vector2D.h
+
+TARGET = common_unit_tests
+#RC_FILE = $$RESOURCE_PATH/win_resource.rc
+#RESOURCES = $$RESOURCE_PATH/qt_resource.qrc
+
+win32:LIBS += user32.lib shell32.lib Advapi32.lib gdi32.lib
scrnsavw.lib opengl32.lib glu32.lib comctl32.lib $$IDLSCR_RES_LOC
+
+unix:DESTDIR = ../../../bin
+#unix:OBJECTS_DIR = ../compiled_objects
+unix:OBJECTS_DIR = .
+#unix:MOC_DIR = ../compiled_objects
+unix:MOC_DIR = .
+unix:LIBS += -lGL -lGLU -lX11 -lXmu -lXi -lm
+
=======================================
--- /dev/null
+++ /branches/backus_dev/src/common/unit_tests/unit_tests_main.cpp Sun Feb
7 14:05:58 2010
@@ -0,0 +1,4 @@
+#include <QtTest/QtTest>
+#include "utility/unit_tests/Test_Point2D.h"
+
+QTEST_MAIN(Test_Point2D)
=======================================
--- /dev/null
+++ /branches/backus_dev/src/common/utility/unit_tests/Test_Point2D.cpp Sun
Feb 7 14:05:58 2010
@@ -0,0 +1,364 @@
+/**
+ * Copyright (c) 2009 Jeff Backus.
+ *
+ * Licensed under the GNU General Public License, Version 2.0
(the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Additionally, this code makes heavy use of the Qt libraries from
+ * Trolltech. These libraries are released under the GNU
+ * General Public License, Version 2.0, as well. Please contact
+ * Trolltech for more information.
+ *
+ * http://trolltech.com/
+ *
+ */
+//#include <iostream>
+#include <sstream>
+#include <string>
+using namespace std;
+
+#include "Test_Point2D.h"
+
+void Test_Point2D::Test_GetSetX() {
+ Point2D testPoint;
+
+ // set to a positive number
+ testPoint.setX(5.1);
+ QVERIFY(testPoint.getX() == 5.1);
+ QVERIFY(testPoint.getY() == 0.0);
+
+ // set to default
+ testPoint.setX();
+ QVERIFY(testPoint.getX() == 0.0);
+ QVERIFY(testPoint.getY() == 0.0);
+
+ // set to a negative number
+ testPoint.setX(-1000.4);
+ QVERIFY(testPoint.getX() == -1000.4);
+ QVERIFY(testPoint.getY() == 0.0);
+}
+
+void Test_Point2D::Test_GetSetY() {
+ Point2D testPoint;
+
+ // set to a positive number
+ testPoint.setY(7.2);
+ QVERIFY(testPoint.getX() == 0.0);
+ QVERIFY(testPoint.getY() == 7.2);
+
+ // set to default
+ testPoint.setY();
+ QVERIFY(testPoint.getX() == 0.0);
+ QVERIFY(testPoint.getY() == 0.0);
+
+ // set to a negative number
+ testPoint.setY(-1413.9);
+ QVERIFY(testPoint.getX() == 0.0);
+ QVERIFY(testPoint.getY() == -1413.9);
+}
+
+void Test_Point2D::Test_SetValue() {
+ Point2D testPoint;
+ double xVal;
+ double yVal;
+
+ // set to positive numbers
+ xVal = 12.19;
+ yVal = 0.194;
+ testPoint.setValue(xVal,yVal);
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // set to default
+ testPoint.setValue();
+ QVERIFY(testPoint.getX() == 0.0);
+ QVERIFY(testPoint.getY() == 0.0);
+
+ // set to a negative number
+ xVal = -0.294;
+ yVal = -194.109;
+ testPoint.setValue(xVal,yVal);
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+}
+
+void Test_Point2D::Test_Constructor() {
+ // set to positive numbers
+ Point2D testPointA(5.4,7.2);
+ QVERIFY(testPointA.getX() == 5.4);
+ QVERIFY(testPointA.getY() == 7.2);
+
+ // set to default
+ Point2D testPointB;
+ QVERIFY(testPointB.getX() == 0.0);
+ QVERIFY(testPointB.getY() == 0.0);
+
+ // set to a negative number
+ Point2D testPointC(-5923.1,-21734.1);
+ QVERIFY(testPointC.getX() == -5923.1);
+ QVERIFY(testPointC.getY() == -21734.1);
+}
+
+void Test_Point2D::Test_OperatorSet() {
+ Point2D testPoint;
+
+ // set to positive numbers
+ Point2D testPointA(5.4,7.2);
+ testPoint = testPointA;
+ QVERIFY(testPoint.getX() == testPointA.getX());
+ QVERIFY(testPoint.getY() == testPointA.getY());
+
+ // set to default
+ Point2D testPointB;
+ testPoint = testPointB;
+ QVERIFY(testPoint.getX() == testPointB.getX());
+ QVERIFY(testPoint.getY() == testPointB.getY());
+
+ // set to a negative number
+ Point2D testPointC(-5923.1,-21734.1);
+ testPoint = testPointC;
+ QVERIFY(testPoint.getX() == testPointC.getX());
+ QVERIFY(testPoint.getY() == testPointC.getY());
+}
+
+void Test_Point2D::Test_OperatorEqual() {
+ Point2D testPointA(5.4,7.2);
+ Point2D testPointB;
+ Point2D testPointC(-5923.1,-21734.1);
+
+ Point2D testPoint = testPointA;
+ QVERIFY(testPoint == testPointA);
+ QVERIFY(!(testPoint == testPointB));
+ QVERIFY(!(testPoint == testPointC));
+
+ testPoint = testPointB;
+ QVERIFY(!(testPoint == testPointA));
+ QVERIFY(testPoint == testPointB);
+ QVERIFY(!(testPoint == testPointC));
+
+ testPoint = testPointC;
+ QVERIFY(!(testPoint == testPointA));
+ QVERIFY(!(testPoint == testPointB));
+ QVERIFY(testPoint == testPointC);
+}
+
+void Test_Point2D::Test_OperatorNotEqual() {
+ Point2D testPointA(5.4,7.2);
+ Point2D testPointB;
+ Point2D testPointC(-5923.1,-21734.1);
+
+ Point2D testPoint = testPointA;
+ QVERIFY(!(testPoint != testPointA));
+ QVERIFY(testPoint != testPointB);
+ QVERIFY(testPoint != testPointC);
+
+ testPoint = testPointB;
+ QVERIFY(testPoint != testPointA);
+ QVERIFY(!(testPoint != testPointB));
+ QVERIFY(testPoint != testPointC);
+
+ testPoint = testPointC;
+ QVERIFY(testPoint != testPointA);
+ QVERIFY(testPoint != testPointB);
+ QVERIFY(!(testPoint != testPointC));
+}
+
+void Test_Point2D::Test_OperatorMultiply() {
+ double xVal = 5.4;
+ double yVal = 7.2;
+ double mul;
+ Point2D testPoint(xVal, yVal);
+
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // Positive number
+ mul = 4.91;
+ testPoint = testPoint * mul;
+ xVal *= mul;
+ yVal *= mul;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // Negative number
+ mul = -0.15;
+ testPoint = testPoint * mul;
+ xVal *= mul;
+ yVal *= mul;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // Zero
+ mul = 0.0;
+ testPoint = testPoint * mul;
+ xVal *= mul;
+ yVal *= mul;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+}
+
+void Test_Point2D::Test_OperatorDivide() {
+ double xVal = 32.149;
+ double yVal = 91.43;
+ double div;
+ Point2D testPoint(xVal, yVal);
+
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // Positive number
+ div = 0.7291;
+ testPoint = testPoint / div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // Negative number
+ div = -15.941;
+ testPoint = testPoint / div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // One
+ div = 1.0;
+ testPoint = testPoint / div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // Zero
+ div = 0.0;
+ testPoint = testPoint / div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+}
+
+void Test_Point2D::Test_OperatorMultiplyEqual() {
+ double xVal = 1.19;
+ double yVal = 910.14;
+ double mul;
+ Point2D testPoint(xVal, yVal);
+
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // Positive number
+ mul = 0.1234613;
+ testPoint *= mul;
+ xVal *= mul;
+ yVal *= mul;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // Negative number
+ mul = -7234.19;
+ testPoint *= mul;
+ xVal *= mul;
+ yVal *= mul;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // Zero
+ mul = 0.0;
+ testPoint *= mul;
+ xVal *= mul;
+ yVal *= mul;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+}
+
+void Test_Point2D::Test_OperatorDivideEqual() {
+ double xVal = 12.1;
+ double yVal = 0.7143;
+ double div;
+ Point2D testPoint(xVal, yVal);
+
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // Positive number
+ div = 71.45;
+ testPoint /= div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // Negative number
+ div = -0.941613;
+ testPoint /= div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // One
+ div = 1.0;
+ testPoint /= div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+
+ // Zero
+ div = 0.0;
+ testPoint /= div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testPoint.getX() == xVal);
+ QVERIFY(testPoint.getY() == yVal);
+}
+
+void Test_Point2D::Test_OperatorOstream() {
+ double xVal;
+ double yVal;
+
+ // set to positive numbers
+ xVal = 56.4;
+ yVal = 17.2;
+
+ Point2D testPoint(xVal, yVal);
+ ostringstream testOSSA(ostringstream::out);
+ testOSSA.precision(15);
+ testOSSA << testPoint;
+ string testStrA = testOSSA.str();
+
+ ostringstream controlOSSA(ostringstream::out);
+ controlOSSA.precision(15);
+ controlOSSA << "("<<xVal<<","<<yVal<<")";
+ string controlStrA = controlOSSA.str();
+
+ QVERIFY(testStrA == controlStrA);
+
+ // set to negative numbers
+ xVal = -324151.1;
+ yVal = -0.1932414;
+
+ testPoint.setValue(xVal, yVal);
+ ostringstream testOSSB(ostringstream::out);
+ testOSSB.precision(15);
+ testOSSB << testPoint;
+ string testStrB = testOSSB.str();
+
+ ostringstream controlOSSB(ostringstream::out);
+ controlOSSB.precision(15);
+ controlOSSB << "("<<xVal<<","<<yVal<<")";
+ string controlStrB = controlOSSB.str();
+
+ QVERIFY(testStrB == controlStrB);
+}
=======================================
--- /dev/null
+++ /branches/backus_dev/src/common/utility/unit_tests/Test_Point2D.h Sun
Feb 7 14:05:58 2010
@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2009 Jeff Backus.
+ *
+ * Licensed under the GNU General Public License, Version 2.0
(the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Additionally, this code makes heavy use of the Qt libraries from
+ * Trolltech. These libraries are released under the GNU
+ * General Public License, Version 2.0, as well. Please contact
+ * Trolltech for more information.
+ *
+ * http://trolltech.com/
+ *
+ */
+
+/**
+ * This set of classes is for unit testing Point2D.
+ */
+
+#ifndef __TEST_POINT2D_H__
+#define __TEST_POINT2D_H__
+
+#include <QtTest/QtTest>
+#include "../Point2D.h"
+
+class Test_Point2D: public QObject {
+ Q_OBJECT
+
+ private slots:
+ void Test_GetSetX();
+ void Test_GetSetY();
+ void Test_SetValue();
+ void Test_Constructor();
+ void Test_OperatorSet();
+ void Test_OperatorEqual();
+ void Test_OperatorNotEqual();
+ void Test_OperatorMultiply();
+ void Test_OperatorDivide();
+ void Test_OperatorMultiplyEqual();
+ void Test_OperatorDivideEqual();
+ void Test_OperatorOstream();
+
+ private:
+};
+
+#endif
=======================================
--- /branches/backus_dev/Makefile.in Sun Aug 2 11:49:07 2009
+++ /branches/backus_dev/Makefile.in Sun Feb 7 14:05:58 2010
@@ -46,7 +46,7 @@
UNINSTALL_XSCR = $(xscrdatadir)/$(INSTALL_XSCR)
UPDATEXSCR = @UPDATEXSCR@

-.PHONY : forceall all clean doc repoclean distclean
+.PHONY : forceall all clean doc repoclean distclean unit_tests

forceall :
-rm bin/*
@@ -54,6 +54,13 @@

all : $(TRG)

+unit_tests : bin/common_unit_tests
+
+bin/common_unit_tests : src/common/unit_tests/unit_tests.pro
src/common/unit_tests/unit_tests_main.cpp
+ cd $(srcdir)/src/common/unit_tests/ && $(QMAKE) unit_tests.pro \
+ -o Makefile.unit_tests && \
+ $(MAKE) -f Makefile.unit_tests
+
bin/PlasmaLenz : src/PlasmaLenz/project_files/PlasmaLenz_scr.pro
cd $(srcdir)/src/PlasmaLenz/project_files/ && $(QMAKE) PlasmaLenz_scr.pro
\
-o Makefile.PlasmaLenz_scr && \
@@ -109,6 +116,7 @@
-rm bin/AcidRain bin/AcidRain_glut
-rm bin/SpiralLenz bin/SpiralLenz_glut
-rm bin/PlasmaGenerator
+ -rm bin/*unit_tests
-cd $(srcdir)/src/PlasmaLenz/project_files/ && $(MAKE) -f
Makefile.PlasmaLenz_scr clean
-cd $(srcdir)/src/PlasmaLenz/project_files/ && $(MAKE) -f
Makefile.PlasmaLenz_glut clean
-cd $(srcdir)/src/Crawlies/project_files/ && $(MAKE) -f
Makefile.Crawlies_scr clean
@@ -126,6 +134,7 @@
-rm bin/Crawlies bin/Crawlies_glut
-rm bin/AcidRain bin/AcidRain_glut
-rm bin/SpiralLenz bin/SpiralLenz_glut
+ -rm bin/*unit_tests
-cd $(srcdir)/src/PlasmaLenz/project_files/ && $(MAKE) -f
Makefile.PlasmaLenz_scr distclean
-cd $(srcdir)/src/PlasmaLenz/project_files/ && $(MAKE) -f
Makefile.PlasmaLenz_glut distclean
-cd $(srcdir)/src/Crawlies/project_files/ && $(MAKE) -f
Makefile.Crawlies_scr distclean
=======================================
--- /branches/backus_dev/src/SpiralLenz/project_files/SpiralLenz_glut.pro
Sun Aug 2 11:49:07 2009
+++ /branches/backus_dev/src/SpiralLenz/project_files/SpiralLenz_glut.pro
Sun Feb 7 14:05:58 2010
@@ -19,7 +19,7 @@

SOURCES += $$COMMON_PATH/spirals/SpiralAlgorithm.cpp
SOURCES += $$COMMON_PATH/spirals/RectangularSpiralAlgorithm.cpp
-SOURCES += $$COMMON_PATH/spirals/NgonSpiralAlgorithm.cpp
+//SOURCES += $$COMMON_PATH/spirals/NgonSpiralAlgorithm.cpp
SOURCES += $$COMMON_PATH/spirals/PolarSpiralAlgorithm.cpp

SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPalette.cpp
@@ -63,7 +63,7 @@

HEADERS += $$COMMON_PATH/spirals/SpiralAlgorithm.h
HEADERS += $$COMMON_PATH/spirals/RectangularSpiralAlgorithm.h
-HEADERS += $$COMMON_PATH/spirals/NgonSpiralAlgorithm.h
+//HEADERS += $$COMMON_PATH/spirals/NgonSpiralAlgorithm.h
HEADERS += $$COMMON_PATH/spirals/PolarSpiralAlgorithm.h

HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPalette.h
=======================================
---
/branches/backus_dev/src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp
Sun Aug 2 11:49:07 2009
+++
/branches/backus_dev/src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp
Sun Feb 7 14:05:58 2010
@@ -36,7 +36,10 @@
#include "SpiralBackground.h"

// begin tmp
-#include "spirals/NgonSpiralAlgorithm.h"
+// modified 02/06/10 to get back on track..
+//#include "spirals/NgonSpiralAlgorithm.h"
+#include "spirals/RectangularSpiralAlgorithm.h"
+// end mod
#include "spirals/PolarSpiralAlgorithm.h"
// end tmp

@@ -255,20 +258,21 @@
int width,
QHash<QString, IndexedPaletteProfile*>* palHash) {

-
+ /*
PolarSpiralAlgorithm* alg =
new PolarSpiralAlgorithm(_colorWidth,_emptyWidth,_bConstantColor,
_bRandomColor, _bIncrementColor);
+ */
/*
NgonSpiralAlgorithm* alg =
new NgonSpiralAlgorithm(0,_colorWidth,_emptyWidth,_bConstantColor,
_bRandomColor, _bIncrementColor);
*/
- /*
+
RectangularSpiralAlgorithm* alg =
new RectangularSpiralAlgorithm(_colorWidth,_emptyWidth,_bConstantColor,
_bRandomColor, _bIncrementColor);
- */
+
if(alg == NULL)
return NULL;

=======================================
--- /branches/backus_dev/src/common/utility/Point2D.cpp Mon Apr 27 14:19:22
2009
+++ /branches/backus_dev/src/common/utility/Point2D.cpp Sun Feb 7 14:05:58
2010
@@ -1,10 +1,35 @@
+/**
+ * Copyright (c) 2009 Jeff Backus.
+ *
+ * Licensed under the GNU General Public License, Version 2.0
(the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Additionally, this code makes heavy use of the Qt libraries from
+ * Trolltech. These libraries are released under the GNU
+ * General Public License, Version 2.0, as well. Please contact
+ * Trolltech for more information.
+ *
+ * http://trolltech.com/
+ *
+ */
+#include "Point2D.h"
+
/**
* Constructor.
*
* @param x The initial x value of the vector.
* @param y The initial y value of the vector.
*/
-Point2D::Point2D(const double x=0.0, const double y=0.0) {
+Point2D::Point2D(const double x, const double y) {
_x = x;
_y = y;
}
@@ -24,7 +49,7 @@
/**
* Sets the x value.
*/
-void Point2D::setX(const double x=0.0) {
+void Point2D::setX(const double x) {
_x = x;
}

@@ -37,7 +62,7 @@
/**
* Sets the y value.
*/
-void Point2D::setY(const double y=0.0) {
+void Point2D::setY(const double y) {
_y = y;
}

@@ -49,31 +74,45 @@

return *this;
}
-Point2D& Point2D::operator==(const Point2D& other) {
+
+/**
+ * Sets both the x & y values.
+ */
+void Point2D::setValue(const double x, const double y) {
+ _x = x;
+ _y = y;
+}
+
+bool Point2D::operator==(const Point2D& other) {
return (_x == other._x && _y == other._y);
}
-Point2D& Point2D::operator!=(const Point2D& other) {
+bool Point2D::operator!=(const Point2D& other) {
return !(*this == other);
}
Point2D& Point2D::operator*(const double val) {
- Point2D retVal = *this;
- retVal *= val;
- return retVal;
+ *this *= val;
+ return *this;
}
Point2D& Point2D::operator/(const double val) {
- Point2D retVal = *this;
- retVal /= val;
- return retVal;
+ *this /= val;
+ return *this;
}
Point2D& Point2D::operator*=(const double val) {
- Point2D retVal = *this;
- retVal._x *= val;
- retVal._y *= val;
- return retVal;
+ _x *= val;
+ _y *= val;
+ return *this;
}
Point2D& Point2D::operator/=(const double val) {
- Point2D retVal = *this;
- retVal._x /= val;
- retVal._y /= val;
- return retVal;
-}
+ _x /= val;
+ _y /= val;
+ return *this;
+}
+
+/**
+ * friend vector to dump to an ostream
+ */
+ostream& operator<<(ostream& os, const Point2D& point) {
+ Point2D tmp = point;
+ os<<"("<<tmp.getX()<<","<<tmp.getY()<<")";
+ return os;
+}
=======================================
--- /branches/backus_dev/src/common/utility/Point2D.h Mon Apr 27 14:19:22
2009
+++ /branches/backus_dev/src/common/utility/Point2D.h Sun Feb 7 14:05:58
2010
@@ -28,7 +28,7 @@
*/

#include <iostream>
-#include <meth.h>
+#include <math.h>

using namespace std;

@@ -72,28 +72,25 @@
*/
void setY(const double y=0.0);

+ /**
+ * Sets both the x & y values.
+ */
+ void setValue(const double x=0.0, const double y=0.0);
+
Point2D& operator=(const Point2D& other);
- Point2D& operator==(const Point2D& other);
- Point2D& operator!=(const Point2D& other);
+ bool operator==(const Point2D& other);
+ bool operator!=(const Point2D& other);
// these operations geometrically don't make sense, but are for ease of
use.
Point2D& operator*(const double val);
Point2D& operator/(const double val);
Point2D& operator*=(const double val);
Point2D& operator/=(const double val);

+ friend ostream& operator<<(ostream& os, const Point2D& point);
+
private:
double _x;
double _y;
};
-
-// **** Begin Friend definitions ****
-
-/**
- * friend vector to dump to an ostream
- */
-friend ostream& operator<<(ostream& os, const Point2D& point) {
- os<<"("<<point.getX()<<","<<point.getY()<<")";
- return os;
-}

#endif

Reply all
Reply to author
Forward
0 new messages