Release_0.03_Alpha created at 9ccd54a55217
Release_0.8_Beta created at 800308f93612
dev created at 4d296da626db
10 new revisions:
Revision: 5fa5a9c4df03
Author: Jeff Backus <
jeff....@gmail.com>
Date: Sat Mar 14 12:45:43 2009 UTC
Log: Creating a dev branch. Should have been doing this all along....
http://code.google.com/p/idlescreen/source/detail?r=5fa5a9c4df03
Revision: 34032171b541
Author: Jeff Backus <
jeff....@gmail.com>
Date: Mon Mar 16 21:29:13 2009 UTC
Log: Fixed the windows resource title for the PlasmaGenerator. Added
Spira...
http://code.google.com/p/idlescreen/source/detail?r=34032171b541
Revision: 82aa12a01f77
Author: Jeff Backus <
jeff....@gmail.com>
Date: Mon Apr 27 00:56:58 2009 UTC
Log: Made a number of changes, but currently working on redoing the
spiral ...
http://code.google.com/p/idlescreen/source/detail?r=82aa12a01f77
Revision: 55534db500ba
Author: Jeff Backus <
jeff....@gmail.com>
Date: Mon Apr 27 21:19:22 2009 UTC
Log: Added Point2D and Vector2D classes. Have not been tested! Need
to al...
http://code.google.com/p/idlescreen/source/detail?r=55534db500ba
Revision: 87af136e877d
Author: Jeff Backus <
jeff....@gmail.com>
Date: Sun Aug 2 18:49:07 2009 UTC
Log: Still working on SpiralLenz. Won't compile yet. Committing so
that i...
http://code.google.com/p/idlescreen/source/detail?r=87af136e877d
Revision: 9af23b015ecb
Author: Jeff Backus <
jeff....@gmail.com>
Date: Sun Feb 7 22:05:58 2010 UTC
Log: Started back to work on Spiral. Started adding in unit test
framework...
http://code.google.com/p/idlescreen/source/detail?r=9af23b015ecb
Revision: 3cfa3b6e29b2
Author: Jeff Backus <
jeff....@gmail.com>
Date: Mon Feb 8 02:40:30 2010 UTC
Log: Added unit tests for misc_funcs & Vector2D, but the still need a
lot o...
http://code.google.com/p/idlescreen/source/detail?r=3cfa3b6e29b2
Revision: f059e2e49913
Author: Jeff Backus <
jeff....@gmail.com>
Date: Thu Feb 11 02:19:00 2010 UTC
Log: Made a lot of progress with Vector2D and its unit test. Have one
more...
http://code.google.com/p/idlescreen/source/detail?r=f059e2e49913
Revision: ee3dfa30733e
Author: Jeff Backus <
jeff....@gmail.com>
Date: Sat Feb 13 23:17:14 2010 UTC
Log: Finished Vector2D tests and debugging.
http://code.google.com/p/idlescreen/source/detail?r=ee3dfa30733e
Revision: 4d296da626db
Author: Jeff Backus <
jeff....@gmail.com>
Date: Sat Feb 20 16:25:28 2010 UTC
Log: More work on SpiralLenz. The current algorithm looks ok. Need
to cha...
http://code.google.com/p/idlescreen/source/detail?r=4d296da626db
==============================================================================
Revision: 5fa5a9c4df03
Author: Jeff Backus <
jeff....@gmail.com>
Date: Sat Mar 14 12:45:43 2009 UTC
Log: Creating a dev branch. Should have been doing this all along....
http://code.google.com/p/idlescreen/source/detail?r=5fa5a9c4df03
==============================================================================
Revision: 34032171b541
Author: Jeff Backus <
jeff....@gmail.com>
Date: Mon Mar 16 21:29:13 2009 UTC
Log: Fixed the windows resource title for the PlasmaGenerator. Added
SpiralLenz and
have begun working on the spirals. The screen saver part requires a lot of
work yet.
http://code.google.com/p/idlescreen/source/detail?r=34032171b541
Added:
/src/SpiralLenz/compiled_objects/
ignore.me
/src/SpiralLenz/man_page/SpiralLenz.1
/src/SpiralLenz/msvc/glut_demo/Debug/
ignore.me
/src/SpiralLenz/msvc/glut_demo/Release/
ignore.me
/src/SpiralLenz/msvc/redirector/Debug/
ignore.me
/src/SpiralLenz/msvc/redirector/Release/
ignore.me
/src/SpiralLenz/msvc/redirector/redirector.rc
/src/SpiralLenz/msvc/redirector/resource.h
/src/SpiralLenz/msvc/scr/Debug/
ignore.me
/src/SpiralLenz/msvc/scr/Release/
ignore.me
/src/SpiralLenz/project_files/SpiralLenz_glut.pro
/src/SpiralLenz/project_files/SpiralLenz_scr.pro
/src/SpiralLenz/resource_files/app_icon.ico
/src/SpiralLenz/resource_files/app_icon.png
/src/SpiralLenz/resource_files/defaults.xml
/src/SpiralLenz/resource_files/html/MainDialog.jpg
/src/SpiralLenz/resource_files/html/PaletteEditorChooser.jpg
/src/SpiralLenz/resource_files/html/ProfileEditDialog.html
/src/SpiralLenz/resource_files/html/ProfileEditDialog.jpg
/src/SpiralLenz/resource_files/html/index.html
/src/SpiralLenz/resource_files/qt_resource.qrc
/src/SpiralLenz/resource_files/resource.h
/src/SpiralLenz/resource_files/win_resource.rc
/src/SpiralLenz/src/ConfigWidget.cpp
/src/SpiralLenz/src/ProfileEditDialog.cpp
/src/SpiralLenz/src/ProfileEditDialog.h
/src/SpiralLenz/src/SpiralBackground.cpp
/src/SpiralLenz/src/SpiralBackground.h
/src/SpiralLenz/src/SpiralBackgroundProfile.cpp
/src/SpiralLenz/src/SpiralBackgroundProfile.h
/src/SpiralLenz/src/project_specific_externs.cpp
/src/SpiralLenz/src/redirector_main.cpp
/src/common/spirals/RectangularSpiralAlgorithm.cpp
/src/common/spirals/RectangularSpiralAlgorithm.h
/src/common/spirals/SpiralAlgorithm.cpp
/src/common/spirals/SpiralAlgorithm.h
Modified:
/src/PlasmaGenerator/resource_files/win_resource.rc
=======================================
--- /dev/null
+++ /src/SpiralLenz/compiled_objects/
ignore.me Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,1 @@
+Ignore this file. It is just to ensure that the directory gets created
during checkout.
=======================================
--- /dev/null
+++ /src/SpiralLenz/man_page/SpiralLenz.1 Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,35 @@
+.TH "PlasmaLenz" 1 "" "X Version 11"
+.SH NAME
+PlasmaLenz \- plasma fractal screen saver.
+.SH SYNOPSIS
+.B PlasmaLenz
+[\--root]
+[\-c]
+.SH DESCRIPTION
+PlasmaLenz is a screen saver for use with XScreenSaver that generates a
+plasma fractal, then rotates through the palette, reminiscent of the demos
+of days gone by. PlasmaLenz is part of the IdleScreen project
+(\fIhttp://
sites.google.com/site/idlescreenproject\fP).
+.SH OPTIONS
+.TP 8
+.B \--root
+Draw on the root window.
+.TP 8
+.B \-c
+Display the configuration dialog.
+.SH "SEE ALSO"
+.BR X (1),
+.BR xscreensaver (1),
+.BR xscreensaver-demo (1),
+.BR Crawlies (1),
+.BR AcidRain (1)
+.SH COPYRIGHT
+Copyright \(co 2008 by Jeff Backus and the IdleScreen Project.
+
+PlasmaLenz is released under the GNU General Public License version 2. It
+is distributed AS IS, without any warranty WHAT SO EVER. A copy of the
+GPLv2 can be obtained from
+\fIhttp://
www.gnu.org/licenses/old-licenses/gpl-2.0.html\fP
+.SH AUTHOR
+Jeff Backus
+
=======================================
--- /dev/null
+++ /src/SpiralLenz/msvc/glut_demo/Debug/
ignore.me Mon Mar 16 21:29:13 2009
UTC
@@ -0,0 +1,1 @@
+Ignore this file. It is just to ensure that the directory gets created
during checkout.
=======================================
--- /dev/null
+++ /src/SpiralLenz/msvc/glut_demo/Release/
ignore.me Mon Mar 16 21:29:13
2009 UTC
@@ -0,0 +1,1 @@
+Ignore this file. It is just to ensure that the directory gets created
during checkout.
=======================================
--- /dev/null
+++ /src/SpiralLenz/msvc/redirector/Debug/
ignore.me Mon Mar 16 21:29:13
2009 UTC
@@ -0,0 +1,1 @@
+Ignore this file. It is just to ensure that the directory gets created
during checkout.
=======================================
--- /dev/null
+++ /src/SpiralLenz/msvc/redirector/Release/
ignore.me Mon Mar 16 21:29:13
2009 UTC
@@ -0,0 +1,1 @@
+Ignore this file. It is just to ensure that the directory gets created
during checkout.
=======================================
--- /dev/null
+++ /src/SpiralLenz/msvc/redirector/redirector.rc Mon Mar 16 21:29:13 2009
UTC
@@ -0,0 +1,65 @@
+// Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+#include "../../resource_files/resource.h"
+#include "../../../common/utility/redirector_resource.h"
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "#include ""../../resource_files/resource.h""\r\n"
+ "#include ""../../../common/utility/redirector_resource.h""\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "#include ""../../resource_files/win_resource.rc""\r\n"
+ "#include ""../../../common/utility/redirector_resource.rc""\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+#endif // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+#include "../../resource_files/win_resource.rc"
+#include "../../../common/utility/redirector_resource.rc"
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
=======================================
--- /dev/null
+++ /src/SpiralLenz/msvc/redirector/resource.h Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,14 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by redirector.rc
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 101
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1001
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
=======================================
--- /dev/null
+++ /src/SpiralLenz/msvc/scr/Debug/
ignore.me Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,1 @@
+Ignore this file. It is just to ensure that the directory gets created
during checkout.
=======================================
--- /dev/null
+++ /src/SpiralLenz/msvc/scr/Release/
ignore.me Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,1 @@
+Ignore this file. It is just to ensure that the directory gets created
during checkout.
=======================================
--- /dev/null
+++ /src/SpiralLenz/project_files/SpiralLenz_glut.pro Mon Mar 16 21:29:13
2009 UTC
@@ -0,0 +1,98 @@
+TEMPLATE = app
+win32:CONFIG += qt warn_on
+unix:CONFIG += qt x11 warn_on release
+QT += xml
+
+unix:COMMON_PATH = ../../common
+win32:COMMON_PATH = ../../../common
+
+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
+
+SOURCES = $$COMMON_PATH/core/glut_demo.cpp
$$COMMON_PATH/core/win_misc_funcs.cpp
+
+SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPalette.cpp
+SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialog.cpp
+SOURCES +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteDialogEntryButton.cpp
+SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPaletteEditorWidget.cpp
+SOURCES +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidget.cpp
+SOURCES +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidgetItem.cpp
+SOURCES +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidgetSplitDlg.cpp
+SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPaletteProfile.cpp
+SOURCES += $$COMMON_PATH/utility/misc_funcs.cpp
+SOURCES += $$COMMON_PATH/utility/ImportExportDialog.cpp
+SOURCES += $$COMMON_PATH/utility/HelpDialog.cpp
+SOURCES += $$COMMON_PATH/gpl_related/gpldialog.cpp
+SOURCES += $$COMMON_PATH/plasma/PlasmaAlgorithm.cpp
+
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/opengl_main.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/Background.cpp
$$COMMON_PATH/2d_bgnd_w_lens/BackgroundProfile.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/configdlg_main.cpp
$$COMMON_PATH/2d_bgnd_w_lens/ConfigManager.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/IndexedPaletteBackground.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/MasterProfile.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/PaletteEditor.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/PaletteSelectWidget.cpp
+
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensProfile.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/GenericLensObject.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensObject.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensManager.cpp
+SOURCES +=
$$COMMON_PATH/2d_bgnd_w_lens/lens_engine/SphericalLensProfile.cpp
+
+SOURCES += $$SOURCE_PATH/ConfigWidget.cpp $$SOURCE_PATH/PlasmaFractal.cpp
+SOURCES += $$SOURCE_PATH/PlasmaFractalBackgroundProfile.cpp
$$SOURCE_PATH/project_specific_externs.cpp
+SOURCES += $$COMMON_PATH/utility/AboutDialog.cpp
+SOURCES += $$SOURCE_PATH/ProfileEditDialog.cpp
+
+HEADERS = $$COMMON_PATH/core/win_misc_funcs.h
+
+HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPalette.h
+HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialog.h
+HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialogEntryButton.h
+HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteEditorWidget.h
+HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidget.h
+HEADERS +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidgetItem.h
+HEADERS +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidgetSplitDlg.h
+HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteProfile.h
+HEADERS += $$COMMON_PATH/utility/misc_funcs.h
+HEADERS += $$COMMON_PATH/utility/ImportExportDialog.h
+HEADERS += $$COMMON_PATH/utility/HelpDialog.h
+HEADERS += $$COMMON_PATH/gpl_related/gpldialog.h
+HEADERS += $$COMMON_PATH/plasma/PlasmaAlgorithm.h
+HEADERS += $$COMMON_PATH/core/opengl_main.h
+
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/Background.h
$$COMMON_PATH/2d_bgnd_w_lens/BackgroundProfile.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/ConfigManager.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/IndexedPaletteBackground.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/MasterProfile.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/globaldefs.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/ConfigWidget.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/project_specific_extern_defs.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/PaletteEditor.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/PaletteSelectWidget.h
+
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensProfile.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/GenericLensObject.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensObject.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensManager.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/SphericalLensProfile.h
+
+HEADERS += $$SOURCE_PATH/PlasmaFractalBackgroundProfile.h
$$SOURCE_PATH/PlasmaFractal.h
+HEADERS += $$RESOURCE_PATH/resource.h
+HEADERS += $$COMMON_PATH/utility/AboutDialog.h
+HEADERS += $$SOURCE_PATH/ProfileEditDialog.h
+
+TARGET = SpiralLenz_glut
+RESOURCES = $$RESOURCE_PATH/qt_resource.qrc
+
+win32:LIBS += user32.lib shell32.lib Advapi32.lib gdi32.lib scrnsavw.lib
opengl32.lib glu32.lib comctl32.lib
+
+unix:DESTDIR = ../../../bin
+unix:OBJECTS_DIR = ../compiled_objects
+unix:MOC_DIR = ../compiled_objects
+unix:LIBS += -lglut -lGL -lGLU -lX11 -lXmu -lXi -lm
=======================================
--- /dev/null
+++ /src/SpiralLenz/project_files/SpiralLenz_scr.pro Mon Mar 16 21:29:13
2009 UTC
@@ -0,0 +1,101 @@
+TEMPLATE = app
+win32:CONFIG += qt warn_on
+unix:CONFIG += qt x11 warn_on release
+QT += xml
+
+unix:COMMON_PATH = ../../common
+win32:COMMON_PATH = ../../../common
+
+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
+
+win32:SOURCES = $$COMMON_PATH/core/win_main.cpp
+unix:SOURCES = $$COMMON_PATH/core/unix_main.cpp
+SOURCES += $$COMMON_PATH/core/win_misc_funcs.cpp
+
+SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPalette.cpp
+SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialog.cpp
+SOURCES +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteDialogEntryButton.cpp
+SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPaletteEditorWidget.cpp
+SOURCES +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidget.cpp
+SOURCES +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidgetItem.cpp
+SOURCES +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidgetSplitDlg.cpp
+SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPaletteProfile.cpp
+SOURCES += $$COMMON_PATH/utility/misc_funcs.cpp
+SOURCES += $$COMMON_PATH/utility/ImportExportDialog.cpp
+SOURCES += $$COMMON_PATH/utility/HelpDialog.cpp
+SOURCES += $$COMMON_PATH/gpl_related/gpldialog.cpp
+SOURCES += $$COMMON_PATH/plasma/PlasmaAlgorithm.cpp
+
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/opengl_main.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/Background.cpp
$$COMMON_PATH/2d_bgnd_w_lens/BackgroundProfile.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/configdlg_main.cpp
$$COMMON_PATH/2d_bgnd_w_lens/ConfigManager.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/IndexedPaletteBackground.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/MasterProfile.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/PaletteEditor.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/PaletteSelectWidget.cpp
+
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensProfile.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/GenericLensObject.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensObject.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensManager.cpp
+SOURCES +=
$$COMMON_PATH/2d_bgnd_w_lens/lens_engine/SphericalLensProfile.cpp
+
+SOURCES += $$SOURCE_PATH/ConfigWidget.cpp $$SOURCE_PATH/PlasmaFractal.cpp
+SOURCES += $$SOURCE_PATH/PlasmaFractalBackgroundProfile.cpp
$$SOURCE_PATH/project_specific_externs.cpp
+SOURCES += $$COMMON_PATH/utility/AboutDialog.cpp
+SOURCES += $$SOURCE_PATH/ProfileEditDialog.cpp
+
+HEADERS = $$COMMON_PATH/core/win_misc_funcs.h
+
+HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPalette.h
+HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialog.h
+HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialogEntryButton.h
+HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteEditorWidget.h
+HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidget.h
+HEADERS +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidgetItem.h
+HEADERS +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidgetSplitDlg.h
+HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteProfile.h
+HEADERS += $$COMMON_PATH/utility/misc_funcs.h
+HEADERS += $$COMMON_PATH/utility/ImportExportDialog.h
+HEADERS += $$COMMON_PATH/utility/HelpDialog.h
+HEADERS += $$COMMON_PATH/gpl_related/gpldialog.h
+HEADERS += $$COMMON_PATH/plasma/PlasmaAlgorithm.h
+HEADERS += $$COMMON_PATH/core/opengl_main.h
+
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/Background.h
$$COMMON_PATH/2d_bgnd_w_lens/BackgroundProfile.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/ConfigManager.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/IndexedPaletteBackground.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/MasterProfile.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/globaldefs.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/ConfigWidget.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/project_specific_extern_defs.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/PaletteEditor.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/PaletteSelectWidget.h
+
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensProfile.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/GenericLensObject.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensObject.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensManager.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/SphericalLensProfile.h
+
+HEADERS += $$SOURCE_PATH/PlasmaFractalBackgroundProfile.h
$$SOURCE_PATH/PlasmaFractal.h
+HEADERS += $$RESOURCE_PATH/resource.h
+HEADERS += $$COMMON_PATH/utility/AboutDialog.h
+HEADERS += $$SOURCE_PATH/ProfileEditDialog.h
+unix:HEADERS += $$COMMON_PATH/include/vroot.h
+
+TARGET = SpiralLenz
+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:MOC_DIR = ../compiled_objects
+unix:LIBS += -lGL -lGLU -lX11 -lXmu -lXi -lm
=======================================
--- /dev/null
+++ /src/SpiralLenz/resource_files/app_icon.ico Mon Mar 16 21:29:13 2009 UTC
Binary file, no diff available.
=======================================
--- /dev/null
+++ /src/SpiralLenz/resource_files/app_icon.png Mon Mar 16 21:29:13 2009 UTC
Binary file, no diff available.
=======================================
--- /dev/null
+++ /src/SpiralLenz/resource_files/defaults.xml Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,111 @@
+<!DOCTYPE PlasmaLenz_Configuration>
+<PlasmaLenz_Configuration>
+ <BackgroundProfile>
+ <type>PlasmaFractalBackground</type>
+ <name>Classic RGB Profile</name>
+ <coarseness>4.5</coarseness>
+ <steps_per_tick>2048</steps_per_tick>
+ <anmiate_palette>true</anmiate_palette>
+ <palette_x_speed>1</palette_x_speed>
+ <palette_y_speed>1</palette_y_speed>
+ <clamp_color>true</clamp_color>
+ <palette>Classic RGB Palette</palette>
+ </BackgroundProfile>
+ <IndexedPaletteProfile>
+ <name>Classic RGB Palette</name>
+ <width>192</width>
+ <height>1</height>
+ <interpolate_colors>Linear</interpolate_colors>
+ <wrap_colors>true</wrap_colors>
+ <default_color>
+ <red>0</red>
+ <green>0</green>
+ <blue>0</blue>
+ </default_color>
+ <color_list>
+ <color_entry>
+ <red>255</red>
+ <green>0</green>
+ <blue>0</blue>
+ <alpha>255</alpha>
+ <x_coordinate>0</x_coordinate>
+ <y_coordinate>0</y_coordinate>
+ </color_entry>
+ <color_entry>
+ <red>0</red>
+ <green>255</green>
+ <blue>0</blue>
+ <alpha>255</alpha>
+ <x_coordinate>63</x_coordinate>
+ <y_coordinate>0</y_coordinate>
+ </color_entry>
+ <color_entry>
+ <red>0</red>
+ <green>0</green>
+ <blue>255</blue>
+ <alpha>255</alpha>
+ <x_coordinate>127</x_coordinate>
+ <y_coordinate>0</y_coordinate>
+ </color_entry>
+ </color_list>
+ </IndexedPaletteProfile>
+ <LensProfile>
+ <type>SphericalLensProfile</type>
+ <name>Sphere</name>
+ <palette_name>Default Lens Palette</palette_name>
+ <outline_width>2</outline_width>
+ <random_tint>false</random_tint>
+ <use_primary_tint>false</use_primary_tint>
+ <primary_tint_is_complement>false</primary_tint_is_complement>
+ <use_outline_tint>false</use_outline_tint>
+ <outline_tint_is_complement>true</outline_tint_is_complement>
+ <min_speed>2</min_speed>
+ <max_speed>6</max_speed>
+ <random_speed>true</random_speed>
+ <min_angle>0.785398</min_angle>
+ <max_angle>2.35619</max_angle>
+ <random_angle>true</random_angle>
+ <random_side>true</random_side>
+ <side_types>
+ <side_entry>
+ <side>Bottom</side>
+ <location>0</location>
+ </side_entry>
+ <side_entry>
+ <side>Top</side>
+ <location>1</location>
+ </side_entry>
+ <side_entry>
+ <side>Left</side>
+ <location>2</location>
+ </side_entry>
+ <side_entry>
+ <side>Right</side>
+ <location>3</location>
+ </side_entry>
+ </side_types>
+ <min_radius>0.075</min_radius>
+ <max_radius>0.15</max_radius>
+ <distortion_factor>0.75</distortion_factor>
+ <random_size>true</random_size>
+ <instances_max>5</instances_max>
+ </LensProfile>
+ <MasterProfile>
+ <name>Classic RGB</name>
+ <width>1024</width>
+ <height>1024</height>
+ <timer_millis>50</timer_millis>
+ <background_profile>Classic RGB Profile</background_profile>
+ <lens_profile>Sphere</lens_profile>
+ </MasterProfile>
+ <random_master_profiles>false</random_master_profiles>
+ <gpl_accepted>false</gpl_accepted>
+ <master_profile_history_size>3</master_profile_history_size>
+ <selected_master_profile_list>
+ <selected_entry>
+ <name>Classic RGB</name>
+ <location>0</location>
+ </selected_entry>
+ </selected_master_profile_list>
+</PlasmaLenz_Configuration>
+
=======================================
--- /dev/null
+++ /src/SpiralLenz/resource_files/html/MainDialog.jpg Mon Mar 16 21:29:13
2009 UTC
Binary file, no diff available.
=======================================
--- /dev/null
+++ /src/SpiralLenz/resource_files/html/PaletteEditorChooser.jpg Mon Mar 16
21:29:13 2009 UTC
Binary file, no diff available.
=======================================
--- /dev/null
+++ /src/SpiralLenz/resource_files/html/ProfileEditDialog.html Mon Mar 16
21:29:13 2009 UTC
@@ -0,0 +1,105 @@
+<HTML>
+<HEAD>
+<TITLE>Profile Editor</TITLE>
+</HEAD>
+<BODY>
+<H2>Profile Editor</H2><br>
+<img src="ProfileEditDialog.jpg" width="454" height="531" border="0"
alt="" align="middle">
+<h3>The Basics</h3>
+<p>Each profile contains several important options that the
+user is able to adjust. Before discussing these options, however,
+lets take a moment to go over the basics. In order to generate
+a plasma fractal, PlasmaLenz requires a palette of colors to use,
+the dimensions of the fractal to generate, and a factor of
+volatility. All three factor into how varied the fractals look,
+larger fractals with a larger number of different colors, and a
+larger factor of volatility will have more variation than
+smaller fractals with a fewer number of different colors and
+a smaller factor of volatility.</P>
+<p>After generating the plasma
+fractal, PlasmaLenz has the ability to rotate through the
+palette, which causes the fractal to look like its "flowing".
+Additionally, PlasmaLenz has the ability to add lens sprites to
+the screen, which create a nice "bubble" like effect.</p>
+<h3>The Nitty-Gritty</h3>
+<p>Here we will discuss the specifics of each parameter.</p>
+<ul><li><b>Width, Height</b> - These are the dimensions of the
+plasma, and required to be a power of 2, thus the drop-down
+boxes.</li>
+<li><b>Milliseconds Between Frames</b> - This parameter controls
+the number of milliseconds to wait before <i>starting</i> the
+next frame after the current frame is initiated. In other
+words, this is a lower bound on the rendering speed. If it
+takes your machine longer than the value of this parameter to
+render each scene, the result will be dropped frames. Smaller
+values for this parameter can result in smoother animation,
+if the machine can handle it. The
+maximum framerate can be calculated by dividing 1000
+by the value of this parameter. For example, for a value of
+50, the maximum framerate will be 1000 / 50 = 20 frames per
+second.</li>
+<li><b>Palette</b> - this is the palette to use to color the
+plasma fractal. Use the drop-down list to select one of
+the available palettes, or you can add a new palette by
+clicking the "Add" button to the right. Clicking the "Edit"
+button will edit the palette currently selected. For more
+information on palettes and the Palette Editor, please
+click <a href="IndexedPaletteDialog.html">here</a>. For
+more suggestions on designing a palette, please see below.</li>
+<li><b>Animate Palette</b> - When this box is checked,
+PlasmaLenz will rotate through the palette colors, creating
+a fluid-like animation.</li>
+<li><b>X Speed, Y Speed</b> - These parameters control the
+speed at which the palette is rotated through in the X (or
+primary) and Y (or secondary) directions. The larger
+the number, the quicker the rotation. A value of 1.0
+corresponds to stepping one color per frame.</li>
+<li><b>Volatility</b> - This slider controls the amount of
+variation, or volatility, within the plasma field.</li>
+<li><b>Clamp color on overflow</b> - When checked, this
+parameter will cause the plasma fractal to clamp to the endmost
+color when it exceeds an endpoint, as opposed to wrapping
+around to the other side.</li>
+<li><b>Number of Lenses</b> - This parameter controls the
+maximum number of lenses allowed on screen at any given time.
+The number of lenses on screen can be smaller than this
+number, but not larger.</li>
+<li><b>Size</b> - This parameter controls the size of the
+lenses. Size will determine the amount of warping the lens
+will cause.</li>
+<li><b>Variation</b> - This parameter controls how much
+variation there is in the size of the lenses. Moving
+the slider all the way to left to "Min" will result in all
+lenses having the same size.</li></ul>
+<h3>Palette Considerations</h3>
+<p>Palette design is a bit of an artform, but some guidelines
+that I stick to are as follows:</p>
+<ul><li>Stick to a small number of "key" colors, say 3-5.</li>
+<li>Keep a consistent amount of undefined colors between
+each "key" color, say 15 or 31.</li>
+<li>Utilize color interpolation and color wrapping.</li>
+<li>Have fun doing it!</li></ul>
+<h3>Performance</h3>
+<p>The two parameters that affect performance the most are
+the plasma dimensions and the number of milliseconds between
+frames. If the screen saver seems jerky, try increasing the
+number of milliseconds between frames and reducing the plasma
+dimensions. Raw CPU power is part of the equation, but the
+biggest bottleneck is the speed of your computer's front-side
+bus. For slower buses, reducing the dimensions of the
+plasma will have a huge effect. The number and size of the
+lenses will also have an effect on the speed, particularly
+for slower CPUs. Field volatility, the size of the
+palette, and the palette rotation speed won't have an effect
+on the frame rate at all, however
+larger palettes will "flow" more slowly, due to the larger
+number of colors to iterate through. This goes for
+2D palettes, also.</p>
+<h3>Where To Look For More Info</h3>
+<p>For more help, feel free to visit us at
+
http://sites.google.com/site/idlescreenproject/, where
+you can take advantage of the FAQS, Wiki, and user lists.</p>
+<hr>
+<a href="index.html">Back To the Main Page</a>
+</BODY>
+</HTML>
=======================================
--- /dev/null
+++ /src/SpiralLenz/resource_files/html/ProfileEditDialog.jpg Mon Mar 16
21:29:13 2009 UTC
Binary file, no diff available.
=======================================
--- /dev/null
+++ /src/SpiralLenz/resource_files/html/index.html Mon Mar 16 21:29:13 2009
UTC
@@ -0,0 +1,94 @@
+<html>
+<head>
+<title>PlasmaLenz Help</title>
+</head>
+<body>
+<h2>PlasmaLenz Help</h2><br>
+<img src="MainDialog.jpg" width="683" height="458" border="0" alt=""
align="middle">
+<h3>Profiles</h3>
+<P>PlasmaLenz is capable of maintaining multiple
+configuration profiles, which it will either
+randomly or sequentially select at each invocation.
+The box on the left of the
+dialog box contains the list of available profiles,
+and the box on the right contains the list of
+currently selected profiles. Profiles are added
+to the selected list by selecting them in the box
+on the list, and clicking the ">>" button. Clicking
+the "<<" button will remove any selected profiles
+in the box on the right. Pushing the "Up" button
+will move the currently selected profile in the box
+on the right up in the list, and the "Down" button
+will move the selected profile down in the list.
+Below the list of
+selected profiles is the check box to enable or
+disable random profile selection, as well as the
+field that determines the history size, or
+the number of profiles that must be used before
+a profile can be repeated.</p>
+<h3>Creating, Editing, and Deleting Profiles</h3>
+<p>To create a new profile, simply click the "New"
+button under the list of available profiles on
+the left. This will bring up the
+<a href="ProfileEditDialog.html">Profile Editor</a>
+dialog box with an empty profile.
+ To edit a profile, select the
+profile to edit in the box on the left and click
+the "Edit" button. This will open the
+<a href="ProfileEditDialog.html">Profile Editor</a>
+dialog box for the selected profile.
+Clicking delete will permanently delete the profile
+that is currently selected in the box on the left.
+For more information on the Profile Editor
+and the various profile settings, please
+click <a href="ProfileEditDialog.html">here</a>
+or on "Help" in the Profile Editor dialog box.</p>
+<h3>Palettes and the Palette Editor</h3><br>
+<img src="PaletteEditorChooser.jpg" width="392" height="364" border="0"
alt="" align="middle">
+<p>All configuration profiles contain references
+to a color palette. Palettes are separate entities,
+and multiple configuration profiles can reference
+the same palette. To create/edit/delete palettes
+without opening the
+<a href="ProfileEditDialog.html">Profile Editor</a>,
+simply click
+the "Palette Editor" button below the list of
+available profiles. This brings up a dialog that allows
+you to add new palettes, duplicate an existing
+palette, edit an existing palette, or delete a palette.
+Note that all palettes must have unique names. Clicking
+"Duplicate" will prompt you for a new, unique, name
+for the palette. Clicking on "New" or "Edit" will
+bring up the
+<a href="IndexedPaletteDialog.html">Palette Editor</a>.
+For mor information
+on the Palette Editor and on palettes, please click
+<a href="IndexedPaletteDialog.html">here</a> or
+on "Help" in the Palette Editor dialog box.
+For information on palette design considerations,
+please see refer to the help documentation for
+the <a href="ProfileEditDialog.html">Profile Editor</a>.</p>
+<h3>Importing and Exporting</h3>
+<p>PlasmaLenz allows you to import and export
+some or all of your profiles and palettes to an
+XML file. This allows you to backup, restore, and share
+your favorite settings with ease. To export your
+settings, simply click "Export Settings" on the right
+side of the dialog box, select the settings you wish
+to save, click "Export", then enter the name of
+the file to export to. To import settings, simply
+click on "Import Settings" on the right side of
+the dialog box, navigate to the file you wish to import,
+select the profiles and/or palettes to import, then
+click "Import".</p>
+<h3>Final Notes</h3>
+<p>If you make a mistake, take heart! None of the
+settings are actually saved to disk until you click
+"Ok" or "Apply". Clicking "Cancel" will abandon any and
+all changes you have made since the last save.</p>
+<h3>For More Information</h3>
+For more information, including a wiki, bug tracker, and
+program updates, please visit us at
+
http://sites.google.com/site/idlescreenproject!
+</body>
+</html>
=======================================
--- /dev/null
+++ /src/SpiralLenz/resource_files/qt_resource.qrc Mon Mar 16 21:29:13 2009
UTC
@@ -0,0 +1,15 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file alias="defaults.xml">defaults.xml</file>
+ <file alias="app_icon.png">app_icon.png</file>
+ <file alias="gplv2.txt">../../common/gpl_related/gplv2.txt</file>
+ <file alias="help/index.html">html/index.html</file>
+ <file alias="help/MainDialog.jpg">html/MainDialog.jpg</file>
+ <file
alias="help/PaletteEditorChooser.jpg">html/PaletteEditorChooser.jpg</file>
+ <file
alias="help/ProfileEditDialog.html">html/ProfileEditDialog.html</file>
+ <file alias="help/ProfileEditDialog.jpg">html/ProfileEditDialog.jpg</file>
+ <file
alias="help/IndexedPaletteDialog.html">../../common/IndexedPalette/resource_files/IndexedPaletteDialog.html</file>
+ <file
alias="help/IndexedPaletteDialog.jpg">../../common/IndexedPalette/resource_files/IndexedPaletteDialog.jpg</file>
+ <file
alias="help/InsertColorDialog.jpg">../../common/IndexedPalette/resource_files/InsertColorDialog.jpg</file>
+</qresource>
+</RCC>
=======================================
--- /dev/null
+++ /src/SpiralLenz/resource_files/resource.h Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,18 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by win_resource.rc
+//
+#define IDS_DESCRIPTION 1
+#define ID_APP 100
+#define DLG_SCRNSAVECONFIGURE 2003
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 103
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1001
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
=======================================
--- /dev/null
+++ /src/SpiralLenz/resource_files/win_resource.rc Mon Mar 16 21:29:13 2009
UTC
@@ -0,0 +1,97 @@
+// Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+DLG_SCRNSAVECONFIGURE DIALOGEX 0, 0, 195, 127
+STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_DISABLED | WS_CAPTION
+CAPTION "Property Page"
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ LTEXT "TODO: layout property page",IDC_STATIC,53,59,90,8
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Icon
+//
+
+// Icon with lowest ID value placed first to ensure application icon
+// remains consistent on all systems.
+ID_APP
ICON "../../resource_files/app_icon.ico"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// String Table
+//
+
+STRINGTABLE
+BEGIN
+ IDS_DESCRIPTION "SpiralLenz"
+END
+
+#endif // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
=======================================
--- /dev/null
+++ /src/SpiralLenz/src/ConfigWidget.cpp Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,689 @@
+/**
+ * Copyright (c) 2008 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/
+ *
+ */
+
+//begin debug
+//#include <iostream>
+//using namespace std;
+#include "2d_bgnd_w_lens/lens_engine/SphericalLensProfile.h"
+//end debug
+
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QPushButton>
+#include <QCheckBox>
+#include <QWidget>
+#include <QGroupBox>
+#include <QIcon>
+#include <QLabel>
+#include <QFileDialog>
+#include <QDir>
+
+//temp
+//#include <QMessageBox>
+//end temp
+
+#include "../../common/2d_bgnd_w_lens/ConfigWidget.h"
+#include "../../common/2d_bgnd_w_lens/PaletteEditor.h"
+#include "../../common/utility/ImportExportDialog.h"
+#include "../../common/utility/misc_funcs.h"
+#include "../../common/utility/AboutDialog.h"
+#include "../../common/utility/HelpDialog.h"
+#include "../../common/2d_bgnd_w_lens/project_specific_extern_defs.h"
+#include "ProfileEditDialog.h"
+
+//constructor & destructor
+ConfigWidget::ConfigWidget(QWidget* parent, Qt::WindowFlags f) {
+ QDialog(parent, f);
+
+ _manager = NULL;
+ _gplDialog = NULL;
+ _stackedLayout = NULL;
+ _mpAvailList = NULL;
+ _mpSelList = NULL;
+
+ _windowTitle = tr("PlasmaLenz Configuration");
+
+ setWindowTitle(_windowTitle);
+
+ QIcon icon(":/app_icon.png");
+ setWindowIcon(icon);
+}
+
+ConfigWidget::~ConfigWidget() {
+ _manager = NULL;
+
+ if(_gplDialog != NULL) {
+ delete _gplDialog;
+ _gplDialog = NULL;
+ }
+
+ if(_stackedLayout != NULL) {
+ delete _stackedLayout;
+ _stackedLayout = NULL;
+ }
+
+ if(_mpAvailList != NULL) {
+ delete _mpAvailList;
+ _mpAvailList = NULL;
+ }
+
+ if(_mpSelList != NULL) {
+ delete _mpSelList;
+ _mpSelList = NULL;
+ }
+
+ if(_historyBox != NULL) {
+ delete _historyBox;
+ _historyBox = NULL;
+ }
+}
+
+void ConfigWidget::setup(void) {
+
+ //precaution
+ if(_manager == NULL) {
+ emit dialogFinished();
+ }
+
+ _gplDialog = new GPLDialog(_manager->getGPLAccepted());
+
+ QWidget* tempWidget = NULL;
+ QPushButton* tempButton = NULL;
+ QLabel* tempLabel = NULL;
+ QVBoxLayout* mainLayout = new QVBoxLayout();
+
+ //Master Profile selection lists and related.
+ tempWidget = genMPWidget();
+ mainLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ // import/export/palette editor buttons
+ QHBoxLayout* midButtonsLayout = new QHBoxLayout();
+
+ tempButton = new QPushButton(tr("Palette Editor"));
+ tempButton->setToolTip(tr("Opens the palette editor."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(paletteEditorClicked(bool)));
+ midButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ midButtonsLayout->addStretch(0);
+
+ tempButton = new QPushButton(tr("Import Settings"));
+ tempButton->setToolTip(tr("Imports settings from a file."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(importClicked(bool)));
+ midButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempButton = new QPushButton(tr("Export Settings"));
+ tempButton->setToolTip(tr("Exports settings to a file."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(exportClicked(bool)));
+ midButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempWidget = new QWidget();
+ tempWidget->setLayout(midButtonsLayout);
+ mainLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ //About, Help, OK, Apply, and Cancel buttons
+ QHBoxLayout* botButtonsLayout = new QHBoxLayout();
+
+ tempButton = new QPushButton(tr("A&bout"));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(aboutClicked(bool)));
+ botButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempButton = new QPushButton(tr("&Help"));
+ tempButton->setDefault(false);
+ tempButton->setAutoDefault(false);
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(helpClicked(bool)));
+ botButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ botButtonsLayout->addStretch(0);
+
+ tempButton = new QPushButton(tr("&OK"));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(okClicked(bool)));
+ tempButton->setDefault(true);
+ botButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempButton = new QPushButton(tr("&Apply"));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(applyClicked(bool)));
+ botButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempButton = new QPushButton(tr("&Cancel"));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(cancelClicked(bool)));
+ botButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempWidget = new QWidget();
+ tempWidget->setLayout(botButtonsLayout);
+ mainLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ setLayout(mainLayout);
+
+ populateMPLists();
+
+}
+
+void ConfigWidget::setManager(ConfigManager* manager) {
+ _manager = manager;
+}
+
+void ConfigWidget::addListClicked(bool checked) {
+ if(_mpAvailList == NULL || _mpSelList == NULL)
+ return;
+
+ QList<QListWidgetItem*> itemList = _mpAvailList->selectedItems();
+ for(int i =0; i<itemList.size(); i++) {
+
if(_mpSelList->findItems(itemList.at(i)->text(),Qt::MatchExactly).empty()) {
+ _mpSelList->addItem(itemList.at(i)->text());
+ }
+ }
+}
+
+void ConfigWidget::removeListClicked(bool checked) {
+ if(_mpSelList == NULL)
+ return;
+
+ QList<QListWidgetItem*> list = _mpSelList->selectedItems();
+ for(int i=0;i<list.size(); i++) {
+ QListWidgetItem* tmp = _mpSelList->takeItem(_mpSelList->row(
list.at(i)));
+ delete tmp;
+ tmp = NULL;
+ }
+}
+
+void ConfigWidget::upListClicked(bool checked) {
+ if(_mpSelList == NULL)
+ return;
+
+ int row = _mpSelList->currentRow();
+ if(row > 0) {
+ _mpSelList->insertItem(row-1,_mpSelList->takeItem(row));
+ _mpSelList->setCurrentRow(row-1);
+ }
+}
+
+void ConfigWidget::downListClicked(bool checked) {
+ if(_mpSelList == NULL)
+ return;
+
+ int row = _mpSelList->currentRow();
+ if(row < _mpSelList->count()) {
+ _mpSelList->insertItem(row+1,_mpSelList->takeItem(row));
+ if(row+1 == _mpSelList->count()) {
+ _mpSelList->setCurrentRow(_mpSelList->count()-1);
+ } else {
+ _mpSelList->setCurrentRow(row+1);
+ }
+ }
+}
+
+void ConfigWidget::okClicked(bool checked) {
+ saveData();
+
+ emit dialogFinished();
+}
+
+void ConfigWidget::applyClicked(bool checked) {
+ saveData();
+}
+
+void ConfigWidget::cancelClicked(bool checked) {
+ emit dialogFinished();
+}
+
+void ConfigWidget::randomClicked(bool checked) {
+ _manager->setRandomProfile(checked);
+}
+
+void ConfigWidget::aboutClicked(bool checked) {
+ AboutDialog* dlg = new AboutDialog(getAppFullName(), getAppVersion());
+ if(dlg != NULL) {
+ dlg->exec();
+ delete dlg;
+ dlg = NULL;
+ }
+}
+
+//shows the GPL dialog
+void ConfigWidget::showGPLDialog(void) {
+ _gplDialog->exec();
+ _manager->setGPLAccepted(_gplDialog->isAccepted());
+ if(_manager->getGPLAccepted()) {
+ _manager->save();
+ }
+}
+
+void ConfigWidget::addMPClicked(bool checked) {
+
+ ProfileEditDialog* dlg = new ProfileEditDialog("", _manager);
+ QObject::connect(dlg, SIGNAL(profileNameChange(QString, QString)), this,
SLOT(profileNameChange(QString, QString)));
+ dlg->exec();
+}
+
+void ConfigWidget::editMPClicked(bool checked) {
+// QMessageBox::information(this, _windowTitle, "Not implemented yet.",
QMessageBox::Ok);
+
+ if(_mpAvailList == NULL)
+ return;
+
+ QList<QListWidgetItem*> list = _mpAvailList->selectedItems();
+ for(int i=0;i<list.size(); i++) {
+ QListWidgetItem* tmp = _mpAvailList->item(_mpAvailList->row(
list.at(i)));
+ ProfileEditDialog* dlg = new ProfileEditDialog(tmp->text(), _manager);
+ QObject::connect(dlg, SIGNAL(profileNameChange(QString, QString)), this,
SLOT(profileNameChange(QString, QString)));
+ dlg->exec();
+
+ //clean up
+ tmp = NULL;
+ delete dlg;
+ dlg = NULL;
+ }
+}
+
+void ConfigWidget::deleteMPClicked(bool checked) {
+ if(_mpAvailList == NULL)
+ return;
+
+ QList<QListWidgetItem*> list = _mpAvailList->selectedItems();
+ for(int i=0;i<list.size(); i++) {
+ // get the selected master profile
+ QListWidgetItem* tmp =
_mpAvailList->takeItem(_mpAvailList->row(
list.at(i)));
+ QString name = tmp->text();
+ delete tmp;
+ tmp = NULL;
+
+ //delete the background profile
+ MasterProfile tempMp = _manager->getProfile(name);
+ _manager->removeBackgroundProfile(tempMp.getBackgroundProfileName());
+
+ //delete the master profile
+ _manager->removeProfile(name);
+
+ //now remove the master profile from selected list, if it is in there.
+ int j=0;
+ bool bDone = false;
+ while(!bDone && j<_mpSelList->count()) {
+ tmp = _mpSelList->item(j);
+ if(tmp->text() == name) {
+ bDone = true;
+ _mpSelList->takeItem(j);
+ delete tmp;
+ tmp = NULL;
+ }
+
+ j++;
+ }
+ }
+}
+
+void ConfigWidget::advancedChecked(bool checked) {
+// nada
+}
+
+//clears and then populates both MasterProfile lists.
+void ConfigWidget::populateMPLists() {
+ if(_mpAvailList == NULL || _mpSelList == NULL)
+ return;
+
+ //available list
+ _mpAvailList->clear();
+ _mpAvailList->addItems(_manager->getAvailableProfiles());
+
+ //selected list
+ _mpSelList->clear();
+ _mpSelList->addItems(_manager->getSelectedProfiles());
+}
+
+//generates a widget that contains the available and selected
+//master profile lists as well as the requisite buttons.
+QWidget* ConfigWidget::genMPWidget() {
+ QWidget* tempWidget = NULL;
+ QPushButton* tempButton = NULL;
+
+ QVBoxLayout* mpLayout = new QVBoxLayout();
+
+ QHBoxLayout* listsLayout = new QHBoxLayout();
+
+ _mpAvailList = new QListWidget();
+ _mpAvailList->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ _mpAvailList->setToolTip(tr("This is the list of available configuration
profiles."));
+
+ listsLayout->addWidget(_mpAvailList);
+
+ QVBoxLayout* listButtonLayout = new QVBoxLayout();
+
+ tempButton = new QPushButton(">>");
+ tempButton->setToolTip(tr("Click to add the items selected in the list of
available configuration profiles")+"\n"
+ +tr("to the list of selected configuration profiles."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(addListClicked(bool)));
+ listButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempButton = new QPushButton("<<");
+ tempButton->setToolTip(tr("Click to remove the selected items in the list
of selected configuration profiles."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(removeListClicked(bool)));
+ listButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempButton = new QPushButton(tr("Up"));
+ tempButton->setToolTip(tr("Click to move the selected item in the list of
selected configuration profiles up in")+"\n"
+ +tr("the order."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(upListClicked(bool)));
+ listButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempButton = new QPushButton(tr("Down"));
+ tempButton->setToolTip(tr("Click to move the selected item in the list of
selected configuration profiles")+"\n"
+ +tr("down in the order."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(downListClicked(bool)));
+ listButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempWidget = new QWidget();
+ tempWidget->setLayout(listButtonLayout);
+ listsLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ _mpSelList = new QListWidget();
+ _mpSelList->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ _mpSelList->setToolTip(tr("This is the list of currently selected
configuration profiles."));
+ listsLayout->addWidget(_mpSelList);
+
+ tempWidget = new QWidget();
+ tempWidget->setLayout(listsLayout);
+ mpLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ //add/edit/delete buttons, stretch, history box
+ QHBoxLayout* bottomButtonLayout = new QHBoxLayout();
+
+ tempButton = new QPushButton(tr("New"));
+ tempButton->setToolTip(tr("Click to add a new configuration profile."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(addMPClicked(bool)));
+ bottomButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempButton = new QPushButton(tr("Edit"));
+ tempButton->setToolTip(tr("Click to edit the currently selected
configuration profile."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(editMPClicked(bool)));
+ bottomButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempButton = new QPushButton(tr("Delete"));
+ tempButton->setToolTip(tr("Click to permanently remove the currently
selected configuration profile."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(deleteMPClicked(bool)));
+ bottomButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ bottomButtonLayout->addStretch(0);
+
+ //history box
+ QGroupBox* randomBox = new QGroupBox(tr("Choose &Randomly"));
+ randomBox->setCheckable(true);
+ randomBox->setChecked(_manager->isRandomProfile());
+ randomBox->setToolTip(tr("Enabling this will randomize the order in which
the configuration profiles will run."));
+ QObject::connect(randomBox, SIGNAL(clicked(bool)), this,
SLOT(randomClicked(bool)));
+
+ QHBoxLayout* historyLayout = new QHBoxLayout();
+ QLabel* historyLabel = new QLabel(tr("Size of History"));
+ historyLabel->setToolTip(tr("The number of times before a configuration
profile can run again."));
+ historyLayout->addWidget(historyLabel);
+
+ _historyBox = new QSpinBox();
+ _historyBox->setRange(0,10);
+ _historyBox->setSingleStep(1);
+ _historyBox->setValue(_manager->getProfileHistorySize());
+ _historyBox->setToolTip(tr("The number of times before a configuration
profile can run again."));
+ historyLayout->addWidget(_historyBox);
+
+ randomBox->setLayout(historyLayout);
+ bottomButtonLayout->addWidget(randomBox);
+
+ tempWidget = new QWidget();
+ tempWidget->setLayout(bottomButtonLayout);
+ mpLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ tempWidget = new QWidget();
+ tempWidget->setLayout(mpLayout);
+ return tempWidget;
+}
+
+//saves all data back to the configuration manager
+void ConfigWidget::saveData() {
+ //update list of selected profiles
+ if(_mpSelList != NULL) {
+ QStringList retVal;
+ for(int i=0;i<_mpSelList->count();i++) {
+ QListWidgetItem* tmp = _mpSelList->item(i);
+ if(tmp != NULL) {
+ retVal.append(tmp->text());
+ }
+ }
+ _manager->setSelectedProfiles(retVal);
+ }
+
+ //update history size
+ _manager->setProfileHistorySize(_historyBox->value());
+
+ _manager->save();
+}
+void ConfigWidget::profileNameChange(QString oldName, QString newName) {
+ if(_mpAvailList == NULL)
+ return;
+
+ if(oldName != newName) {
+ //it is an addition. Append to the available list.
+ if(oldName == "") {
+ _mpAvailList->addItem(newName);
+ } else {
+ //otherwise, we're replacing.
+
+ //search the list for the old name, remove it and
+ //insert the new one in the same position.
+ int j=0;
+ bool bDone = false;
+ while(!bDone && j < _mpAvailList->count()) {
+ QListWidgetItem* tmp = _mpAvailList->item(j);
+ if(tmp->text() == oldName) {
+ bDone = true;
+ //remove
+ _mpAvailList->takeItem(j);
+ delete tmp;
+ tmp = NULL;
+
+ //insert
+ _mpAvailList->insertItem(j, newName);
+ }
+
+ j++;
+ }
+ // repeat on the list of selected items
+ j=0;
+ bDone = false;
+ while(!bDone &&j<_mpSelList->count()) {
+ QListWidgetItem* tmp = _mpSelList->item(j);
+ if(tmp->text() == oldName) {
+ bDone = true;
+ //remove
+ _mpSelList->takeItem(j);
+ delete tmp;
+ tmp = NULL;
+
+ //insert
+ _mpSelList->insertItem(j, newName);
+ }
+ j++;
+ }
+ }
+ }
+}
+
+void ConfigWidget::importClicked(bool checked) {
+// QMessageBox::information(this, _windowTitle, "Not implemented yet.",
QMessageBox::Ok);
+ ImportExportDialog dlg(true);
+
+ // get file name to import from
+ QString filename = QFileDialog::getOpenFileName(this, tr("Import Settings
From File"), QDir::homePath(),
+ tr("Settings Files (*.xml)"));
+
+ if(filename.isEmpty())
+ return;
+
+ // create a temporary config manager and load
+ // it with data from the import file.
+ ConfigManager* tmpMgr = new ConfigManager();
+ if(tmpMgr == NULL)
+ return;
+ tmpMgr->importFromFile(filename, false);
+
+ // populate dialog box
+ QStringList bkgnds = tmpMgr->getAvailableProfiles();
+ dlg.addSubItems("Configuration Profiles", bkgnds, true);
+
+ QStringList palettes = tmpMgr->getPaletteNames();
+ dlg.addSubItems("Palettes", palettes, true);
+
+ // show dialog and get lists of checked items
+ if(dlg.exec() == QDialog::Rejected) {
+ delete tmpMgr;
+ tmpMgr = NULL;
+ return;
+ }
+ bkgnds = dlg.getSubItems("Configuration Profiles", true);
+ palettes = dlg.getSubItems("Palettes", true);
+
+ // first, add in the palettes, since they don't
+ // have any dependencies
+ for(int i = 0; i<palettes.size(); i++) {
+ IndexedPaletteProfile tmpPal = tmpMgr->getPaletteProfile(
palettes.at(i));
+ _manager->addPalette(tmpPal);
+ }
+
+ // now go through the MasterProfiles, adding sub profiles
+ // it requires (including IndexedPaletteProfiles).
+ for(int i = 0; i<bkgnds.size(); i++) {
+ MasterProfile tmpMp = tmpMgr->getProfile(
bkgnds.at(i));
+ // make sure the master profile doesn't exist, so that we don't
+ // unnecessarily the other things. No need to check everything else
+ // since the respective add routines will check before appending
+ // to the lists.
+ if(!_manager->doesProfileExist(tmpMp.getName())) {
+ LensProfile* tmpLens =
tmpMgr->getLensProfile(tmpMp.getLensProfileName());
+ _manager->addLensProfile(tmpLens);
+ //debug?
+ tmpLens = NULL;
+ //end debug
+ PlasmaFractalBackgroundProfile* tmpBkgnd =
(PlasmaFractalBackgroundProfile*)tmpMgr->getBackgroundProfile(tmpMp.getBackgroundProfileName());
+ IndexedPaletteProfile tmpPal =
tmpMgr->getPaletteProfile(tmpBkgnd->getPaletteName());
+ _manager->addPalette(tmpPal);
+ _manager->addBackgroundProfile(*tmpBkgnd);
+ _manager->addProfile(tmpMp);
+ _mpAvailList->addItem(tmpMp.getName());
+ }
+ }
+}
+
+void ConfigWidget::exportClicked(bool checked) {
+ ImportExportDialog dlg(false);
+
+ // populate dialog box
+ QStringList bkgnds = _manager->getAvailableProfiles();
+ dlg.addSubItems("Configuration Profiles", bkgnds, true);
+
+ QStringList palettes = _manager->getPaletteNames();
+ dlg.addSubItems("Palettes", palettes, true);
+
+ // show dialog and get lists of checked items
+ if(dlg.exec() == 0)
+ return;
+ bkgnds = dlg.getSubItems("Configuration Profiles", true);
+ palettes = dlg.getSubItems("Palettes", true);
+
+ // get file name to export to
+ QString filename = QFileDialog::getSaveFileName(this, tr("Export Settings
to File"), QDir::homePath(),
+ tr("Settings Files (*.xml)"));
+
+ if(filename.isEmpty())
+ return;
+
+ // now create a temporary config manager that
+ // contains only the profiles that we want. Be sure to grab
+ // all miscellaneous profiles that the MasterProfile
+ // (including the IndexedPaletteProfiles).
+ ConfigManager* tmpMgr = new ConfigManager();
+ if(tmpMgr == NULL)
+ return;
+
+ // first, add in the palettes, since they don't
+ // have any dependencies
+ for(int i = 0; i<palettes.size(); i++) {
+ IndexedPaletteProfile tmpPal =
_manager->getPaletteProfile(
palettes.at(i));
+ tmpMgr->addPalette(tmpPal);
+ }
+
+ // now go through the MasterProfiles, adding sub profiles
+ // it requires (including IndexedPaletteProfiles).
+ for(int i = 0; i<bkgnds.size(); i++) {
+ MasterProfile tmpMp = _manager->getProfile(
bkgnds.at(i));
+ LensProfile* tmpLens =
_manager->getLensProfile(tmpMp.getLensProfileName());
+ tmpMgr->addLensProfile(tmpLens);
+ //debug?
+ tmpLens = NULL;
+ //debug?
+ PlasmaFractalBackgroundProfile* tmpBkgnd =
(PlasmaFractalBackgroundProfile*)_manager->getBackgroundProfile(tmpMp.getBackgroundProfileName());
+ IndexedPaletteProfile tmpPal =
_manager->getPaletteProfile(tmpBkgnd->getPaletteName());
+ tmpMgr->addPalette(tmpPal);
+ tmpMgr->addBackgroundProfile(*tmpBkgnd);
+ tmpMgr->addProfile(tmpMp);
+ }
+
+ // save!
+ tmpMgr->exportToFile(filename, false);
+ delete tmpMgr;
+ tmpMgr = NULL;
+}
+
+void ConfigWidget::paletteEditorClicked(bool checked) {
+ PaletteEditor* dlg = new PaletteEditor(_manager, this);
+ dlg->exec();
+
+ //clean up
+ delete dlg;
+ dlg = NULL;
+}
+void ConfigWidget::helpClicked(bool checked) {
+ HelpDialog* dlg = new HelpDialog("qrc:/help/index.html");
+ if(dlg != NULL) {
+ dlg->exec();
+ delete dlg;
+ dlg = NULL;
+ }
+}
=======================================
--- /dev/null
+++ /src/SpiralLenz/src/ProfileEditDialog.cpp Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,823 @@
+/**
+ * Copyright (c) 2008 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 <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QPushButton>
+#include <QGroupBox>
+#include <QLabel>
+
+#include <QMessageBox>
+
+#include "ProfileEditDialog.h"
+#include "2d_bgnd_w_lens/lens_engine/SphericalLensProfile.h"
+#include "utility/misc_funcs.h"
+#include "utility/HelpDialog.h"
+
+ProfileEditDialog::ProfileEditDialog(QString targetName, ConfigManager*
confMgr, QWidget* parent, Qt::WindowFlags f) {
+ QDialog(parent, f);
+
+ _coarsenessAdjust = 100.0;
+ _nameBox = NULL;
+ _timerBox = NULL;
+ _screenXBox = NULL;
+ _screenYBox = NULL;
+ _coarsenessBox = NULL;
+ _paletteBox = NULL;
+ _paletteXSpeedBox = NULL;
+ _paletteYSpeedBox = NULL;
+ _clampColorBox = NULL;
+ _palDlg = NULL;
+ _lensSizeSlider = NULL;
+ _lensVarSlider = NULL;
+ _numLenses = NULL;
+
+ _confMgr = confMgr;
+
+ if(confMgr == NULL)
+ return;
+
+ _windowTitle = tr("Profile Editor");
+
+ setWindowTitle(_windowTitle);
+ setWindowModality(Qt::WindowModal);
+ QIcon icon(":/app_icon.png");
+ setWindowIcon(icon);
+
+ _oldName = targetName;
+ if(targetName != "") {
+ _mp = _confMgr->getProfile(targetName);
+ }
+
+ //set up dialog box
+ QWidget* tempWidget = NULL;
+ QPushButton* tempButton = NULL;
+ QVBoxLayout* mainLayout = new QVBoxLayout();
+ QString tempToolTip;
+
+ // Begin MasterProfile related.
+ // Note: MasterProfiles & BackgroundProfiles are
+ // collectively called "Configuration Profiles"
+ // throughout the program (i.e. that's what the
+ // user sees.)
+
+ //name field
+ QHBoxLayout* nameLayout = new QHBoxLayout();
+
+ tempToolTip = tr("The name of this configuration profile.");
+
+ tempWidget = new QLabel(tr("Name:"));
+ tempWidget->setToolTip(tempToolTip);
+ nameLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ _nameBox = new QLineEdit(_mp.getName());
+ _nameBox->setToolTip(tempToolTip);
+ nameLayout->addWidget(_nameBox);
+
+ tempWidget = new QWidget();
+ tempWidget->setLayout(nameLayout);
+ mainLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ //timer and dimensions
+ QHBoxLayout* dimAndTimeLayout = new QHBoxLayout();
+
+ //dimensions group box
+ QGroupBox* dimBox = new QGroupBox(tr("Plasma Dimensions"));
+ QHBoxLayout* dimBoxLayout = new QHBoxLayout();
+
+ _screenXBox = new QComboBox();
+ _screenYBox = new QComboBox();
+
+ _screenXBox->setEditable(false);
+ _screenXBox->setEditable(false);
+
+ //populate the combo box with powers of 2
+ int val = 64; //2^6
+ int xCurVal = 0;
+ int yCurVal = 0;
+ for(int i=0;i<13-6;i++) {
+ _screenXBox->addItem(QString::number(val));
+ _screenYBox->addItem(QString::number(val));
+ if(val <= _mp.getScreenHeight()) {
+ yCurVal=i;
+ }
+ if(val <= _mp.getScreenWidth()) {
+ xCurVal=i;
+ }
+ val*=2;
+ }
+
+ _screenXBox->setCurrentIndex(xCurVal);
+ _screenYBox->setCurrentIndex(yCurVal);
+
+ tempToolTip = tr("The resolution width of the plasma in pixels. Does not
need to match actual")+"\n"
+ +tr("screen resolution.");
+ tempWidget = new QLabel(tr("Width:"));
+ tempWidget->setToolTip(tempToolTip);
+ dimBoxLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+ _screenXBox->setToolTip(tempToolTip);
+ dimBoxLayout->addWidget(_screenXBox);
+
+ dimBoxLayout->addStretch(0);
+
+ tempToolTip = tr("The resolution height of the plasma in pixels. Does
not need to match actual")+"\n"
+ +tr("screen resolution.");
+ tempWidget = new QLabel(tr("Height:"));
+ tempWidget->setToolTip(tempToolTip);
+ dimBoxLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+ _screenYBox->setToolTip(tempToolTip);
+ dimBoxLayout->addWidget(_screenYBox);
+
+ dimBox->setLayout(dimBoxLayout);
+ dimAndTimeLayout->addWidget(dimBox);
+ tempWidget = NULL;
+
+ dimAndTimeLayout->addStretch(0);
+
+ tempWidget = new QLabel(tr("Milliseconds Between Frames:"));
+ tempToolTip = tr("The number of milliseconds between frames. The higher
the number, the")+"\n"
+ +tr("slower the animation.");
+ tempWidget->setToolTip(tempToolTip);
+ dimAndTimeLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ _timerBox = new QSpinBox();
+
+ _timerBox = new QSpinBox();
+ _timerBox->setRange(10,1000);
+ _timerBox->setSingleStep(10);
+ _timerBox->setValue(_mp.getTimerMillis());
+ _timerBox->setToolTip(tempToolTip);
+ dimAndTimeLayout->addWidget(_timerBox);
+
+ tempWidget = new QWidget();
+ tempWidget->setLayout(dimAndTimeLayout);
+ mainLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ // Begin PlasmaFractalBackgroundProfile related
+
+ // get the backgroundprofile in order to populate the data fields.
+ PlasmaFractalBackgroundProfile* plasmaProfile = NULL;
+ QString bkgndProfileName = _mp.getBackgroundProfileName();
+ if(_confMgr->doesBackgroundProfileExist(bkgndProfileName)) {
+ plasmaProfile = new PlasmaFractalBackgroundProfile();
+ if(plasmaProfile != NULL) {
+ PlasmaFractalBackgroundProfile* tempProfile =
(PlasmaFractalBackgroundProfile*)
(_confMgr->getBackgroundProfile(bkgndProfileName));
+ *plasmaProfile = *tempProfile;
+ _bAnimatePalette = plasmaProfile->getAnimatePalette();
+ }
+ }
+
+ // palette name combo box + add & edit buttons
+ QGroupBox* palGroupBox = new QGroupBox(tr("Palette"));
+ if(palGroupBox == NULL)
+ return;
+ palGroupBox->setCheckable(false);
+ palGroupBox->setFlat(false);
+
+ QHBoxLayout* palBoxLayout = new QHBoxLayout();
+
+ _paletteBox = new QComboBox();
+ _paletteBox->setEditable(false);
+ if(plasmaProfile != NULL) {
+ populatePalList(plasmaProfile->getPaletteName());
+ } else {
+ populatePalList("");
+ }
+ tempToolTip = tr("The currently selected palette.");
+ _paletteBox->setToolTip(tempToolTip);
+ palBoxLayout->addWidget(_paletteBox);
+
+ palBoxLayout->addStretch(0);
+
+ tempButton = new QPushButton(tr("&Add"));
+ tempButton->setDefault(false);
+ tempButton->setAutoDefault(false);
+ tempToolTip = tr("Add a new palette.");
+ tempButton->setToolTip(tempToolTip);
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(addPalClicked(bool)));
+ palBoxLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempButton = new QPushButton(tr("&Edit"));
+ tempButton->setDefault(false);
+ tempButton->setAutoDefault(false);
+ tempToolTip = tr("Edit the selected palette.");
+ tempButton->setToolTip(tempToolTip);
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(editPalClicked(bool)));
+ palBoxLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ palGroupBox->setLayout(palBoxLayout);
+ mainLayout->addWidget(palGroupBox);
+ tempWidget = NULL;
+
+ // Palette Animation enable and speeds
+ QGroupBox* animPalBox = new QGroupBox(tr("Animate Palette"));
+ animPalBox->setCheckable(true);
+ animPalBox->setChecked(_bAnimatePalette);
+ animPalBox->setFlat(false);
+ animPalBox->setToolTip(tr("This will enable rotating the palette in both
the X and Y directions by the specified speed."));
+ QObject::connect(animPalBox, SIGNAL(clicked(bool)), this,
SLOT(animatePalClicked(bool)));
+
+ QHBoxLayout* animPalLayout = new QHBoxLayout();
+ tempWidget = new QLabel(tr("X Speed:"));
+ tempToolTip = tr("This is how fast the palette will change in the X
(primary) direction.");
+ tempWidget->setToolTip(tempToolTip);
+ animPalLayout->addWidget(tempWidget);
+
+ _paletteXSpeedBox = new QDoubleSpinBox();
+ _paletteXSpeedBox->setDecimals(1);
+ _paletteXSpeedBox->setMinimum(0.0);
+ _paletteXSpeedBox->setSingleStep(0.1);
+ if(plasmaProfile != NULL) {
+ _paletteXSpeedBox->setValue(plasmaProfile->getPaletteXSpeed());
+ } else {
+ _paletteXSpeedBox->setValue(1.0);
+ }
+ _paletteXSpeedBox->setToolTip(tempToolTip);
+ animPalLayout->addWidget(_paletteXSpeedBox);
+
+ animPalLayout->addStretch(0);
+
+ tempWidget = new QLabel(tr("Y Speed:"));
+ tempToolTip = tr("This is how fast the palette will change in the Y
(secondary) direction.");
+ tempWidget->setToolTip(tempToolTip);
+ animPalLayout->addWidget(tempWidget);
+
+ _paletteYSpeedBox = new QDoubleSpinBox();
+ _paletteYSpeedBox->setDecimals(1);
+ _paletteYSpeedBox->setMinimum(0.0);
+ _paletteYSpeedBox->setSingleStep(0.1);
+ if(plasmaProfile != NULL) {
+ _paletteYSpeedBox->setValue(plasmaProfile->getPaletteYSpeed());
+ } else {
+ _paletteYSpeedBox->setValue(1.0);
+ }
+ _paletteYSpeedBox->setToolTip(tempToolTip);
+ animPalLayout->addWidget(_paletteYSpeedBox);
+
+ animPalBox->setLayout(animPalLayout);
+ mainLayout->addWidget(animPalBox);
+
+ QGroupBox* fieldBox = new QGroupBox(tr("Field Generation"));
+ if(fieldBox == NULL)
+ return;
+ fieldBox->setCheckable(false);
+ fieldBox->setFlat(false);
+
+ QHBoxLayout* ccLayout = new QHBoxLayout();
+
+ tempWidget = new QLabel(tr("Less Volatile"));
+ tempToolTip = tr("This quantity determines how coarse or volatile the
fractal is. More volatile, the more variation.");
+ tempWidget->setToolTip(tempToolTip);
+ ccLayout->addWidget(tempWidget);
+
+ _coarsenessBox = new QSlider(Qt::Horizontal);
+ _coarsenessBox->setTickInterval(0.10*_coarsenessAdjust);
+ //_coarsenessBox->setTickPosition(QSlider::TicksBelow);
+ _coarsenessBox->setMinimum(0.01*_coarsenessAdjust);
+ _coarsenessBox->setMaximum(6.00*_coarsenessAdjust);
+ if(plasmaProfile != NULL) {
+
_coarsenessBox->setValue(plasmaProfile->getCoarseness()*_coarsenessAdjust);
+ } else {
+ _coarsenessBox->setValue(4.50*_coarsenessAdjust);
+ }
+ _coarsenessBox->setToolTip(tempToolTip);
+ ccLayout->addWidget(_coarsenessBox);
+
+ tempWidget = new QLabel(tr("More Volatile"));
+ tempWidget->setToolTip(tempToolTip);
+ ccLayout->addWidget(tempWidget);
+
+ ccLayout->addStretch(0);
+
+ _clampColorBox = new QCheckBox(tr("Clamp color on overflow"));
+ if(plasmaProfile != NULL) {
+ _clampColorBox->setChecked(plasmaProfile->getClampColorIndex());
+ } else {
+ _clampColorBox->setChecked(true);
+ }
+ _clampColorBox->setToolTip(tr("When the plasma algorithm generates an
invalid color index, it will clamp")+"\n"
+ +tr("to the nearest valid color if checked, or wrap around if
unchecked."));
+ ccLayout->addWidget(_clampColorBox);
+
+ fieldBox->setLayout(ccLayout);
+ mainLayout->addWidget(fieldBox);
+ tempWidget = NULL;
+
+ // Begin SphericalLensProfile related
+ _numLenses = new QSpinBox();
+ if(_numLenses == NULL)
+ return;
+ _numLenses->setMinimum(0);
+ _numLenses->setMaximum(100);
+ _lensSizeSlider = new QSlider(Qt::Horizontal);
+ if(_lensSizeSlider == NULL)
+ return;
+ _lensVarSlider = new QSlider(Qt::Horizontal);
+ if(_lensVarSlider == NULL)
+ return;
+ _lensSizeSlider->setMinimum(1);
+ _lensSizeSlider->setMaximum(50);
+ _lensVarSlider->setMinimum(0);
+ _lensVarSlider->setMaximum(100);
+ _lensSizeSlider->setTickInterval(1);
+ _lensVarSlider->setTickInterval(1);
+
+ QString lensProfileName = _mp.getLensProfileName();
+
+ if(!lensProfileName.isEmpty()) {
+ SphericalLensProfile* lp =
(SphericalLensProfile*)_confMgr->getLensProfile(lensProfileName);
+
+ _numLenses->setValue(lp->getMaxNumLenses());
+ float maxR = lp->getMaxRadius();
+ float avgR = (lp->getMinRadius()+maxR)/2.0;
+ _lensSizeSlider->setValue(avgR*100.0);
+ _lensVarSlider->setValue( (maxR-avgR)*100.0/avgR);
+ } else {
+ _numLenses->setValue(0);
+ _lensSizeSlider->setValue(1);
+ _lensVarSlider->setValue(0);
+ }
+
+ QHBoxLayout* tmpHBox = NULL;
+ QVBoxLayout* tmpVBox = NULL;
+ QGroupBox* lensBox = new QGroupBox(tr("Lenses"));
+ if(lensBox == NULL)
+ return;
+ lensBox->setFlat(false);
+ lensBox->setCheckable(false);
+ QHBoxLayout* lensLayout = new QHBoxLayout();
+ if(lensLayout == NULL)
+ return;
+
+ tempToolTip = tr("Determines the maximum number of lenses on screen at
one time.");
+ tempWidget = new QLabel(tr("Number:"));
+ tempWidget->setToolTip(tempToolTip);
+ lensLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+ _numLenses->setToolTip(tempToolTip);
+ lensLayout->addWidget(_numLenses);
+
+ lensLayout->addStretch(0);
+
+ tmpVBox = new QVBoxLayout();
+ if(tmpVBox == NULL)
+ return;
+ tmpHBox = new QHBoxLayout();
+ if(tmpHBox == NULL)
+ return;
+
+ tempToolTip = tr("Determines the average size of the lenses.");
+ tempWidget = new QLabel(tr("Size"));
+ if(tempWidget == NULL)
+ return;
+ tempWidget->setToolTip(tempToolTip);
+ tmpHBox->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ tmpHBox->addStretch(0);
+
+ tempWidget = new QLabel(tr("Min"));
+ if(tempWidget == NULL)
+ return;
+ tempWidget->setToolTip(tempToolTip);
+ tmpHBox->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ _lensSizeSlider->setToolTip(tempToolTip);
+ tmpHBox->addWidget(_lensSizeSlider);
+
+ tempWidget = new QLabel(tr("Max"));
+ if(tempWidget == NULL)
+ return;
+ tempWidget->setToolTip(tempToolTip);
+ tmpHBox->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ tempWidget = new QWidget();
+ tempWidget->setLayout(tmpHBox);
+ tmpVBox->addWidget(tempWidget);
+ tempWidget = NULL;
+ tmpHBox = NULL;
+
+ tmpHBox = new QHBoxLayout();
+ if(tmpHBox == NULL)
+ return;
+
+ tempToolTip = tr("Determines the amount of size variation.");
+ tempWidget = new QLabel(tr("Variation"));
+ if(tempWidget == NULL)
+ return;
+ tempWidget->setToolTip(tempToolTip);
+ tmpHBox->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ tmpHBox->addStretch(0);
+
+ tempWidget = new QLabel(tr("Min"));
+ if(tempWidget == NULL)
+ return;
+ tempWidget->setToolTip(tempToolTip);
+ tmpHBox->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ _lensVarSlider->setToolTip(tempToolTip);
+ tmpHBox->addWidget(_lensVarSlider);
+
+ tempWidget = new QLabel(tr("Max"));
+ if(tempWidget == NULL)
+ return;
+ tempWidget->setToolTip(tempToolTip);
+ tmpHBox->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ tempWidget = new QWidget();
+ tempWidget->setLayout(tmpHBox);
+ tmpVBox->addWidget(tempWidget);
+ tempWidget = NULL;
+ tmpHBox = NULL;
+
+ tempWidget = new QWidget();
+ tempWidget->setLayout(tmpVBox);
+ lensLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ lensBox->setLayout(lensLayout);
+ mainLayout->addWidget(lensBox);
+
+ //Help, OK and Cancel buttons
+ QHBoxLayout* botButtonsLayout = new QHBoxLayout();
+
+ tempButton = new QPushButton(tr("&Help"));
+ tempButton->setDefault(false);
+ tempButton->setAutoDefault(false);
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(helpClicked(bool)));
+ botButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ botButtonsLayout->addStretch(0);
+
+ tempButton = new QPushButton(tr("&OK"));
+ tempButton->setDefault(true);
+ tempButton->setAutoDefault(true);
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(okClicked(bool)));
+ botButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempButton = new QPushButton(tr("&Cancel"));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(cancelClicked(bool)));
+ botButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
+
+ tempWidget = new QWidget();
+ tempWidget->setLayout(botButtonsLayout);
+ mainLayout->addWidget(tempWidget);
+ tempWidget = NULL;
+
+ setLayout(mainLayout);
+}
+
+ProfileEditDialog::~ProfileEditDialog() {
+ _confMgr = NULL;
+
+ if(_nameBox != NULL) {
+ delete _nameBox;
+ _nameBox = NULL;
+ }
+
+ if(_timerBox != NULL) {
+ delete _timerBox;
+ _timerBox = NULL;
+ }
+
+ if(_screenXBox != NULL) {
+ delete _screenXBox;
+ _screenXBox = NULL;
+ }
+
+ if(_screenYBox != NULL) {
+ delete _screenYBox;
+ _screenYBox = NULL;
+ }
+
+ if(_coarsenessBox != NULL) {
+ delete _coarsenessBox;
+ _coarsenessBox = NULL;
+ }
+
+ if(_paletteBox != NULL) {
+ delete _paletteBox;
+ _paletteBox = NULL;
+ }
+
+ if(_paletteXSpeedBox != NULL) {
+ delete _paletteXSpeedBox;
+ _paletteXSpeedBox = NULL;
+ }
+
+ if(_paletteYSpeedBox != NULL) {
+ delete _paletteYSpeedBox;
+ _paletteYSpeedBox = NULL;
+ }
+
+ if(_clampColorBox != NULL) {
+ delete _clampColorBox;
+ _clampColorBox = NULL;
+ }
+ if(_palDlg != NULL) {
+ delete _palDlg;
+ _palDlg = NULL;
+ }
+ if(_lensSizeSlider != NULL) {
+ delete _lensSizeSlider;
+ _lensSizeSlider = NULL;
+ }
+ if(_lensVarSlider != NULL) {
+ delete _lensVarSlider;
+ _lensVarSlider = NULL;
+ }
+ if(_numLenses != NULL) {
+ delete _numLenses;
+ _numLenses = NULL;
+ }
+}
+
+void ProfileEditDialog::okClicked(bool checked) {
+
+ /** !!!!!!!!!!!! NOTE !!!!!!!!!
+ * This code needs modified to handle the BackgroundProfile and
LensProfile
+ * modifications/additions.
+ */
+
+ if(_confMgr == NULL)
+ return;
+
+ //update data in local copy
+
+ // BackgroundProfile related
+ // populate data fields
+ if(_paletteBox->currentIndex() < 0) {
+ QMessageBox::warning(this, _windowTitle, "Please choose a palette from
the drop-down box.", QMessageBox::Ok);
+ return;
+ }
+
+ PlasmaFractalBackgroundProfile tmpProfile;
+ tmpProfile.setAnimatePalette(_bAnimatePalette);
+ tmpProfile.setClampColorIndex(_clampColorBox->isChecked());
+
tmpProfile.setCoarseness(((float)_coarsenessBox->value())/_coarsenessAdjust);
+ tmpProfile.setGenStepsPerTick(2048);
+ tmpProfile.setPaletteXSpeed(_paletteXSpeedBox->value());
+ tmpProfile.setPaletteYSpeed(_paletteYSpeedBox->value());
+ tmpProfile.setPaletteName(_paletteBox->currentText());
+
+ // check for an existing BackgroundProfile. If none
+ // create a new one, otherwise update the current one.
+ QString tempName = _mp.getBackgroundProfileName();
+ if(tempName == "" || !_confMgr->doesBackgroundProfileExist(tempName)) {
+ // generate a random BackgroundProfile name that doesn't exist.
+ while(tempName == "" || _confMgr->doesBackgroundProfileExist(tempName)) {
+ tempName = QString("BackgroundProfile_")+randStr(20);
+ }
+ tmpProfile.setName(tempName);
+ _confMgr->addBackgroundProfile(tmpProfile);
+ } else {
+ tmpProfile.setName(tempName);
+ _confMgr->replaceBackgroundProfile(tempName,tmpProfile);
+ }
+ _mp.setBackgroundProfileName(tempName);
+
+ // LensProfile related
+ SphericalLensProfile tmpSphere;
+ tmpSphere.setMaxNumLenses(_numLenses->value());
+ float avgR = _lensSizeSlider->value();
+ float rangeR = _lensVarSlider->value();
+ float minR = avgR * (1.00 - rangeR/100.0);
+ float maxR = avgR * (1.00 + rangeR/100.0);
+ tmpSphere.setRadius(minR/100.0, maxR/100.0, (rangeR > 0.00));
+ tempName = _mp.getLensProfileName();
+
+ //!!! NOTE: There is a bug that causes a core dump in this code!
+ if(tempName == "" || !_confMgr->doesLensProfileExist(tempName)) {
+ // generate a random LensProfile name that doesn't exist.
+ while(tempName == "" || _confMgr->doesLensProfileExist(tempName)) {
+ tempName = QString("LensProfile_")+randStr(20);
+ }
+ tmpSphere.setName(tempName);
+
+ LensProfile* tL = tmpSphere.clone();
+ _confMgr->addLensProfile(tL);
+ } else {
+ tmpSphere.setName(tempName);
+ LensProfile* tL = tmpSphere.clone();
+ _confMgr->replaceLensProfile(tempName,*tL);
+ }
+ _mp.setLensProfileName(tempName);
+ // !!! end note
+
+ // master profile related
+ _mp.setTimerMillis(_timerBox->value());
+ _mp.setScreenWidth(_screenXBox->currentText().toInt());
+ _mp.setScreenHeight(_screenYBox->currentText().toInt());
+
+ QString newName = _nameBox->text();
+ _mp.setName(newName);
+
+ //send local copy back to config manager.
+ //need to check to see if this was an addition,
+ //if the name has changed
+ //if the new name conflicts
+ //etc.
+ if(newName == "") {
+ QString message(tr("Please enter a valid name."));
+ QMessageBox::warning(this, _windowTitle, message, QMessageBox::Ok);
+ return;
+ }
+
+ //Check to see if the name is already in use.
+ if(_oldName != newName &&_confMgr->doesProfileExist(newName)) {
+ QString message(tr("A profile with name '"));
+ message += newName;
+ message += tr("' already exists. Please choose a new name.");
+ QMessageBox::warning(this, _windowTitle, message, QMessageBox::Ok);
+ return;
+ }
+
+ if(_oldName == "") {
+ //add it!
+ _confMgr->addProfile(_mp);
+ } else {
+ //we've editted a preexisting palette.
+ _confMgr->replaceProfile(_oldName, _mp);
+ }
+
+ if(_oldName != newName) {
+ emit profileNameChange(_oldName, newName);
+ }
+ emit accepted();
+ //emit finished(0);
+ close();
+}
+
+void ProfileEditDialog::cancelClicked(bool checked) {
+ //emit finished(1);
+ emit rejected();
+ close();
+}
+
+void ProfileEditDialog::addPalClicked(bool checked) {
+ if(_confMgr == NULL || _paletteBox == NULL)
+ return;
+
+ editPalette(QString(""), false);
+}
+
+void ProfileEditDialog::editPalClicked(bool checked) {
+ if(_confMgr == NULL || _paletteBox == NULL)
+ return;
+
+ if(_paletteBox->currentIndex() >= 0) {
+ QString selected = _paletteBox->currentText();
+
+ //check for existence and edit if so
+ if(_confMgr->doesPaletteExist(selected)) {
+ editPalette(selected, true);
+ }
+ }
+}
+
+//attempts to edit the specified palette.
+void ProfileEditDialog::editPalette(const QString& palName, bool bReplace)
{
+ if(_confMgr == NULL || _paletteBox == NULL)
+ return;
+
+ QString oldPalName = palName;
+
+ bool bDone = false;
+ bool bFirstPass = true;
+
+ IndexedPaletteDialog* palDlg = NULL;
+ IndexedPaletteProfile tmpProfile;
+ if(bReplace) {
+ tmpProfile = _confMgr->getPaletteProfile(palName);
+ }
+
+ while(!bDone) {
+ // display the palette editor dialog using either a new
+ // object or the one requested for edit.
+ if(bFirstPass && !bReplace) {
+ palDlg = new IndexedPaletteDialog(NULL,this);
+ } else {
+ palDlg = new IndexedPaletteDialog(&tmpProfile,this);
+ }
+ bFirstPass = false;
+ if(palDlg != NULL) {
+ // if the user clicked ok, then try to update the palette
+ if(palDlg->exec() == QDialog::Accepted) {
+ tmpProfile = palDlg->getPalette();
+
+ // check the name to make sure it is valid and not
+ // already in the list.
+ QString newName = tmpProfile.getName();
+ if(newName == "") {
+ //give the user a warning dialog box
+ QMessageBox::warning(this, 0, "Please enter a valid name.",
QMessageBox::Ok);
+ } else if(oldPalName != newName && _confMgr->doesPaletteExist(newName)) {
+ //give the user a warning dialog box
+ QString message(tr("A palette with name '"));
+ message += newName;
+ message += "' already exists. Please choose a new name.";
+ QMessageBox::warning(this, 0, message, QMessageBox::Ok);
+ } else {
+ // name is valid, so try to insert or replace based on bReplace
+ if(bReplace) {
+ _confMgr->replacePalette(oldPalName, tmpProfile);
+ } else {
+ _confMgr->addPalette(tmpProfile);
+ }
+
+ // if we are replacing, remove old name first, then
+ // insert the new name.
+ if(oldPalName != "" && oldPalName != newName) {
+ int i=0;
+ int count = _paletteBox->count();
+ QString tmpItem = _paletteBox->itemText(0);
+ while(tmpItem != oldPalName && i < count) {
+ i++;
+ tmpItem = _paletteBox->itemText(i);
+ }
+ if(tmpItem == oldPalName) {
+ _paletteBox->removeItem(i);
+ }
+ }
+ _paletteBox->addItem(newName);
+ _paletteBox->setCurrentIndex(_paletteBox->count()-1);
+ bDone = true;
+ }
+ } else {
+ bDone = true;
+ }
+ //clean up
+ delete _palDlg;
+ _palDlg = NULL;
+ } else {
+ bDone = true;
+ }
+ }
+}
+
+void ProfileEditDialog::animatePalClicked(bool checked) {
+ _bAnimatePalette = checked;
+}
+
+// populates the palette name selection combo box
+void ProfileEditDialog::populatePalList(QString selected) {
+ if(_paletteBox == NULL)
+ return;
+
+ // empty list and repopulate
+ _paletteBox->clear();
+ _paletteBox->addItems(_confMgr->getPaletteNames());
+
+ // select the currently selected.
+ int idx = _paletteBox->findText(selected);
+ _paletteBox->setCurrentIndex(idx);
+}
+
+void ProfileEditDialog::helpClicked(bool checked) {
+ //QMessageBox::information(this, _windowTitle, "Not implemented yet.",
QMessageBox::Ok);
+ HelpDialog* dlg = new HelpDialog("qrc:/help/ProfileEditDialog.html");
+ if(dlg != NULL) {
+ dlg->exec();
+ delete dlg;
+ dlg = NULL;
+ }
+}
+
=======================================
--- /dev/null
+++ /src/SpiralLenz/src/ProfileEditDialog.h Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,117 @@
+/**
+ * Copyright (c) 2008 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 class represents the dialog box used to edit the screen saver
profiles.
+ * Manages both the MasterProfile and BackgroundProfile objects.
+ *
+ * Revision History:
+ * 080301 jsbackus Initial Revision.
+ */
+
+#ifndef __PROFILEEDITDIALOG_H__
+#define __PROFILEEDITDIALOG_H__
+
+#include <QDialog>
+#include <QListWidget>
+#include <QComboBox>
+#include <QCheckBox>
+#include <QLineEdit>
+#include <QSpinBox>
+#include <QDoubleSpinBox>
+#include <QSlider>
+
+//#include "../../common/2d_bgnd_w_lens/ConfigManager.h"
+//#include "../../common/2d_bgnd_w_lens/MasterProfile.h"
+//#include "../../common/2d_bgnd_w_lens/BackgroundProfile.h"
+//#include "PlasmaFractalBackgroundProfile.h"
+//#include "../../../common/IndexedPalette/IndexedPaletteDialog.h"
+
+#include "2d_bgnd_w_lens/ConfigManager.h"
+#include "2d_bgnd_w_lens/MasterProfile.h"
+#include "2d_bgnd_w_lens/BackgroundProfile.h"
+#include "PlasmaFractalBackgroundProfile.h"
+#include "IndexedPalette/IndexedPaletteDialog.h"
+
+class ProfileEditDialog : public QDialog {
+
+ Q_OBJECT
+
+public:
+ ProfileEditDialog(QString targetName = "", ConfigManager* confMgr = NULL,
QWidget* parent = 0, Qt::WindowFlags f = 0);
+ ~ProfileEditDialog();
+
+public slots:
+ //ok is responsible for updating the ConfigManager
+ void okClicked(bool checked = false);
+ void cancelClicked(bool checked = false);
+ void helpClicked(bool checked = false);
+
+ void addPalClicked(bool checked = false);
+ void editPalClicked(bool checked = false);
+ void animatePalClicked(bool checked = false);
+
+signals:
+ void profileNameChange(QString oldName, QString newName);
+
+private:
+ //attempts to edit the specified palette.
+ //void editPalette(IndexedPaletteProfile* pal, bool bWasAddRename =
false);
+ //attempts to edit the specified palette.
+ void editPalette(const QString& palName, bool bReplace = false);
+
+ // populates the palette name selection combo box
+ void populatePalList(QString selected);
+
+ //MasterProfile related
+ QLineEdit* _nameBox;
+ QSpinBox* _timerBox;
+ QComboBox* _screenXBox;
+ QComboBox* _screenYBox;
+
+ MasterProfile _mp;
+
+ //PlasmaFractalBackgroundProfile related
+ QSlider* _coarsenessBox;
+ float _coarsenessAdjust;
+ QComboBox* _paletteBox;
+ bool _bAnimatePalette;
+ QDoubleSpinBox* _paletteXSpeedBox;
+ QDoubleSpinBox* _paletteYSpeedBox;
+ QCheckBox* _clampColorBox;
+
+ IndexedPaletteDialog* _palDlg;
+ QString _palOldName;
+
+ // lens related
+ QSlider* _lensSizeSlider;
+ QSlider* _lensVarSlider;
+ QSpinBox* _numLenses;
+
+ ConfigManager* _confMgr;
+
+ QString _oldName;
+ QString _windowTitle;
+};
+#endif
=======================================
--- /dev/null
+++ /src/SpiralLenz/src/SpiralBackground.cpp Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,136 @@
+/**
+ * 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 "SpiralBackground.h"
+
+/**
+ * Constructor takes the dimensions, a pointer to the palette,
+ * whether to rotate the palette, and the palette color skip.
+ */
+SpiralBackground::SpiralBackground(int sizeX, int sizeY, IndexedPalette*
pal,
+ bool bAnimatePalette, float paletteXSpeed,
+ float paletteYSpeed) {
+
+ // base class specific
+ initIndexedPaletteBackground(sizeX,sizeY);
+ setPalette(pal);
+ _bEnableAnimation = bAnimatePalette;
+ _xSpeed = paletteXSpeed;
+ _ySpeed = paletteYSpeed;
+
+ _bSetupFinished = false;
+
+ // general defaults
+ _numGenStepsPerTick = 0;
+ _bRandomColor = false;
+ _algorithm = NULL;
+ _style = SINGLE;
+
+ // SINGLE style specific
+ _bLerpToDefault = false;
+ _singleWidth = 1;
+ // end SINGLE style
+
+
+ // initialize field to -1 (no color)
+ for(int i=0;i<_height*_width;i++)
+ {
+ _field[i] = -1;
+ }
+
+}
+
+SpiralBackground::~SpiralBackground() {
+ destroyIndexedPaletteBackground();
+}
+
+/**
+ * Initializes the generator algorithm to generate a single-color
+ * spiral of the specified width, rotating through the primary palette
+ * direction as it extends outward. If bLerpToDefaultColor is true,
+ * the palette color will be in the middle with, the default palette color
+ * on the borders. If bRandomColor is true, the first color index is
+ * randomly picked.
+ * If genStepsPerTick is 0, then it will all be done in one swoop.
+ */
+void SpiralBackground::genSingleColorSpiral(SpiralBackgroundShape shape,
+ int genStepsPerTick, int width,
+ bool bRandomColor,
+ bool bLerpToDefaultColor) {
+ _numGenStepsPerTick = genStepsPerTick;
+ _bRandomColor = bRandomColor;
+
+ _style = SINGLE;
+ _singleWidth = width;
+ _bLerpToDefaultColor = bLerpToDefaultColor;
+
+ //_algorithm =
+ //_shape = shape;
+}
+
+/**
+ * Initializes the generator algorithm to generate a multi-color spiral,
+ * that remains constant through the whole spiral. The width is the
+ * width (primary axis) of the palette. If bRandomColor is true,
+ * the initial index is randomly picked and the palette will be wrapped.
+ * If genStepsPerTick is 0, then it will all be done in one swoop.
+ */
+void SpiralBackground::genMultiColorSpiral(SpiralBackgroundShape shape,
+ int genStepsPerTick,
+ bool bRandomColor) {
+ _numGenStepsPerTick = genStepsPerTick;
+ _bRandomColor = bRandomColor;
+
+ _style = MULTIWIDTH;
+
+ //_shape = shape;
+ //_algorithm =
+}
+
+/**
+ * Finishes generating the spiral then rotates the palette when done.
+ */
+void SpiralBackground::clocktick() {
+ if(_paletteWidth > 0)
+ {
+ if(!_bSetupFinished)
+ {
+ spiralGenStep();
+ }
+ else
+ {
+ rotateColorIndex();
+ }
+ }
+}
+
+/**
+ * Performs one iteration of the fractal generation.
+ */
+void SpiralBackground::spiralGenStep() {
+ if(_algorithm.calc(_numGenStepsPerTick))
+ _bSetupFinished = true;
+}
+
=======================================
--- /dev/null
+++ /src/SpiralLenz/src/SpiralBackground.h Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,112 @@
+/**
+ * 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 class generates a spiral background. After generation,
+ * it will rotate the palette with the specified primary and
+ * secondary speeds.
+ */
+
+//#include <stdlib.h>
+//#include <ctime>
+
+//using namespace std;
+
+#ifndef __SPIRALBACKGROUND_H__
+#define __SPIRALBACKGROUND_H__
+
+#include "2d_bgnd_w_lens/globaldefs.h"
+#include "2d_bgnd_w_lens/IndexedPaletteBackground.h"
+
+#include "SpiralBackgroundAlgorithm.h"
+#include "RectangularSpiral.h"
+
+enum SpiralBackgroundShape {
+ POLAR, RECTANGULAR, DIAMOND, TRIANGULAR
+};
+
+enum SpiralBackgroundSytle {
+ SINGLE, MULTIWIDTH
+};
+
+class SpiralBackground : public IndexedPaletteBackground {
+
+ public:
+ /**
+ * Constructor takes the dimensions, a pointer to the palette,
+ * whether to rotate the palette, and the palette color skip.
+ */
+ SpiralBackground(int sizeX, int sizeY, IndexedPalette* pal,
+ bool bAnimatePalette, float paletteXSpeed,
+ float paletteYSpeed);
+
+ ~SpiralBackground();
+
+ /**
+ * Initializes the generator algorithm to generate a single-color
+ * spiral of the specified width, rotating through the primary palette
+ * direction as it extends outward. If bLerpToDefaultColor is true,
+ * the palette color will be in the middle with, the default palette
color
+ * on the borders. If bRandomColor is true, the first color index is
+ * randomly picked.
+ * If genStepsPerTick is 0, then it will all be done in one swoop.
+ */
+ void genSingleColorSpiral(int genStepsPerTick, int width,
+ bool bRandomColor, bool bLerpToDefaultColor);
+
+ /**
+ * Initializes the generator algorithm to generate a multi-color spiral,
+ * that remains constant through the whole spiral. The width is the
+ * width (primary axis) of the palette. If bRandomColor is true,
+ * the initial index is randomly picked and the palette will be wrapped.
+ * If genStepsPerTick is 0, then it will all be done in one swoop.
+ */
+ void genMultiColorSpiral(int genStepsPerTick, bool bRandomColor);
+
+ // *** Begin Extended Methods ***
+ /**
+ * Finishes generating the spiral then rotates the palette when done.
+ */
+ virtual void clocktick();
+ // *** End Extended Methods ***
+
+ private:
+ /**
+ * Performs one iteration of the fractal generation.
+ */
+ void spiralGenStep();
+
+ int _numGenStepsPerTick;
+ bool _bRandomColor;
+
+ // specific to SINGLE style
+ bool _bLerpToDefaultColor;
+ int _singleWidth;
+ // end specific to SINGLE style
+
+ SpiralBackgroundShapeAlgorithm* _algorithm;
+ SpiralBackgroundStyle _style;
+};
+
+#endif
=======================================
--- /dev/null
+++ /src/SpiralLenz/src/SpiralBackgroundProfile.cpp Mon Mar 16 21:29:13
2009 UTC
@@ -0,0 +1,332 @@
+/**
+ * Copyright (c) 2008 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 <QtXml/QDomElement>
+#include <QtXml/QDomText>
+
+//#include "../../common/utility/misc_funcs.h"
+
+#include "utility/misc_funcs.h"
+#include "PlasmaFractalBackgroundProfile.h"
+#include "PlasmaFractal.h"
+
+PlasmaFractalBackgroundProfile::PlasmaFractalBackgroundProfile() {
+ _xmlTypeValue = "PlasmaFractalBackground";
+
+ //defaults
+ _name = "Empty";
+ _palName = "";
+ _coarseness = 1.0;
+ _genStepsPerTick = 2048;
+ _bAnimatePalette = true;
+ _paletteXSpeed = 1;
+ _paletteYSpeed = 1;
+ _bClampColorIndex = true;
+}
+
+PlasmaFractalBackgroundProfile::~PlasmaFractalBackgroundProfile() {
+}
+
+/* Attempts to load this background profile object from the
+ * specified QDomNode.
+ */
+BackgroundProfile* PlasmaFractalBackgroundProfile::load(QDomNode &node) {
+ float tmpF;
+ int tmpI;
+ QDomElement tempElem;
+
+ //sanity check on the input
+ if(node.nodeName() != getXMLTagName())
+ return NULL;
+
+ //make sure that the type value matches
+ tempElem = node.firstChildElement("type");
+ if(tempElem.isNull() || tempElem.text() != _xmlTypeValue)
+ return NULL;
+
+ PlasmaFractalBackgroundProfile* retVal = new
PlasmaFractalBackgroundProfile();
+
+ tempElem = node.firstChildElement("name");
+ if(!tempElem.isNull()) {
+ retVal->_name = tempElem.text();
+ }
+
+ tempElem = node.firstChildElement("coarseness");
+ if(!tempElem.isNull()) {
+ tmpF = tempElem.text().toFloat();
+ if(tmpF > 0.00 && tmpF < 10000.00) {
+ retVal->_coarseness = tmpF;
+ }
+ }
+
+ tempElem = node.firstChildElement("steps_per_tick");
+ if(!tempElem.isNull()) {
+ tmpI = tempElem.text().toInt();
+ if(tmpI > 0 && tmpI < 30000) {
+ retVal->_genStepsPerTick = tmpI;
+ }
+ }
+
+ tempElem = node.firstChildElement("anmiate_palette");
+ if(!tempElem.isNull()) {
+ QString param = tempElem.text();
+ retVal->_bAnimatePalette = stringToBool(param);
+ }
+
+ tempElem = node.firstChildElement("palette_x_speed");
+ if(!tempElem.isNull()) {
+ tmpI = tempElem.text().toInt();
+ if(tmpI >= 0 && tmpI < 30000) {
+ retVal->_paletteXSpeed = tmpI;
+ }
+ }
+
+ tempElem = node.firstChildElement("palette_y_speed");
+ if(!tempElem.isNull()) {
+ tmpI = tempElem.text().toInt();
+ if(tmpI >= 0 && tmpI < 30000) {
+ retVal->_paletteYSpeed = tmpI;
+ }
+ }
+
+ tempElem = node.firstChildElement("clamp_color");
+ if(!tempElem.isNull()) {
+ QString param = tempElem.text();
+ retVal->_bClampColorIndex = stringToBool(param);
+ }
+
+ tempElem = node.firstChildElement("palette");
+ if(!tempElem.isNull()) {
+ retVal->_palName = tempElem.text();
+ }
+
+ return retVal;
+}
+
+
+/*
+ * Returns a QDomNode object that represents this profile.
+ */
+QDomNode PlasmaFractalBackgroundProfile::save(QDomDocument* doc) {
+ QString tempStr;
+ QDomText tempNode;
+ QDomElement tempElem;
+ QDomElement retVal = doc->createElement(getXMLTagName());
+
+ //type
+ tempNode = doc->createTextNode(_xmlTypeValue);
+ tempElem = doc->createElement("type");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //name
+ tempNode = doc->createTextNode(_name);
+ tempElem = doc->createElement("name");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //coarseness
+ tempStr.setNum(_coarseness);
+ tempNode = doc->createTextNode(tempStr);
+ tempElem = doc->createElement("coarseness");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //steps per tick
+ tempStr.setNum(_genStepsPerTick);
+ tempNode = doc->createTextNode(tempStr);
+ tempElem = doc->createElement("steps_per_tick");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //animate palette?
+ tempNode = doc->createTextNode(boolToString(_bAnimatePalette));
+ tempElem = doc->createElement("anmiate_palette");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //palette X speed
+ tempStr.setNum(_paletteXSpeed);
+ tempNode = doc->createTextNode(tempStr);
+ tempElem = doc->createElement("palette_x_speed");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //palette Y speed
+ tempStr.setNum(_paletteYSpeed);
+ tempNode = doc->createTextNode(tempStr);
+ tempElem = doc->createElement("palette_y_speed");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //clamp color index?
+ tempNode = doc->createTextNode(boolToString(_bClampColorIndex));
+ tempElem = doc->createElement("clamp_color");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //palette name
+ tempNode = doc->createTextNode(_palName);
+ tempElem = doc->createElement("palette");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ return retVal;
+}
+
+/*
+ * Creates and returns a new background object.
+ */
+Background* PlasmaFractalBackgroundProfile::getNewBackgroundObj(int
height, int width, QHash<QString, IndexedPaletteProfile*>* palHash) {
+ return new PlasmaFractal(width, height,
+ palHash->value(_palName)->createPalette(), _coarseness,
_genStepsPerTick,
+ _bAnimatePalette, _paletteXSpeed, _paletteYSpeed, _bClampColorIndex);
+}
+
+/*
+ * get/set palette name.
+ */
+QString PlasmaFractalBackgroundProfile::getPaletteName() {
+ return _palName;
+}
+
+void PlasmaFractalBackgroundProfile::setPaletteName(QString paletteName) {
+ _palName = paletteName;
+}
+
+/*
+ * get/set coarseness.
+ */
+float PlasmaFractalBackgroundProfile::getCoarseness() {
+ return _coarseness;
+}
+
+void PlasmaFractalBackgroundProfile::setCoarseness(float coarseness) {
+ _coarseness = coarseness;
+}
+
+/*
+ * get/set steps per tick
+ */
+int PlasmaFractalBackgroundProfile::getGenStepsPerTick() {
+ return _genStepsPerTick;
+}
+
+void PlasmaFractalBackgroundProfile::setGenStepsPerTick(int
genStepsPerTick) {
+ _genStepsPerTick = genStepsPerTick;
+}
+
+/*
+ * Get/set animate palette.
+ */
+bool PlasmaFractalBackgroundProfile::getAnimatePalette() {
+ return _bAnimatePalette;
+}
+
+void PlasmaFractalBackgroundProfile::setAnimatePalette(bool
bAnimatePalette) {
+ _bAnimatePalette = bAnimatePalette;
+}
+
+/*
+ * get/set palette x speed.
+ */
+float PlasmaFractalBackgroundProfile::getPaletteXSpeed() {
+ return _paletteXSpeed;
+}
+
+void PlasmaFractalBackgroundProfile::setPaletteXSpeed(float speed) {
+ _paletteXSpeed = speed;
+}
+
+/*
+ * get/set palette y speed.
+ */
+float PlasmaFractalBackgroundProfile::getPaletteYSpeed() {
+ return _paletteYSpeed;
+}
+
+void PlasmaFractalBackgroundProfile::setPaletteYSpeed(float speed) {
+ _paletteYSpeed = speed;
+}
+
+/*
+ * Get/set clamp color index.
+ */
+bool PlasmaFractalBackgroundProfile::getClampColorIndex() {
+ return _bClampColorIndex;
+}
+
+void PlasmaFractalBackgroundProfile::setClampColorIndex(bool
bClampColorIndex) {
+ _bClampColorIndex = bClampColorIndex;
+}
+
+/*
+ * Overloaded assignment operator
+ */
+PlasmaFractalBackgroundProfile&
PlasmaFractalBackgroundProfile::operator=(PlasmaFractalBackgroundProfile&
other) {
+ _name = other._name;
+ _palName = other._palName;
+ _coarseness = other._coarseness;
+ _genStepsPerTick = other._genStepsPerTick;
+ _bAnimatePalette = other._bAnimatePalette;
+ _paletteXSpeed = other._paletteXSpeed;
+ _paletteYSpeed = other._paletteYSpeed;
+ _bClampColorIndex = other._bClampColorIndex;
+
+ return *this;
+}
+
+/*
+ * Creates a new object with this object's settings.
+ */
+BackgroundProfile* PlasmaFractalBackgroundProfile::clone() {
+ PlasmaFractalBackgroundProfile* retVal = new
PlasmaFractalBackgroundProfile();
+
+ *retVal = *this;
+
+ return (BackgroundProfile*)retVal;
+}
+
+/**
+ * Called whenever palette names change
+ */
+void PlasmaFractalBackgroundProfile::paletteNameChanged(QString oldName,
+ QString newName) {
+ // if the palette name matches the old name, change the name.
+ if(_palName == oldName) {
+ _palName = newName;
+ }
+}
+
+/**
+ * Called whenever a palette is removed.
+ */
+void PlasmaFractalBackgroundProfile::paletteRemoved(QString palName) {
+ // if this palette has been removed, set current palette name to ""
+ if(_palName == palName) {
+ _palName = QString("");
+ }
+}
+
+
=======================================
--- /dev/null
+++ /src/SpiralLenz/src/SpiralBackgroundProfile.h Mon Mar 16 21:29:13 2009
UTC
@@ -0,0 +1,134 @@
+/**
+ * Copyright (c) 2008 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 background profile is responsible for setting up and returning a
new
+ * PlasmaFractal background object.
+ *
+ * @author jeff backus
+ * @date 09/01/2007
+ */
+
+#ifndef __PLASMAFRACTALBACKGROUNDPROFILE_H__
+#define __PLASMAFRACTALBACKGROUNDPROFILE_H__
+
+#include <QString>
+#include <QtXml/QDomNode>
+#include <QtXml/QDomDocument>
+
+#include "../../common/2d_bgnd_w_lens/BackgroundProfile.h"
+
+class PlasmaFractalBackgroundProfile : public BackgroundProfile {
+
+public:
+ PlasmaFractalBackgroundProfile();
+ ~PlasmaFractalBackgroundProfile();
+
+ /* Attempts to load this background profile object from the
+ * specified QDomNode.
+ */
+ BackgroundProfile* load(QDomNode &node);
+
+ /*
+ * Returns a QDomNode object that represents this profile.
+ */
+ QDomNode save(QDomDocument* doc);
+
+ /*
+ * Creates and returns a new background object.
+ */
+ Background* getNewBackgroundObj(int height, int width, QHash<QString,
IndexedPaletteProfile*>* palHash);
+
+ /*
+ * get/set palette name.
+ */
+ QString getPaletteName();
+ void setPaletteName(QString paletteName);
+
+ /*
+ * get/set coarseness.
+ */
+ float getCoarseness();
+ void setCoarseness(float coarseness);
+
+ /*
+ * get/set steps per tick
+ */
+ int getGenStepsPerTick();
+ void setGenStepsPerTick(int genStepsPerTick);
+
+ /*
+ * Get/set animate palette.
+ */
+ bool getAnimatePalette();
+ void setAnimatePalette(bool bAnimatePalette);
+
+ /*
+ * get/set palette x speed.
+ */
+ float getPaletteXSpeed();
+ void setPaletteXSpeed(float speed);
+
+ /*
+ * get/set palette y speed.
+ */
+ float getPaletteYSpeed();
+ void setPaletteYSpeed(float speed);
+
+ /*
+ * Get/set clamp color index.
+ */
+ bool getClampColorIndex();
+ void setClampColorIndex(bool bClampColorIndex);
+
+ /*
+ * Overloaded assignment operator.
+ */
+ PlasmaFractalBackgroundProfile& operator=(PlasmaFractalBackgroundProfile&
other);
+
+ /*
+ * Creates a new object with this object's settings.
+ */
+ BackgroundProfile* clone();
+
+ /**
+ * Called whenever palette names change
+ */
+ virtual void paletteNameChanged(QString oldName, QString newName);
+
+ /**
+ * Called whenever a palette is removed.
+ */
+ virtual void paletteRemoved(QString palName);
+
+private:
+ QString _palName;
+ float _coarseness;
+ int _genStepsPerTick;
+ bool _bAnimatePalette;
+ float _paletteXSpeed;
+ float _paletteYSpeed;
+ bool _bClampColorIndex;
+};
+#endif
=======================================
--- /dev/null
+++ /src/SpiralLenz/src/project_specific_externs.cpp Mon Mar 16 21:29:13
2009 UTC
@@ -0,0 +1,114 @@
+/**
+ * Copyright (c) 2008 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 file contains project specific definitions, including version
number.
+ */
+
+#include <QString>
+
+#include "../../common/2d_bgnd_w_lens/BackgroundProfile.h"
+#include "../../common/2d_bgnd_w_lens/lens_engine/LensProfile.h"
+#include "../../common/2d_bgnd_w_lens/lens_engine/SphericalLensProfile.h"
+#include "SpiralBackgroundProfile.h"
+
+/**
+ * This function will create an array that contains the profiles
+ * for allowable backgrounds and sets numProfiles to indicate
+ * the number of profiles in the array. If there is a problem,
+ * numProfiles will be set to 0 and NULL will be returned.
+ */
+BackgroundProfile** getBackgroundTypes(int* numProfiles) {
+ BackgroundProfile** retVal = NULL;
+
+ *numProfiles = 1;
+ retVal = new BackgroundProfile*[*numProfiles];
+
+ if(retVal == NULL) {
+ *numProfiles = 0;
+ return NULL;
+ }
+
+ retVal[0] = (BackgroundProfile*) (new SpiralBackgroundProfile());
+
+ if(retVal[0] == NULL) {
+ *numProfiles = 0;
+ return NULL;
+ }
+
+ return retVal;
+}
+
+/**
+ * This function will create an array that contains the profiles
+ * for allowable lenses and sets numProfiles to indicate
+ * the number of profiles in the array. If there is a problem,
+ * numProfiles will be set to 0 and NULL will be returned.
+ */
+LensProfile** getLensTypes(int* numProfiles) {
+ LensProfile** retVal = NULL;
+
+ *numProfiles = 1;
+ retVal = new LensProfile*[*numProfiles];
+
+ if(retVal == NULL) {
+ *numProfiles = 0;
+ return NULL;
+ }
+
+ retVal[0] = (LensProfile*) (new SphericalLensProfile());
+
+ if(retVal[0] == NULL) {
+ *numProfiles = 0;
+ return NULL;
+ }
+
+ return retVal;
+}
+
+/**
+ * This function returns the string used to create the path for
+ * the settings file. It is also used to define the XML
+ * document root.
+ */
+QString getAppConfigName(){
+ return QString("SpiralLenz");
+}
+
+/**
+ * Returns the full name of the screen saver to be used in
+ * places such as title bars of dialog boxes and the About
+ * dialog box.
+ */
+QString getAppFullName() {
+ return QString("SpiralLenz");
+}
+
+/**
+ * Returns the version string for the screen saver.
+ */
+QString getAppVersion() {
+ return QString("0.1");
+}
+
=======================================
--- /dev/null
+++ /src/SpiralLenz/src/redirector_main.cpp Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,40 @@
+/**
+ * Copyright (c) 2008 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.
+ *
+ */
+
+/**
+ * This is the main entry point for the redirector exec. The majority
+ * of the code is in redirector.cpp, located in the common/utility.
+ *
+ * Revision history:
+ * 090314 jsbackus Initial version.
+ */
+#include <windows.h>
+
+#include "../resource_files/resource.h"
+
+#include "../../common/utility/redirector.h"
+
+const char KEY_NAME[] = "SpiralLenz";
+
+/**
+ * Main entry point.
+ */
+//int winmain(int argc, char** argv) {
+int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow) {
+
+ return redirector(lpCmdLine, &KEY_NAME[0]);
+}
=======================================
--- /dev/null
+++ /src/common/spirals/RectangularSpiralAlgorithm.cpp Mon Mar 16 21:29:13
2009 UTC
@@ -0,0 +1,290 @@
+#include "RectangularSpiralAlgorithm.h"
+
+/**
+ * Constructor.
+ */
+RectangularSpiralAlgorithm::RectangularSpiralAlgorithm() {
+ _cornerSeg = NULL;
+ _straightSeg = NULL;
+}
+
+RectangularSpiralAlgorithm::~RectangularSpiralAlgorithm() {
+ if(_cornerSeg != NULL) {
+ delete [] _cornerSeg;
+ _cornerSeg = NULL;
+ }
+ if(_straightSeg != NULL) {
+ delete [] _straightSeg;
+ _straightSeg = NULL;
+ }
+}
+
+/**
+ * Initializes the algorithm. Doesn't perform any actual generation.
+ * @param field The array of integers in which to generate the spiral
field.
+ * @param screenWidth the width of the screen in pixels.
+ * @param screenHeight the height of the screen in pixels.
+ * @param numColors the number of colors in the palette primary direction.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @param bRandomColor whether or not the initial color is randomly
selected.
+ * @see calc()
+ */
+void RectangularSpiralAlgorithm::initialize(int* field, int screenWidth,
+ int screenHeight, int numColors,
+ int colorWidth, int emptyWidth,
+ bool bConstantColor,
+ bool bRandomColor) {
+ initializeBase(field, screenWidth, screenHeight, numColors, colorWidth,
+ colorHeight, bConstantColor);
+
+ if(_height <= 0)
+ return;
+ if(_width <= 0)
+ return;
+ if(_numColors <= 0)
+ return;
+
+ calcSegs();
+
+ // set initial starting position
+ _currX = screenWidth / 2;
+ _currY = screenHeight / 2;
+
+ // pick initial color
+ if(bRandomColor) {
+ _nextIdx = jrand() % numColors;
+ } else {
+ _nextIdx = 0;
+ }
+
+ // pick direction
+ _dir = jrand() % 4;
+ _bClockwise = (jrand() % 2 == 0);
+
+ // set initial distances
+ switch(_dir) {
+ case UP:
+ _bXPositive = _bClockwise;
+ _xSegs = 2;
+
+ _bYPositive = true;
+ _ySegs = 1;
+ _remainingSegs = 1;
+ break;
+ case DOWN:
+ _bXPositive = !_bClockwise;
+ _xSegs = 2;
+
+ _bYPositive = false;
+ _ySegs = 1;
+ _remainingSegs = 1;
+ break;
+ case LEFT:
+ _bXPositive = false;
+ _xSegs = 1;
+ _remainingSegs = 1;
+
+ _bYPositive = _bClockwise;
+ _ySegs = 2;
+ break;
+ case RIGHT:
+ default:
+ _bXPositive = true;
+ _xSegs = 1;
+ _remainingSegs = 1;
+
+ _bYPositive = !_bClockwise;
+ _ySegs = 2;
+ }
+
+}
+
+/**
+ * Completes one iteration of the algorithm. Returns true if the algorithm
+ * is completed.
+ */
+bool RectangularSpiralAlgorithm::calc() {
+ if(_field == NULL)
+ return;
+ if(_cornerSeg == NULL)
+ return;
+ if(_straightSeg == NULL)
+ return;
+
+ int i;
+
+ /**
+ * To Do:
+ * - Process a segment
+ * - Update _currX and/or _currY
+ * - Update color index, if necessary
+ * - Decrement _remainingSegs
+ * - if _remainingSegs == 0:
+ * - change _dir
+ * - update polarities, current/next segs, and _remainingSegs.
+ */
+
+ // update color index
+ if(!_bConstantColor) {
+ _nextIdx = (_nextIdx+_segmentSize)%_numColors;
+ }
+
+ // update the number of remaining segments. If we hit 0,
+ // time to change direction!
+ _remainingSegs--;
+ if(_remainingSegs <= 0) {
+ // establish new direction
+ switch(_dir) {
+ case UP:
+ _dir = _bClockwise ? RIGHT : LEFT;
+ break;
+ case DOWN:
+ _dir = _bClockwise ? LEFT : RIGHT;
+ break;
+ case LEFT:
+ _dir = _bClockwise ? UP : DOWN;
+ break;
+ case RIGHT:
+ default:
+ _dir = _bClockwise ? DOWN : UP;
+ }
+ }
+
+ /*
+ // old
+ // Check the remaining distance. If it is 0, then we are turning.
+ if(_remainingSegs == 0) {
+ int bevDim = _colorWidth+2*_emptyWidth;
+
+ // move through the turn
+ switch(_dir) {
+ case UP:
+ // up to right or up to left is a counter-clockwise rotation
+ _currY++;
+ int tmpX = _currX;
+ int tmpY = _currY*_width;
+
+ if(_currY >= 0 && _currY < _height) {
+ for(i=0; i<bevDim;i++) {
+ if(tmpX >= 0 && _tmpX < _width) {
+ int bevX = bevDim - _remainingTurn;
+ int bevY = (bevDim - i - 1)*bevDim;
+ if(_bevel[bevX + bevY] >= 0) {
+ _field[tmpY+(tmpX++)] = _nextIdx + _bevel[bevX + bevY];
+ } else {
+ _field[tmpY+(tmpX++)] = -1;
+ }
+ }
+ }
+ }
+ break;
+ case DOWN:
+ // down to right or down to left is a clockwise rotation
+ _currY--;
+ int tmpX = _currX;
+ int tmpY = _currY*_width;
+
+ if(_currY >= 0 && _currY < _height) {
+ for(i=0; i<bevDim;i++) {
+ if(tmpX >= 0 && _tmpX < _width) {
+ int bevX = _remainingTurn;
+ int bevY = (i)*bevDim;
+ if(_bevel[bevX + bevY] >= 0) {
+ _field[tmpY+(tmpX++)] = _nextIdx + _bevel[bevX + bevY];
+ } else {
+ _field[tmpY+(tmpX++)] = -1;
+ }
+ }
+ }
+ }
+ break;
+ case LEFT:
+ break;
+ case RIGHT:
+ default:
+ }
+*/
+}
+
+/**
+ * Calculates both the corner and "straight away" segments.
+ * These segments are _segmentSize x _segmentSize in size.
+ * They are also oriented such that (0,0) is the bottom left corner.
+ * _straightSeg is such that it flows from left to right, and
+ * _cornerSeg is such that it flows from right to up if _bClockwise
+ * is false, or right to down if _bClockwise is true. Note that in
+ * either case, the color index offset has not been properly modulo'd
+ * and should be done so after being added to the current color index,
+ * if _bConstantColor is false. In the case where _bConstantColor is
+ * true, the index offset will always be 0.
+ */
+void RectangularSpiralAlgorithm::calcSegments() {
+ if(_colorWidth <= 0)
+ return;
+ if(_emptyWidth < 0)
+ _emptyWidth = 0;
+
+ // set the segment dimension
+ _segmentSize = _colorWidth + 2*_emptyWidth;
+
+ // create space for the two segments
+ _straightSeg = new int[_segmentSize * _segmentSize];
+ if(_straightSeg == NULL)
+ return;
+ _cornerSeg = new int[_segmentSize * _segmentSize];
+ if(_cornerSeg == NULL)
+ return;
+
+ // build the straight segment. See comment in header file for more
+ // information.
+ int x, y, yCalc, yInvCalc;
+ for(y=0;y<_segmentSize; y++) {
+ yCalc = y * _segmentSize;
+ for(x=0;x<_segmentSize;x++) {
+ if(y<_emptyWidth || y >= _colorWidth + _emptyWidth) {
+ // we're in empty space, so use default color.
+ _straightSeg[yCalc+x] = -1;
+ } else {
+ // we're in the color space. If _bConstantColor, set
+ // to 0, otherwise use x.
+ if(_bConstantColor) {
+ _straightSeg[yCalc+x] = 0;
+ } else {
+ _straightSeg[yCalc+x] = x;
+ }
+ }
+ }
+ }
+
+ // now, we build the corner segment. If _bClockwise is true,
+ // then copy the top left corner as is, and rotate the bottom right
+ // corner about x=y. If _bClockwise is false, copy the bottom left
+ // corner as is, and rotate the top right about x=_segmentSize-y.
+ if(_bClockwise) {
+ for(y = 0; y<_segmentSize; y++) {
+ yCalc = y*_segmentSize;
+ yInvCalc = (_segmentSize - y)*_segmentSize;
+ for(x = 0; x<_segmentSize; x++) {
+ if(x < y) {
+ _cornerSeg[yCalc+x] = _straightSeg[yCalc+x];
+ } else {
+ _cornerSeg[yCalc+x] = _straightSeg[yInvCalc+(_segmentSize-x)];
+ }
+ }
+ }
+ } else {
+ for(y = 0; y<_segmentSize; y++) {
+ yCalc = y*_segmentSize;
+ yInvCalc = (_segmentSize - y)*_segmentSize;
+ for(x = 0; x<_segmentSize; x++) {
+ if(x < (_segmentSize-y)) {
+ _cornerSeg[yCalc+x] = _straightSeg[yCalc+x];
+ } else {
+ _cornerSeg[yCalc+x] = _straightSeg[yInvCalc+(_segmentSize-x)];
+ }
+ }
+ }
+ }
+}
=======================================
--- /dev/null
+++ /src/common/spirals/RectangularSpiralAlgorithm.h Mon Mar 16 21:29:13
2009 UTC
@@ -0,0 +1,102 @@
+/**
+ * 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 algorithm will generate a rectangular spiral.
+ */
+
+#include "utility/misc_funcs.h"
+
+#ifndef __RECTANGULARSPIRALALGORITHM_H__
+#define __RECTANGULARSPIRALALGORITHM_H__
+
+enum RectangularSpiralAlgorithmDir { UP=0, DOWN=1, LEFT=2, RIGHT=3 };
+
+class RectangularSpiralAlgorithm : public SpiralAlgorithm {
+
+ public:
+
+ /**
+ * Constructor.
+ */
+ RectangularSpiralAlgorithm();
+
+ ~RectangularSpiralAlgorithm();
+
+ /**
+ * Initializes the algorithm. Doesn't perform any actual generation.
+ * @param field The array of integers in which to generate the spiral
field.
+ * @param screenWidth the width of the screen in pixels.
+ * @param screenHeight the height of the screen in pixels.
+ * @param numColors the number of colors in the palette primary
direction.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @param bRandomColor whether or not the initial color is randomly
selected.
+ * @see calc()
+ */
+ void initialize(int* field, int screenWidth, int screenHeight,
+ int numColors, int colorWidth, int emptyWidth,
+ bool bConstantColor, bool bRandomColor);
+
+ /**
+ * Completes one iteration of the algorithm. Returns true if the
algorithm
+ * is completed.
+ */
+ bool calc();
+
+ private:
+ /**
+ * Calculates both the corner and "straight away" segments.
+ * These segments are _segmentSize x _segmentSize in size.
+ * They are also oriented such that (0,0) is the bottom left corner.
+ * _straightSeg is such that it flows from left to right, and
+ * _cornerSeg is such that it flows from right to up if _bClockwise
+ * is false, or right to down if _bClockwise is true. Note that in
+ * either case, the color index offset has not been properly modulo'd
+ * and should be done so after being added to the current color index,
+ * if _bConstantColor is false. In the case where _bConstantColor is
+ * true, the index offset will always be 0.
+ */
+ void calcSegments();
+
+ int _segmentSize;
+ int* _cornerSeg;
+ int* _straightSeg;
+
+ RectangularSpiralAlgorithmDir _dir;
+ bool _bClockwise;
+ int _currX;
+ int _currY;
+ int _nextIdx;
+
+ bool _bXPositive; //> either current or next polarity
+ bool _bYPositive; //> either current or next polarity
+ int _xSegs; //> either current or next number of segments
+ int _ySegs; //> either current or next number of segments
+ int _remainingSegs;
+
+};
+
+#endif
=======================================
--- /dev/null
+++ /src/common/spirals/SpiralAlgorithm.cpp Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,97 @@
+#include "SpiralAlgorithm.h"
+
+/**
+ * Constructor.
+ */
+SpiralAlgorithm::SpiralAlgorithm() {
+ _field = NULL;
+ _width = 0;
+ _height = 0;
+ _numColors = 0;
+ _colorWidth = 1;
+ _emptyWidth = 0;
+ _bConstantColor = false;
+}
+
+SpiralAlgorithm::~SpiralAlgorithm() {
+ // someone else is responsible for destroying _field
+ _field = NULL;
+}
+
+ /**
+ * Initializes the algorithm. Doesn't perform any actual generation.
+ * @param field The array of integers in which to generate the spiral
field.
+ * @param screenWidth the width of the screen in pixels.
+ * @param screenHeight the height of the screen in pixels.
+ * @param numColors the number of colors in the palette primary
direction.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @param bRandomColor whether or not the initial color is randomly
selected.
+ * @see calc()
+ */
+void SpiralAlgorithm::initialize(int* field, int screenWidth, int
screenHeight,
+ int numColors, int colorWidth, int emptyWidth,
+ bool bConstantColor, bool bRandomColor) {
+
+ initializeBase(field, screenWidth, screenHeight, numColors, colorWidth,
+ colorHeight, bConstantColor);
+}
+
+/**
+ * Completes one iteration of the algorithm. Returns true if the algorithm
+ * is completed.
+ */
+bool SpiralAlgorithm::calc() {
+ // base does nada.
+ return true;
+}
+
+/**
+ * Completes up to numIterations iterations of the algorithm. If N <= 0,
+ * the algorithm will continue until finished.
+ */
+bool SpiralAlgorithm::calc(int numIterations) {
+ for(int i=0; i<numIterations; i++) {
+ if(calc())
+ return true;
+ }
+ return false;
+}
+
+/**
+ * This is a convenience function that is the same as calling calc(-1).
+ */
+bool SpiralAlgorithm::calcAll() {
+ return calc(-1);
+}
+
+ /**
+ * Initializes the base algorithm. Doesn't perform any actual
generation.
+ * @param field The array of integers in which to generate the spiral
field.
+ * @param screenWidth the width of the screen in pixels.
+ * @param screenHeight the height of the screen in pixels.
+ * @param numColors the number of colors in the palette primary
direction.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @see initialize()
+ */
+void SpiralAlgorithm::initializeBase(int* field, int screenWidth,
+ int screenHeight, int numColors,
+ int colorWidth, int emptyWidth,
+ bool bConstantColor) {
+ _field = field;
+ _width = screenWidth;
+ _height = screenHeight;
+ _numColors = numColors;
+ _colorWidth = colorWidth;
+ _emptyWidth = emptyWidth;
+ _bConstantColor = bConstantColor;
+
+ if(_colorWidth < 0)
+ _colorWidth = 0;
+ if(_emptyWidth < 0)
+ _emptyWidth = 0;
+}
+
=======================================
--- /dev/null
+++ /src/common/spirals/SpiralAlgorithm.h Mon Mar 16 21:29:13 2009 UTC
@@ -0,0 +1,110 @@
+/**
+ * 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 is the base class for the spiral algorithms.
+ */
+
+/*
+#include <stdlib.h>
+#include <ctime>
+using namespace std;
+*/
+
+#ifndef __SPIRALALGORITHM_H__
+#define __SPIRALALGORITHM_H__
+
+class SpiralAlgorithm {
+
+ public:
+
+ /**
+ * Constructor.
+ */
+ SpiralAlgorithm();
+
+ virtual ~SpiralAlgorithm();
+
+ /**
+ * Initializes the algorithm. Doesn't perform any actual generation.
+ * @param field The array of integers in which to generate the spiral
field.
+ * @param screenWidth the width of the screen in pixels.
+ * @param screenHeight the height of the screen in pixels.
+ * @param numColors the number of colors in the palette primary
direction.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @param bRandomColor whether or not the initial color is randomly
selected.
+ * @see calc()
+ */
+ virtual void initialize(int* field, int screenWidth, int screenHeight,
+ int numColors, int colorWidth, int emptyWidth,
+ bool bConstantColor, bool bRandomColor);
+
+ /**
+ * Completes one iteration of the algorithm. Returns true if the
algorithm
+ * is completed.
+ */
+ virtual bool calc();
+
+ /**
+ * Completes up to numIterations iterations of the algorithm. If N <= 0,
+ * the algorithm will continue until finished.
+ * @param numIterations the number of iterations to perform.
+ * @return true if the spiral generation is complete.
+ * @see calc();
+ */
+ bool calc(int numIterations);
+
+ /**
+ * This is a convenience function that is the same as calling calc(-1).
+ * @see calc();
+ */
+ bool calcAll();
+
+ protected:
+ /**
+ * Initializes the base algorithm. Doesn't perform any actual
generation.
+ * @param field The array of integers in which to generate the spiral
field.
+ * @param screenWidth the width of the screen in pixels.
+ * @param screenHeight the height of the screen in pixels.
+ * @param numColors the number of colors in the palette primary
direction.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @see initialize()
+ */
+ void initialize(int* field, int screenWidth, int screenHeight,
+ int numColors, int colorWidth, int emptyWidth,
+ bool bConstantColor);
+
+ int _width;
+ int _height;
+ int _numColors;
+ int _colorWidth;
+ int _emptyWidth;
+ bool _bConstantColor;
+};
+
+#endif
=======================================
--- /src/PlasmaGenerator/resource_files/win_resource.rc Sun Jan 11 19:38:31
2009 UTC
+++ /src/PlasmaGenerator/resource_files/win_resource.rc Mon Mar 16 21:29:13
2009 UTC
@@ -77,7 +77,7 @@
STRINGTABLE
BEGIN
- IDS_DESCRIPTION "PlasmaLenz"
+ IDS_DESCRIPTION "PlasmaGenerator"
END
#endif // English (U.S.) resources
==============================================================================
Revision: 82aa12a01f77
Author: Jeff Backus <
jeff....@gmail.com>
Date: Mon Apr 27 00:56:58 2009 UTC
Log: Made a number of changes, but currently working on redoing the
spiral algorithm to use
a generic N-gon+polar spiral algorithm.
http://code.google.com/p/idlescreen/source/detail?r=82aa12a01f77
Added:
/src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp
/src/SpiralLenz/src/RectangularSpiralBackgroundProfile.h
/src/common/spirals/NgonSpiralAlgorithm.cpp
/src/common/spirals/NgonSpiralAlgorithm.h
Modified:
/Makefile.in
/
configure.ac
/src/SpiralLenz/project_files/SpiralLenz_glut.pro
/src/SpiralLenz/project_files/SpiralLenz_scr.pro
/src/SpiralLenz/resource_files/defaults.xml
/src/SpiralLenz/src/ConfigWidget.cpp
/src/SpiralLenz/src/ProfileEditDialog.h
/src/SpiralLenz/src/SpiralBackground.cpp
/src/SpiralLenz/src/SpiralBackground.h
/src/SpiralLenz/src/SpiralBackgroundProfile.cpp
/src/SpiralLenz/src/SpiralBackgroundProfile.h
/src/SpiralLenz/src/project_specific_externs.cpp
/src/SpiralLenz/src/redirector_main.cpp
/src/common/2d_bgnd_w_lens/Background.h
/src/common/2d_bgnd_w_lens/BackgroundProfile.cpp
/src/common/2d_bgnd_w_lens/BackgroundProfile.h
/src/common/spirals/RectangularSpiralAlgorithm.cpp
/src/common/spirals/RectangularSpiralAlgorithm.h
/src/common/spirals/SpiralAlgorithm.cpp
/src/common/spirals/SpiralAlgorithm.h
/src/common/utility/misc_funcs.cpp
/src/common/utility/misc_funcs.h
=======================================
--- /dev/null
+++ /src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp Mon Apr 27
00:56:58 2009 UTC
@@ -0,0 +1,304 @@
+/**
+ * Copyright (c) 2008 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/
+ *
+ */
+
+// begin debug
+#include <iostream>
+using namespace std;
+// end debug
+
+#include <QtXml/QDomElement>
+#include <QtXml/QDomText>
+
+#include "utility/misc_funcs.h"
+#include "spirals/RectangularSpiralAlgorithm.h"
+#include "RectangularSpiralBackgroundProfile.h"
+#include "SpiralBackground.h"
+
+// begin tmp
+#include "spirals/NgonSpiralAlgorithm.h"
+// end tmp
+
+RectangularSpiralBackgroundProfile::RectangularSpiralBackgroundProfile() {
+ _xmlTypeValue = "RectangularSpiralBackground";
+
+ //defaults
+ _colorWidth = 2;
+ _emptyWidth = 1;
+ _bConstantColor = false;
+ _bRandomColor = false;
+ _bIncrementColor = false;
+}
+
+RectangularSpiralBackgroundProfile::~RectangularSpiralBackgroundProfile() {
+ // no es nada
+}
+
+/**
+ * Attempts to load this background profile object from the
+ * specified QDomNode.
+ */
+BackgroundProfile* RectangularSpiralBackgroundProfile::load(QDomNode
&node) {
+ int tmpI;
+ QDomElement tempElem;
+
+ //sanity check on the input
+ if(node.nodeName() != getXMLTagName())
+ return NULL;
+
+ //make sure that the type value matches
+ tempElem = node.firstChildElement("type");
+ if(tempElem.isNull() || tempElem.text() != _xmlTypeValue)
+ return NULL;
+
+ RectangularSpiralBackgroundProfile* retVal = new
RectangularSpiralBackgroundProfile();
+ if(retVal == NULL)
+ return NULL;
+
+ // load base
+ retVal->loadBase(node);
+
+ // load extended data
+ tempElem = node.firstChildElement("color_width");
+ if(!tempElem.isNull()) {
+ tmpI = tempElem.text().toInt();
+ retVal->setColorWidth(tmpI);
+ }
+
+ tempElem = node.firstChildElement("empty_width");
+ if(!tempElem.isNull()) {
+ tmpI = tempElem.text().toInt();
+ retVal->setEmptyWidth(tmpI);
+ }
+
+ tempElem = node.firstChildElement("constant_color");
+ if(!tempElem.isNull()) {
+ QString param = tempElem.text();
+ retVal->setConstantColor(stringToBool(param));
+ }
+
+ tempElem = node.firstChildElement("random_color");
+ if(!tempElem.isNull()) {
+ QString param = tempElem.text();
+ retVal->setRandomColor(stringToBool(param));
+ }
+
+ tempElem = node.firstChildElement("increment_color");
+ if(!tempElem.isNull()) {
+ QString param = tempElem.text();
+ retVal->setColorIncrement(stringToBool(param));
+ }
+
+ // return new profile
+ return retVal;
+}
+
+/**
+ * Returns a QDomNode object that represents this profile.
+ */
+QDomNode RectangularSpiralBackgroundProfile::save(QDomDocument* doc) {
+ QString tempStr;
+ QDomText tempNode;
+ QDomElement tempElem;
+ QDomElement retVal = doc->createElement(getXMLTagName());
+
+ //type
+ tempNode = doc->createTextNode(_xmlTypeValue);
+ tempElem = doc->createElement("type");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ // save base class values
+ saveBase(&retVal, doc);
+
+ // save extended data
+ //color width
+ tempStr.setNum(_colorWidth);
+ tempNode = doc->createTextNode(tempStr);
+ tempElem = doc->createElement("color_width");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //empty width
+ tempStr.setNum(_emptyWidth);
+ tempNode = doc->createTextNode(tempStr);
+ tempElem = doc->createElement("empty_width");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //constant color?
+ tempNode = doc->createTextNode(boolToString(_bConstantColor));
+ tempElem = doc->createElement("constant_color");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //random color?
+ tempNode = doc->createTextNode(boolToString(_bRandomColor));
+ tempElem = doc->createElement("random_color");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ //increment color?
+ tempNode = doc->createTextNode(boolToString(_bIncrementColor));
+ tempElem = doc->createElement("increment_color");
+ tempElem.appendChild(tempNode);
+ retVal.appendChild(tempElem);
+
+ // return node.
+ return retVal;
+}
+
+ /**
+ * Gets the width of the line to be filled with color
+ */
+int RectangularSpiralBackgroundProfile::getColorWidth() {
+ return _colorWidth;
+}
+
+ /**
+ * Sets the width of the line to be filled with color.
+ */
+void RectangularSpiralBackgroundProfile::setColorWidth(int colorWidth) {
+ cout<<"Attempting to set color width to "<<colorWidth<<"...";
+ if(0 < colorWidth && colorWidth < 30000) {
+ _colorWidth = colorWidth;
+ cout<<"Successful.";
+ }
+ cout<<endl;
+}
+
+ /**
+ * Gets the width of the line to be filled with "empty space" (palette's
+ * default color).
+ */
+int RectangularSpiralBackgroundProfile::getEmptyWidth() {
+ return _emptyWidth;
+}
+
+ /**
+ * Gets the width of the line to be filled with "empty space" (palette's
+ * default color).
+ */
+void RectangularSpiralBackgroundProfile::setEmptyWidth(int emptyWidth) {
+ if(0 <= emptyWidth && emptyWidth < 30000) {
+ _emptyWidth = emptyWidth;
+ }
+}
+
+ /**
+ * Gets whether or not the color should remain constant.
+ */
+bool RectangularSpiralBackgroundProfile::isConstantColor() {
+ return _bConstantColor;
+}
+
+ /**
+ * Sets whether or not the color should remain constant.
+ */
+void RectangularSpiralBackgroundProfile::setConstantColor(bool
bConstantColor) {
+ _bConstantColor = bConstantColor;
+}
+
+ /**
+ * Gets whether or not the initial color is random or index 0.
+ */
+bool RectangularSpiralBackgroundProfile::isRandomColor() {
+ return _bRandomColor;
+}
+
+ /**
+ * Sets whether or not the initial color is random or index 0.
+ */
+void RectangularSpiralBackgroundProfile::setRandomColor(bool bRandomColor)
{
+ _bRandomColor = bRandomColor;
+}
+
+/**
+ * Gets whether or not the color index increases as it spirals out.
+ */
+bool RectangularSpiralBackgroundProfile::doesColorIncrement() {
+ return _bIncrementColor;
+}
+
+ /**
+ * Sets whether or not the color index increases as it spirals out.
+ */
+void RectangularSpiralBackgroundProfile::setColorIncrement(bool
bIncrementColor) {
+ _bIncrementColor = bIncrementColor;
+}
+
+/**
+ * Creates and returns a new background object.
+ */
+Background* RectangularSpiralBackgroundProfile::getNewBackgroundObj(int
height,
+ int width,
+ QHash<QString, IndexedPaletteProfile*>* palHash) {
+
+
+ NgonSpiralAlgorithm* alg =
+ new NgonSpiralAlgorithm(0,_colorWidth,_emptyWidth,_bConstantColor,
+ _bRandomColor, _bIncrementColor);
+ /*
+ RectangularSpiralAlgorithm* alg =
+ new RectangularSpiralAlgorithm(_colorWidth,_emptyWidth,_bConstantColor,
+ _bRandomColor, _bIncrementColor);
+ */
+ if(alg == NULL)
+ return NULL;
+
+ return new SpiralBackground(width, height, alg,
+ palHash->value(_palName)->createPalette(),
+ _bAnimatePalette, _paletteXSpeed, _paletteYSpeed,
+ _genStepsPerTick);
+}
+
+/**
+ * Overloaded assignment operator
+ */
+RectangularSpiralBackgroundProfile&
RectangularSpiralBackgroundProfile::operator=(RectangularSpiralBackgroundProfile&
other) {
+
+ baseCopy(other);
+
+ _colorWidth = other._colorWidth;
+ _emptyWidth = other._emptyWidth;
+ _bConstantColor = other._bConstantColor;
+ _bRandomColor = other._bRandomColor;
+ _bIncrementColor = other._bIncrementColor;
+
+ return *this;
+}
+
+/**
+ * Creates a new object with this object's settings.
+ */
+BackgroundProfile* RectangularSpiralBackgroundProfile::clone() {
+ RectangularSpiralBackgroundProfile* retVal =
+ new RectangularSpiralBackgroundProfile();
+
+ *retVal = *this;
+
+ return (BackgroundProfile*)retVal;
+}
+
+
+
=======================================
--- /dev/null
+++ /src/SpiralLenz/src/RectangularSpiralBackgroundProfile.h Mon Apr 27
00:56:58 2009 UTC
@@ -0,0 +1,135 @@
+/**
+ * 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 is the base class for all spiral background profiles.
+ *
+ * @author jeff backus
+ * @date 03/23/2009
+ */
+
+#ifndef __RECTANGULARSPIRALBACKGROUNDPROFILE_H__
+#define __RECTANGULARSPIRALBACKGROUNDPROFILE_H__
+
+#include <QString>
+#include <QtXml/QDomNode>
+#include <QtXml/QDomDocument>
+
+#include "SpiralBackgroundProfile.h"
+
+class RectangularSpiralBackgroundProfile : public SpiralBackgroundProfile {
+
+ public:
+ RectangularSpiralBackgroundProfile();
+ ~RectangularSpiralBackgroundProfile();
+
+ /**
+ * Attempts to load this background profile object from the
+ * specified QDomNode.
+ */
+ BackgroundProfile* load(QDomNode &node);
+
+ /**
+ * Returns a QDomNode object that represents this profile.
+ */
+ QDomNode save(QDomDocument* doc);
+
+ /**
+ * Creates and returns a new background object.
+ */
+ Background* getNewBackgroundObj(int height, int width,
+ QHash<QString, IndexedPaletteProfile*>* palHash
+ );
+
+ /**
+ * Gets the width of the line to be filled with color
+ */
+ int getColorWidth();
+
+ /**
+ * Sets the width of the line to be filled with color.
+ */
+ void setColorWidth(int colorWidth);
+
+ /**
+ * Gets the width of the line to be filled with "empty space" (palette's
+ * default color).
+ */
+ int getEmptyWidth();
+
+ /**
+ * Gets the width of the line to be filled with "empty space" (palette's
+ * default color).
+ */
+ void setEmptyWidth(int emptyWidth);
+
+ /**
+ * Gets whether or not the color should remain constant.
+ */
+ bool isConstantColor();
+
+ /**
+ * Sets whether or not the color should remain constant.
+ */
+ void setConstantColor(bool bConstantColor);
+
+ /**
+ * Gets whether or not the initial color is random or index 0.
+ */
+ bool isRandomColor();
+
+ /**
+ * Sets whether or not the initial color is random or index 0.
+ */
+ void setRandomColor(bool bRandomColor);
+
+ /**
+ * Gets whether or not the color index increases as it spirals out.
+ */
+ bool doesColorIncrement();
+
+ /**
+ * Sets whether or not the color index increases as it spirals out.
+ */
+ void setColorIncrement(bool bIncrementColor);
+
+ /**
+ * Overloaded assignment operator.
+ */
+ RectangularSpiralBackgroundProfile&
operator=(RectangularSpiralBackgroundProfile& other);
+
+ /**
+ * Creates a new object with this object's settings.
+ */
+ BackgroundProfile* clone();
+
+ private:
+
+ int _colorWidth;
+ int _emptyWidth;
+ bool _bConstantColor;
+ bool _bRandomColor;
+ bool _bIncrementColor;
+};
+#endif
=======================================
--- /dev/null
+++ /src/common/spirals/NgonSpiralAlgorithm.cpp Mon Apr 27 00:56:58 2009 UTC
@@ -0,0 +1,258 @@
+
+// debug
+#include <iostream>
+// end debug
+#include <math.h>
+using namespace std;
+
+#include "NgonSpiralAlgorithm.h"
+
+/**
+ * Constructor.
+ */
+NgonSpiralAlgorithm::NgonSpiralAlgorithm() {
+
+ // parameters
+ _n = 0;
+ _colorWidth = 1;
+ _emptyWidth = 0;
+ _bConstantColor = true;
+ _bRandomColor = false;
+ _bIncrementColor = true;
+
+ // internals
+ _nextIdx = 0;
+ _currX = 0.0;
+ _currY = 0.0;
+ _rCoeff = 0.0;
+ _currR = 0.0;
+ _currTheta = 0.0;
+ _maxR = 0.0;
+
+ // misc constants
+ _maxFieldIdx = 0;
+ _screenXOffset = 0;
+ _screenYOffset = 0;
+}
+
+ /**
+ * Constructor takes initialization parameters.
+ * @param N the number of sides the Ngon has. N=0 for a polar spiral.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @param bRandomColor whether or not the initial color is randomly
selected.
+ * @param bIncrementColor whether to increment the color as it spirals
out.
+ * @see calc()
+ */
+NgonSpiralAlgorithm::NgonSpiralAlgorithm(const int N, const int colorWidth,
+ const int emptyWidth,
+ const bool bConstantColor,
+ const bool bRandomColor,
+ const bool bIncrementColor) {
+
+ // empty constants until initialize(...) is called
+ _maxFieldIdx = 0;
+ _screenXOffset = 0;
+ _screenYOffset = 0;
+ _maxR = 0.0;
+
+ // initial values for internals
+ _nextIdx = 0;
+ _currX = 0.0;
+ _currY = 0.0;
+
+ // set parameters
+ _n = N;
+ _colorWidth = colorWidth;
+ _emptyWidth = emptyWidth;
+ _bConstantColor = bConstantColor;
+ _bRandomColor = bRandomColor;
+ _bIncrementColor = bIncrementColor;
+
+ if(_colorWidth < 0)
+ _colorWidth = 0;
+ if(_emptyWidth < 0)
+ _emptyWidth = 0;
+
+ // calculate misc constants
+ _segmentWidth = _colorWidth + (_emptyWidth<<1);
+
+ // calculate spiral constants and initial values
+ _rCoeff = double(_segmentWidth)/(2.0*NGONSPIRAL_PI);
+ _rCoeff *= (jrand() % 2 == 0) ? 1.0 : -1.0; // whether clockwise or not.
+ _currR = 0.0;
+
+ // for now, just start at 0.
+ _currTheta = 0.0;
+ _lastThetaStep = NGONSPIRAL_PI/16.0;
+
+}
+
+
+NgonSpiralAlgorithm::~NgonSpiralAlgorithm() {
+}
+
+/**
+ * Initializes the algorithm. Doesn't perform any actual generation.
+ * @param field The array of integers in which to generate the spiral
field.
+ * @param screenWidth the width of the screen in pixels.
+ * @param screenHeight the height of the screen in pixels.
+ * @param numColors the number of colors in the palette primary direction.
+ */
+void NgonSpiralAlgorithm::initialize(int* field, const int screenWidth,
+ const int screenHeight,
+ const int numColors) {
+ initializeBase(field, screenWidth, screenHeight, numColors);
+
+ if(_height <= 0)
+ return;
+ if(_width <= 0)
+ return;
+ if(_numColors <= 0)
+ return;
+
+ // calculate remaining internal constants
+ _maxFieldIdx = screenWidth * screenHeight - 1;
+ _screenXOffset = screenWidth>>1;
+ _screenYOffset = screenHeight>>1;
+
+ // calculate polar stopping condition.
+ _maxR = sqrt( _screenXOffset*_screenXOffset +
+ _screenYOffset*_screenYOffset);
+
+ // pick initial color
+ if(_bRandomColor) {
+ _nextIdx = jrand() % numColors;
+ } else {
+ _nextIdx = 0;
+ }
+
+ // begin debug
+ _stepCount = 128; //16;
+ // end debug
+
+}
+
+/**
+ * Completes one iteration of the algorithm. Returns true if the algorithm
+ * is completed.
+ */
+bool NgonSpiralAlgorithm::calc() {
+ if(_field == NULL)
+ return true;
+
+ if(_stepCount < 0)
+ return true;
+ //_stepCount--;
+ // if N is valid, use the N-gon spiral calculations.
+ // Otherwise, use the polar spiral calculations
+ bool retVal;
+ if(2 < _n && _n <= NGONSPIRAL_MAX_N) {
+ retVal = true; // < Temporary!
+ } else {
+ retVal = calcSpiral(&_currX, &_currY, &_currR, &_currTheta,
+ &_lastThetaStep);
+ //retVal = (_currR >= _maxR);
+ }
+
+ // set pixel to next color, if it is within the boundaries.
+ int px = roundDtoI(_currX)+_screenXOffset;
+ int py = roundDtoI(_currY)+_screenYOffset;
+ int fieldIdx = px+py*_width;
+ if(0 <= px && px < _width && 0 <= py && py < _height &&
+ fieldIdx < _maxFieldIdx) {
+ _field[fieldIdx] = _nextIdx;
+ }
+
+ // update color
+ if(!_bConstantColor) {
+ if(_bIncrementColor) {
+ _nextIdx = (_nextIdx+1)%_numColors;
+ } else {
+ _nextIdx = _nextIdx - 1;
+ if(_nextIdx < 0) {
+ _nextIdx = _numColors - _nextIdx;
+ }
+ }
+ }
+
+ return retVal;
+}
+
+/**
+ * Calculates a new X,Y using a polar spiral. Utilizes an adaptive
+ * algorithm to adjust thetaStep such that the new (x,y) value will
+ * be adjacent but not on the previous (x,y) value.
+ *
+ * @param x the previous X value. On return, it is the new X value.
+ * @param y the previous Y value. On return, it is the new Y value.
+ * @param r the previous R value. On return, it is the new R value.
+ * @param theta the previous Theta value. It is updated on return.
+ * @param thetaStep the previous Theta step value. Updated on return.
+ * @return True if the calculation is complete.
+ */
+bool NgonSpiralAlgorithm::calcSpiral(double* x, double* y, double* r,
+ double* theta, double* thetaStep) {
+ //cout<<"Entering calcSpiral"<<endl;
+ double newX;
+ double newY;
+ double newR;
+ double newTheta;
+ double newThetaStep = *thetaStep;
+
+ int iOldX = roundDtoI(*x);
+ int iOldY = roundDtoI(*y);
+ int iNewX;
+ int iNewY;
+
+ int escape_count = 0;
+ bool bDone = false;
+ while(!bDone) {
+ // update Theta
+ newTheta = *theta + newThetaStep;
+
+ // calculate the new R, X and Y
+ newR = _rCoeff * newTheta;
+ newX = newR * cos(newTheta);
+ newY = newR * sin(newTheta);
+
+ // check to see if we've calculated for an adjacent pixel
+ iNewX = roundDtoI(newX);
+ iNewY = roundDtoI(newY);
+ /*
+ cout<<"newX: "<<newX<<","<<iNewX<<endl;
+ cout<<"newY: "<<newY<<","<<iNewY<<endl;
+ cout<<"oldX: "<<*x<<","<<iOldX<<endl;
+ cout<<"oldY: "<<*y<<","<<iOldY<<endl;
+ */
+
+ bDone = true;
+ if(iNewX == iOldX && iNewY == iOldY) {
+ // theta too small
+ newThetaStep*=2.0;
+ bDone = false;
+ } else if(iNewX <= iOldX-2 || iOldX+2 <= iNewX ||
+ iNewY <= iOldY-2 || iOldY+2 <= iNewY) {
+ // theta too large
+ newThetaStep*=0.5;
+ bDone = false;
+ }
+
+ if(++escape_count >= 100) {
+ cout<<"NgonSpiralAlgorithm::calcSpiral() Escape count
reached!"<<endl;
+ cout<<"maxR: "<<_maxR<<endl;
+ //exit(1);
+ //*r = _maxR+1.0;
+ _maxR = -1;
+ bDone = true;
+ }
+ }
+ *x = newX;
+ *y = newY;
+ *r = newR;
+ *theta = newTheta;
+ *thetaStep = newThetaStep;
+
+ return (newR >= _maxR);
+}
=======================================
--- /dev/null
+++ /src/common/spirals/NgonSpiralAlgorithm.h Mon Apr 27 00:56:58 2009 UTC
@@ -0,0 +1,167 @@
+/**
+ * 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 is a generic N-gon spiral algorithm. If N is invalid, a polar
+ * spiral algorithm is used.
+ */
+
+#include "utility/misc_funcs.h"
+#include "SpiralAlgorithm.h"
+
+#ifndef __NGONSPIRALALGORITHM_H__
+#define __NGONSPIRALALGORITHM_H__
+
+//enum NgonSpiralAlgorithmDir { UP=0, DOWN=1, LEFT=2, RIGHT=3 };
+
+#define NGONSPIRAL_PI 3.14159265f
+#define NGONSPIRAL_MAX_N 20
+
+class NgonSpiralAlgorithm : public SpiralAlgorithm {
+
+ public:
+
+ /**
+ * Default constructor.
+ */
+ NgonSpiralAlgorithm();
+
+ /**
+ * Constructor takes initialization parameters.
+ * @param N the number of sides the Ngon has. N=0 for a polar spiral.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @param bRandomColor whether or not the initial color is randomly
selected.
+ * @param bIncrementColor whether to increment the color as it spirals
out.
+ * @see calc()
+ */
+ NgonSpiralAlgorithm(const int N, const int colorWidth, const int
emptyWidth,
+ const bool bConstantColor, const bool bRandomColor,
+ const bool bIncrementColor);
+
+ ~NgonSpiralAlgorithm();
+
+ /**
+ * Initializes the algorithm. Doesn't perform any actual generation.
+ * @param field The array of integers in which to generate the spiral
field.
+ * @param screenWidth the width of the screen in pixels.
+ * @param screenHeight the height of the screen in pixels.
+ * @param numColors the number of colors in the palette primary
direction.
+ */
+ void initialize(int* field, const int screenWidth,
+ const int screenHeight, const int numColors);
+
+ /**
+ * Completes one iteration of the algorithm. Returns true if the
algorithm
+ * is completed.
+ */
+ bool calc();
+
+ private:
+ /**
+ * Calculates a new X,Y using a polar spiral. Utilizes an adaptive
+ * algorithm to adjust thetaStep such that the new (x,y) value will
+ * be adjacent but not on the previous (x,y) value.
+ * @param x the previous X value. On return, it is the new X value.
+ * @param y the previous Y value. On return, it is the new Y value.
+ * @param r the previous R value. On return, it is the new R value.
+ * @param theta the previous Theta value. It is updated on return.
+ * @param thetaStep the previous Theta step value. Updated on return.
+ * @return True if the calculation is complete.
+ */
+ bool calcSpiral(double* x, double* y, double* r, double* theta,
+ double* thetaStep);
+
+ /**
+ * Calculates both the corner and "straight away" segments.
+ * These segments are _segmentSize x _segmentSize in size.
+ * They are also oriented such that (0,0) is the bottom left corner.
+ * _straightSeg is such that it flows from left to right, and
+ * _cornerSeg is such that it flows from right to up if _bClockwise
+ * is false, or right to down if _bClockwise is true. Note that in
+ * either case, the color index offset has not been properly modulo'd
+ * and should be done so after being added to the current color index,
+ * if _bConstantColor is false. In the case where _bConstantColor is
+ * true, the index offset will always be 0.
+ */
+ //void calcSegments();
+
+ /**
+ * Rotates and draws the specified segment at (_currX,_currY) based
+ * on _dir.
+ * @param seg Must be either _cornerSeg or _straightSeg.
+ */
+ //void drawSegment(int* seg);
+
+ // begin parameters
+ int _n;
+ int _colorWidth;
+ int _emptyWidth;
+ bool _bConstantColor;
+ bool _bRandomColor;
+ bool _bIncrementColor;
+ // end parameters
+
+ // begin spiral specific
+ double _rCoeff; // accounts for clockwise/counterclockwise!
+ double _currR;
+ double _currTheta;
+ double _lastThetaStep;
+ double _maxR; //!< polar stopping condition
+ // end spiral specific
+
+ double _currX;
+ double _currY;
+ int _nextIdx;
+
+ // begin constants to speed up calculations
+ int _screenXOffset;
+ int _screenYOffset;
+ int _segmentWidth;
+ int _maxFieldIdx; //> _sizeX * _sizeY - 1;
+ // end constants
+
+ // begin debug
+ int _stepCount;
+
+ /*
+ int* _cornerSeg;
+ int* _straightSeg;
+
+ NgonSpiralAlgorithmDir _dir;
+ bool _bClockwise;
+
+ int _xSegs; //> either current or next number of segments
+ int _ySegs; //> either current or next number of segments
+ int _remainingSegs; //> Segments remaining to draw.
+ int _xMaxSegs; //> Maximum number of segments in the x direction.
+ int _yMaxSegs; //> Maximum number of segments in the y direction.
+
+ // These are to speed up some calculations, since they only need done
once.
+ float _halfSegSize; //> _segmentSize / 2.0
+ */
+};
+
+#endif
=======================================
--- /Makefile.in Mon Mar 9 01:35:05 2009 UTC
+++ /Makefile.in Mon Apr 27 00:56:58 2009 UTC
@@ -89,6 +89,16 @@
-o Makefile.PlasmaGenerator && \
$(MAKE) -f Makefile.PlasmaGenerator
+bin/SpiralLenz : src/SpiralLenz/project_files/SpiralLenz_scr.pro
+ cd $(srcdir)/src/SpiralLenz/project_files/ && $(QMAKE) SpiralLenz_scr.pro
\
+ -o Makefile.SpiralLenz_scr && \
+ $(MAKE) -f Makefile.SpiralLenz_scr
+
+bin/SpiralLenz_glut : src/SpiralLenz/project_files/SpiralLenz_glut.pro
+ cd $(srcdir)/src/SpiralLenz/project_files/ && $(QMAKE)
SpiralLenz_glut.pro \
+ -o Makefile.SpiralLenz_glut && \
+ $(MAKE) -f Makefile.SpiralLenz_glut
+
doc :
cd doc; $(MAKE)
@@ -97,6 +107,7 @@
-rm bin/PlasmaLenz bin/PlasmaLenz_glut
-rm bin/Crawlies bin/Crawlies_glut
-rm bin/AcidRain bin/AcidRain_glut
+ -rm bin/SpiralLenz bin/SpiralLenz_glut
-rm bin/PlasmaGenerator
-cd $(srcdir)/src/PlasmaLenz/project_files/ && $(MAKE) -f
Makefile.PlasmaLenz_scr clean
-cd $(srcdir)/src/PlasmaLenz/project_files/ && $(MAKE) -f
Makefile.PlasmaLenz_glut clean
@@ -104,6 +115,8 @@
-cd $(srcdir)/src/Crawlies/project_files/ && $(MAKE) -f
Makefile.Crawlies_glut clean
-cd $(srcdir)/src/AcidRain/project_files/ && $(MAKE) -f
Makefile.AcidRain_scr clean
-cd $(srcdir)/src/AcidRain/project_files/ && $(MAKE) -f
Makefile.AcidRain_glut clean
+ -cd $(srcdir)/src/SpiralLenz/project_files/ && $(MAKE) -f
Makefile.SpiralLenz_scr clean
+ -cd $(srcdir)/src/SpiralLenz/project_files/ && $(MAKE) -f
Makefile.SpiralLenz_glut clean
-cd $(srcdir)/src/PlasmaGenerator/project_files/ && $(MAKE) -f
Makefile.PlasmaGenerator clean
-cd doc; $(MAKE) -f Makefile clean
@@ -112,12 +125,15 @@
-rm bin/PlasmaLenz bin/PlasmaLenz_glut
-rm bin/Crawlies bin/Crawlies_glut
-rm bin/AcidRain bin/AcidRain_glut
+ -rm bin/SpiralLenz bin/SpiralLenz_glut
-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
-cd $(srcdir)/src/Crawlies/project_files/ && $(MAKE) -f
Makefile.Crawlies_glut distclean
-cd $(srcdir)/src/AcidRain/project_files/ && $(MAKE) -f
Makefile.AcidRain_scr distclean
-cd $(srcdir)/src/AcidRain/project_files/ && $(MAKE) -f
Makefile.AcidRain_glut distclean
+ -cd $(srcdir)/src/SpiralLenz/project_files/ && $(MAKE) -f
Makefile.SpiralLenz_scr distclean
+ -cd $(srcdir)/src/SpiralLenz/project_files/ && $(MAKE) -f
Makefile.SpiralLenz_glut distclean
-cd $(srcdir)/src/PlasmaGenerator/project_files/ && $(MAKE) -f
Makefile.PlasmaGenerator distclean
-cd doc; $(MAKE) -f Makefile distclean
-rm -rf autom4te.cache
=======================================
--- /
configure.ac Mon Mar 9 01:35:05 2009 UTC
+++ /
configure.ac Mon Apr 27 00:56:58 2009 UTC
@@ -127,6 +127,33 @@
[man_targets="$man_targets PlasmaGenerator/man_page/PlasmaGenerator.1"]
fi
+AC_ARG_ENABLE([spirallenz], [AC_HELP_STRING([--enable-spirallenz],
+ [build SpiralLenz screen saver default=yes])],
+ [enable_spirallenz=$enableval],
+ [enable_spirallenz=yes])
+
+if test "$enable_spirallenz" == "yes";
+ then
+ [qt_targets="$qt_targets SpiralLenz"]
+ [data_targets="$data_targets SpiralLenz.xml"]
+ [man_targets="$man_targets SpiralLenz/man_page/SpiralLenz.1"]
+fi
+
+AC_ARG_ENABLE([spirallenz-glut],
[AC_HELP_STRING([--enable-spirallenz-glut],
+ [build SpiralLenz GLUT demo default=no])],
+ [enable_spirallenz_glut=$enableval],
+ [enable_spirallenz_glut=no])
+
+if test "$enable_spirallenz_glut" == "yes";
+ then
+ [qt_targets="$qt_targets SpiralLenz_glut"]
+ [enable_glut="yes"]
+ [data_targets="$data_targets SpiralLenz.xml"]
+ [man_targets="$man_targets SpiralLenz/man_page/SpiralLenz.1"]
+fi
+
+
+# substitute in targets
AC_SUBST(bintrg, $qt_targets)
AC_SUBST(datatrg, $data_targets)
AC_SUBST(mantrg, $man_targets)
=======================================
--- /src/SpiralLenz/project_files/SpiralLenz_glut.pro Mon Mar 16 21:29:13
2009 UTC
+++ /src/SpiralLenz/project_files/SpiralLenz_glut.pro Mon Apr 27 00:56:58
2009 UTC
@@ -14,7 +14,12 @@
INCLUDEPATH = $$COMMON_PATH $$SOURCE_PATH $$RESOURCE_PATH
-SOURCES = $$COMMON_PATH/core/glut_demo.cpp
$$COMMON_PATH/core/win_misc_funcs.cpp
+SOURCES = $$COMMON_PATH/core/glut_demo.cpp
+SOURCES += $$COMMON_PATH/core/win_misc_funcs.cpp
+
+SOURCES += $$COMMON_PATH/spirals/SpiralAlgorithm.cpp
+SOURCES += $$COMMON_PATH/spirals/RectangularSpiralAlgorithm.cpp
+SOURCES += $$COMMON_PATH/spirals/NgonSpiralAlgorithm.cpp
SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPalette.cpp
SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialog.cpp
@@ -28,11 +33,12 @@
SOURCES += $$COMMON_PATH/utility/ImportExportDialog.cpp
SOURCES += $$COMMON_PATH/utility/HelpDialog.cpp
SOURCES += $$COMMON_PATH/gpl_related/gpldialog.cpp
-SOURCES += $$COMMON_PATH/plasma/PlasmaAlgorithm.cpp
SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/opengl_main.cpp
-SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/Background.cpp
$$COMMON_PATH/2d_bgnd_w_lens/BackgroundProfile.cpp
-SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/configdlg_main.cpp
$$COMMON_PATH/2d_bgnd_w_lens/ConfigManager.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/Background.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/BackgroundProfile.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/configdlg_main.cpp
+SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/ConfigManager.cpp
SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/IndexedPaletteBackground.cpp
SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/MasterProfile.cpp
SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/PaletteEditor.cpp
@@ -44,13 +50,20 @@
SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensManager.cpp
SOURCES +=
$$COMMON_PATH/2d_bgnd_w_lens/lens_engine/SphericalLensProfile.cpp
-SOURCES += $$SOURCE_PATH/ConfigWidget.cpp $$SOURCE_PATH/PlasmaFractal.cpp
-SOURCES += $$SOURCE_PATH/PlasmaFractalBackgroundProfile.cpp
$$SOURCE_PATH/project_specific_externs.cpp
+SOURCES += $$SOURCE_PATH/ConfigWidget.cpp
+SOURCES += $$SOURCE_PATH/project_specific_externs.cpp
SOURCES += $$COMMON_PATH/utility/AboutDialog.cpp
-SOURCES += $$SOURCE_PATH/ProfileEditDialog.cpp
+//SOURCES += $$SOURCE_PATH/ProfileEditDialog.cpp
+SOURCES += $$SOURCE_PATH/SpiralBackground.cpp
+SOURCES += $$SOURCE_PATH/SpiralBackgroundProfile.cpp
+SOURCES += $$SOURCE_PATH/RectangularSpiralBackgroundProfile.cpp
HEADERS = $$COMMON_PATH/core/win_misc_funcs.h
+HEADERS += $$COMMON_PATH/spirals/SpiralAlgorithm.h
+HEADERS += $$COMMON_PATH/spirals/RectangularSpiralAlgorithm.h
+HEADERS += $$COMMON_PATH/spirals/NgonSpiralAlgorithm.h
+
HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPalette.h
HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialog.h
HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialogEntryButton.h
@@ -63,10 +76,10 @@
HEADERS += $$COMMON_PATH/utility/ImportExportDialog.h
HEADERS += $$COMMON_PATH/utility/HelpDialog.h
HEADERS += $$COMMON_PATH/gpl_related/gpldialog.h
-HEADERS += $$COMMON_PATH/plasma/PlasmaAlgorithm.h
HEADERS += $$COMMON_PATH/core/opengl_main.h
-HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/Background.h
$$COMMON_PATH/2d_bgnd_w_lens/BackgroundProfile.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/Background.h
+HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/BackgroundProfile.h
HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/ConfigManager.h
HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/IndexedPaletteBackground.h
HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/MasterProfile.h
@@ -82,10 +95,12 @@
HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/LensManager.h
HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/lens_engine/SphericalLensProfile.h
-HEADERS += $$SOURCE_PATH/PlasmaFractalBackgroundProfile.h
$$SOURCE_PATH/PlasmaFractal.h
HEADERS += $$RESOURCE_PATH/resource.h
HEADERS += $$COMMON_PATH/utility/AboutDialog.h
-HEADERS += $$SOURCE_PATH/ProfileEditDialog.h
+//HEADERS += $$SOURCE_PATH/ProfileEditDialog.h
+HEADERS += $$SOURCE_PATH/SpiralBackground.h
+HEADERS += $$SOURCE_PATH/SpiralBackgroundProfile.h
+HEADERS += $$SOURCE_PATH/RectangularSpiralBackgroundProfile.h
TARGET = SpiralLenz_glut
RESOURCES = $$RESOURCE_PATH/qt_resource.qrc
=======================================
--- /src/SpiralLenz/project_files/SpiralLenz_scr.pro Mon Mar 16 21:29:13
2009 UTC
+++ /src/SpiralLenz/project_files/SpiralLenz_scr.pro Mon Apr 27 00:56:58
2009 UTC
@@ -18,6 +18,9 @@
unix:SOURCES = $$COMMON_PATH/core/unix_main.cpp
SOURCES += $$COMMON_PATH/core/win_misc_funcs.cpp
+SOURCES += $$COMMON_PATH/spirals/SpiralAlgorithm.cpp
+SOURCES += $$COMMON_PATH/spirals/RectangularSpiralAlgorithm.cpp
+
SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPalette.cpp
SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialog.cpp
SOURCES +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteDialogEntryButton.cpp
@@ -30,7 +33,6 @@
SOURCES += $$COMMON_PATH/utility/ImportExportDialog.cpp
SOURCES += $$COMMON_PATH/utility/HelpDialog.cpp
SOURCES += $$COMMON_PATH/gpl_related/gpldialog.cpp
-SOURCES += $$COMMON_PATH/plasma/PlasmaAlgorithm.cpp
SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/opengl_main.cpp
SOURCES += $$COMMON_PATH/2d_bgnd_w_lens/Background.cpp
$$COMMON_PATH/2d_bgnd_w_lens/BackgroundProfile.cpp
@@ -53,6 +55,9 @@
HEADERS = $$COMMON_PATH/core/win_misc_funcs.h
+HEADERS += $$COMMON_PATH/spirals/SpiralAlgorithm.h
+HEADERS += $$COMMON_PATH/spirals/RectangularSpiralAlgorithm.h
+
HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPalette.h
HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialog.h
HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialogEntryButton.h
@@ -65,7 +70,6 @@
HEADERS += $$COMMON_PATH/utility/ImportExportDialog.h
HEADERS += $$COMMON_PATH/utility/HelpDialog.h
HEADERS += $$COMMON_PATH/gpl_related/gpldialog.h
-HEADERS += $$COMMON_PATH/plasma/PlasmaAlgorithm.h
HEADERS += $$COMMON_PATH/core/opengl_main.h
HEADERS += $$COMMON_PATH/2d_bgnd_w_lens/Background.h
$$COMMON_PATH/2d_bgnd_w_lens/BackgroundProfile.h
=======================================
--- /src/SpiralLenz/resource_files/defaults.xml Mon Mar 16 21:29:13 2009 UTC
+++ /src/SpiralLenz/resource_files/defaults.xml Mon Apr 27 00:56:58 2009 UTC
@@ -1,14 +1,12 @@
-<!DOCTYPE PlasmaLenz_Configuration>
-<PlasmaLenz_Configuration>
+<!DOCTYPE SpiralLenz_Configuration>
+<SpiralLenz_Configuration>
<BackgroundProfile>
- <type>PlasmaFractalBackground</type>
+ <type>RectangularSpiralBackground</type>
<name>Classic RGB Profile</name>
- <coarseness>4.5</coarseness>
<steps_per_tick>2048</steps_per_tick>
<anmiate_palette>true</anmiate_palette>
<palette_x_speed>1</palette_x_speed>
<palette_y_speed>1</palette_y_speed>
- <clamp_color>true</clamp_color>
<palette>Classic RGB Palette</palette>
</BackgroundProfile>
<IndexedPaletteProfile>
@@ -107,5 +105,5 @@
<location>0</location>
</selected_entry>
</selected_master_profile_list>
-</PlasmaLenz_Configuration>
+</SpiralLenz_Configuration>
=======================================
--- /src/SpiralLenz/src/ConfigWidget.cpp Mon Mar 16 21:29:13 2009 UTC
+++ /src/SpiralLenz/src/ConfigWidget.cpp Mon Apr 27 00:56:58 2009 UTC
@@ -25,7 +25,7 @@
//begin debug
//#include <iostream>
//using namespace std;
-#include "2d_bgnd_w_lens/lens_engine/SphericalLensProfile.h"
+//#include "2d_bgnd_w_lens/lens_engine/SphericalLensProfile.h"
//end debug
#include <QVBoxLayout>
@@ -40,650 +40,659 @@
#include <QDir>
//temp
-//#include <QMessageBox>
+#include <QMessageBox>
//end temp
-#include "../../common/2d_bgnd_w_lens/ConfigWidget.h"
-#include "../../common/2d_bgnd_w_lens/PaletteEditor.h"
-#include "../../common/utility/ImportExportDialog.h"
-#include "../../common/utility/misc_funcs.h"
-#include "../../common/utility/AboutDialog.h"
-#include "../../common/utility/HelpDialog.h"
-#include "../../common/2d_bgnd_w_lens/project_specific_extern_defs.h"
-#include "ProfileEditDialog.h"
+#include "2d_bgnd_w_lens/ConfigWidget.h"
+#include "2d_bgnd_w_lens/PaletteEditor.h"
+#include "utility/ImportExportDialog.h"
+#include "utility/misc_funcs.h"
+#include "utility/AboutDialog.h"
+#include "utility/HelpDialog.h"
+#include "2d_bgnd_w_lens/project_specific_extern_defs.h"
+//#include "ProfileEditDialog.h"
//constructor & destructor
ConfigWidget::ConfigWidget(QWidget* parent, Qt::WindowFlags f) {
- QDialog(parent, f);
+ QDialog(parent, f);
- _manager = NULL;
- _gplDialog = NULL;
- _stackedLayout = NULL;
- _mpAvailList = NULL;
- _mpSelList = NULL;
+ _manager = NULL;
+ _gplDialog = NULL;
+ _stackedLayout = NULL;
+ _mpAvailList = NULL;
+ _mpSelList = NULL;
- _windowTitle = tr("PlasmaLenz Configuration");
+ _windowTitle = tr("SpiralLenz Configuration");
- setWindowTitle(_windowTitle);
+ setWindowTitle(_windowTitle);
- QIcon icon(":/app_icon.png");
- setWindowIcon(icon);
+ QIcon icon(":/app_icon.png");
+ setWindowIcon(icon);
}
ConfigWidget::~ConfigWidget() {
- _manager = NULL;
+ _manager = NULL;
- if(_gplDialog != NULL) {
- delete _gplDialog;
- _gplDialog = NULL;
- }
+ if(_gplDialog != NULL) {
+ delete _gplDialog;
+ _gplDialog = NULL;
+ }
- if(_stackedLayout != NULL) {
- delete _stackedLayout;
- _stackedLayout = NULL;
- }
+ if(_stackedLayout != NULL) {
+ delete _stackedLayout;
+ _stackedLayout = NULL;
+ }
- if(_mpAvailList != NULL) {
- delete _mpAvailList;
- _mpAvailList = NULL;
- }
+ if(_mpAvailList != NULL) {
+ delete _mpAvailList;
+ _mpAvailList = NULL;
+ }
- if(_mpSelList != NULL) {
- delete _mpSelList;
- _mpSelList = NULL;
- }
+ if(_mpSelList != NULL) {
+ delete _mpSelList;
+ _mpSelList = NULL;
+ }
- if(_historyBox != NULL) {
- delete _historyBox;
- _historyBox = NULL;
- }
+ if(_historyBox != NULL) {
+ delete _historyBox;
+ _historyBox = NULL;
+ }
}
void ConfigWidget::setup(void) {
+ /*
+ //precaution
+ if(_manager == NULL) {
+ emit dialogFinished();
+ }
- //precaution
- if(_manager == NULL) {
- emit dialogFinished();
- }
+ _gplDialog = new GPLDialog(_manager->getGPLAccepted());
- _gplDialog = new GPLDialog(_manager->getGPLAccepted());
+ QWidget* tempWidget = NULL;
+ QPushButton* tempButton = NULL;
+ QLabel* tempLabel = NULL;
+ QVBoxLayout* mainLayout = new QVBoxLayout();
- QWidget* tempWidget = NULL;
- QPushButton* tempButton = NULL;
- QLabel* tempLabel = NULL;
- QVBoxLayout* mainLayout = new QVBoxLayout();
+ //Master Profile selection lists and related.
+ tempWidget = genMPWidget();
+ mainLayout->addWidget(tempWidget);
+ tempWidget = NULL;
- //Master Profile selection lists and related.
- tempWidget = genMPWidget();
- mainLayout->addWidget(tempWidget);
- tempWidget = NULL;
+ // import/export/palette editor buttons
+ QHBoxLayout* midButtonsLayout = new QHBoxLayout();
- // import/export/palette editor buttons
- QHBoxLayout* midButtonsLayout = new QHBoxLayout();
+ tempButton = new QPushButton(tr("Palette Editor"));
+ tempButton->setToolTip(tr("Opens the palette editor."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(paletteEditorClicked(bool)));
+ midButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
- tempButton = new QPushButton(tr("Palette Editor"));
- tempButton->setToolTip(tr("Opens the palette editor."));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(paletteEditorClicked(bool)));
- midButtonsLayout->addWidget(tempButton);
- tempButton = NULL;
+ midButtonsLayout->addStretch(0);
- midButtonsLayout->addStretch(0);
+ tempButton = new QPushButton(tr("Import Settings"));
+ tempButton->setToolTip(tr("Imports settings from a file."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(importClicked(bool)));
+ midButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
- tempButton = new QPushButton(tr("Import Settings"));
- tempButton->setToolTip(tr("Imports settings from a file."));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(importClicked(bool)));
- midButtonsLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempButton = new QPushButton(tr("Export Settings"));
+ tempButton->setToolTip(tr("Exports settings to a file."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(exportClicked(bool)));
+ midButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
- tempButton = new QPushButton(tr("Export Settings"));
- tempButton->setToolTip(tr("Exports settings to a file."));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(exportClicked(bool)));
- midButtonsLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempWidget = new QWidget();
+ tempWidget->setLayout(midButtonsLayout);
+ mainLayout->addWidget(tempWidget);
+ tempWidget = NULL;
- tempWidget = new QWidget();
- tempWidget->setLayout(midButtonsLayout);
- mainLayout->addWidget(tempWidget);
- tempWidget = NULL;
-
- //About, Help, OK, Apply, and Cancel buttons
- QHBoxLayout* botButtonsLayout = new QHBoxLayout();
+ //About, Help, OK, Apply, and Cancel buttons
+ QHBoxLayout* botButtonsLayout = new QHBoxLayout();
- tempButton = new QPushButton(tr("A&bout"));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(aboutClicked(bool)));
- botButtonsLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempButton = new QPushButton(tr("A&bout"));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(aboutClicked(bool)));
+ botButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
- tempButton = new QPushButton(tr("&Help"));
- tempButton->setDefault(false);
- tempButton->setAutoDefault(false);
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(helpClicked(bool)));
- botButtonsLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempButton = new QPushButton(tr("&Help"));
+ tempButton->setDefault(false);
+ tempButton->setAutoDefault(false);
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(helpClicked(bool)));
+ botButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
- botButtonsLayout->addStretch(0);
+ botButtonsLayout->addStretch(0);
- tempButton = new QPushButton(tr("&OK"));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(okClicked(bool)));
- tempButton->setDefault(true);
- botButtonsLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempButton = new QPushButton(tr("&OK"));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(okClicked(bool)));
+ tempButton->setDefault(true);
+ botButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
- tempButton = new QPushButton(tr("&Apply"));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(applyClicked(bool)));
- botButtonsLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempButton = new QPushButton(tr("&Apply"));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(applyClicked(bool)));
+ botButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
- tempButton = new QPushButton(tr("&Cancel"));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(cancelClicked(bool)));
- botButtonsLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempButton = new QPushButton(tr("&Cancel"));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(cancelClicked(bool)));
+ botButtonsLayout->addWidget(tempButton);
+ tempButton = NULL;
- tempWidget = new QWidget();
- tempWidget->setLayout(botButtonsLayout);
- mainLayout->addWidget(tempWidget);
- tempWidget = NULL;
+ tempWidget = new QWidget();
+ tempWidget->setLayout(botButtonsLayout);
+ mainLayout->addWidget(tempWidget);
+ tempWidget = NULL;
- setLayout(mainLayout);
+ setLayout(mainLayout);
- populateMPLists();
+ populateMPLists();
+ */
}
void ConfigWidget::setManager(ConfigManager* manager) {
- _manager = manager;
+ _manager = manager;
}
void ConfigWidget::addListClicked(bool checked) {
- if(_mpAvailList == NULL || _mpSelList == NULL)
- return;
+ if(_mpAvailList == NULL || _mpSelList == NULL)
+ return;
- QList<QListWidgetItem*> itemList = _mpAvailList->selectedItems();
- for(int i =0; i<itemList.size(); i++) {
-
if(_mpSelList->findItems(itemList.at(i)->text(),Qt::MatchExactly).empty()) {
- _mpSelList->addItem(itemList.at(i)->text());
- }
- }
+ QList<QListWidgetItem*> itemList = _mpAvailList->selectedItems();
+ for(int i =0; i<itemList.size(); i++) {
+
if(_mpSelList->findItems(itemList.at(i)->text(),Qt::MatchExactly).empty()) {
+ _mpSelList->addItem(itemList.at(i)->text());
+ }
+ }
}
void ConfigWidget::removeListClicked(bool checked) {
- if(_mpSelList == NULL)
- return;
+ if(_mpSelList == NULL)
+ return;
- QList<QListWidgetItem*> list = _mpSelList->selectedItems();
- for(int i=0;i<list.size(); i++) {
- QListWidgetItem* tmp = _mpSelList->takeItem(_mpSelList->row(
list.at(i)));
- delete tmp;
- tmp = NULL;
- }
+ QList<QListWidgetItem*> list = _mpSelList->selectedItems();
+ for(int i=0;i<list.size(); i++) {
+ QListWidgetItem* tmp =
_mpSelList->takeItem(_mpSelList->row(
list.at(i)));
+ delete tmp;
+ tmp = NULL;
+ }
}
void ConfigWidget::upListClicked(bool checked) {
- if(_mpSelList == NULL)
- return;
+ if(_mpSelList == NULL)
+ return;
- int row = _mpSelList->currentRow();
- if(row > 0) {
- _mpSelList->insertItem(row-1,_mpSelList->takeItem(row));
- _mpSelList->setCurrentRow(row-1);
- }
+ int row = _mpSelList->currentRow();
+ if(row > 0) {
+ _mpSelList->insertItem(row-1,_mpSelList->takeItem(row));
+ _mpSelList->setCurrentRow(row-1);
+ }
}
void ConfigWidget::downListClicked(bool checked) {
- if(_mpSelList == NULL)
- return;
+ if(_mpSelList == NULL)
+ return;
- int row = _mpSelList->currentRow();
- if(row < _mpSelList->count()) {
- _mpSelList->insertItem(row+1,_mpSelList->takeItem(row));
- if(row+1 == _mpSelList->count()) {
- _mpSelList->setCurrentRow(_mpSelList->count()-1);
- } else {
- _mpSelList->setCurrentRow(row+1);
- }
- }
+ int row = _mpSelList->currentRow();
+ if(row < _mpSelList->count()) {
+ _mpSelList->insertItem(row+1,_mpSelList->takeItem(row));
+ if(row+1 == _mpSelList->count()) {
+ _mpSelList->setCurrentRow(_mpSelList->count()-1);
+ } else {
+ _mpSelList->setCurrentRow(row+1);
+ }
+ }
}
void ConfigWidget::okClicked(bool checked) {
- saveData();
+ saveData();
- emit dialogFinished();
+ emit dialogFinished();
}
void ConfigWidget::applyClicked(bool checked) {
- saveData();
+ saveData();
}
void ConfigWidget::cancelClicked(bool checked) {
- emit dialogFinished();
+ emit dialogFinished();
}
void ConfigWidget::randomClicked(bool checked) {
- _manager->setRandomProfile(checked);
+ _manager->setRandomProfile(checked);
}
void ConfigWidget::aboutClicked(bool checked) {
- AboutDialog* dlg = new AboutDialog(getAppFullName(), getAppVersion());
- if(dlg != NULL) {
- dlg->exec();
- delete dlg;
- dlg = NULL;
- }
+ AboutDialog* dlg = new AboutDialog(getAppFullName(), getAppVersion());
+ if(dlg != NULL) {
+ dlg->exec();
+ delete dlg;
+ dlg = NULL;
+ }
}
//shows the GPL dialog
void ConfigWidget::showGPLDialog(void) {
- _gplDialog->exec();
- _manager->setGPLAccepted(_gplDialog->isAccepted());
- if(_manager->getGPLAccepted()) {
- _manager->save();
- }
+ _gplDialog->exec();
+ _manager->setGPLAccepted(_gplDialog->isAccepted());
+ if(_manager->getGPLAccepted()) {
+ _manager->save();
+ }
}
void ConfigWidget::addMPClicked(bool checked) {
-
- ProfileEditDialog* dlg = new ProfileEditDialog("", _manager);
- QObject::connect(dlg, SIGNAL(profileNameChange(QString, QString)), this,
SLOT(profileNameChange(QString, QString)));
- dlg->exec();
+ QMessageBox::information(this, _windowTitle, "Not implemented yet.",
QMessageBox::Ok);
+ /*
+ ProfileEditDialog* dlg = new ProfileEditDialog("", _manager);
+ QObject::connect(dlg, SIGNAL(profileNameChange(QString, QString)),
this, SLOT(profileNameChange(QString, QString)));
+ dlg->exec();
+ */
}
void ConfigWidget::editMPClicked(bool checked) {
-// QMessageBox::information(this, _windowTitle, "Not implemented yet.",
QMessageBox::Ok);
-
- if(_mpAvailList == NULL)
- return;
+ QMessageBox::information(this, _windowTitle, "Not implemented yet.",
QMessageBox::Ok);
+ /*
+ if(_mpAvailList == NULL)
+ return;
- QList<QListWidgetItem*> list = _mpAvailList->selectedItems();
- for(int i=0;i<list.size(); i++) {
- QListWidgetItem* tmp = _mpAvailList->item(_mpAvailList->row(
list.at(i)));
- ProfileEditDialog* dlg = new ProfileEditDialog(tmp->text(), _manager);
- QObject::connect(dlg, SIGNAL(profileNameChange(QString, QString)), this,
SLOT(profileNameChange(QString, QString)));
- dlg->exec();
+ QList<QListWidgetItem*> list = _mpAvailList->selectedItems();
+ for(int i=0;i<list.size(); i++) {
+ QListWidgetItem* tmp =
_mpAvailList->item(_mpAvailList->row(
list.at(i)));
+ ProfileEditDialog* dlg = new ProfileEditDialog(tmp->text(), _manager);
+ QObject::connect(dlg, SIGNAL(profileNameChange(QString, QString)),
this, SLOT(profileNameChange(QString, QString)));
+ dlg->exec();
- //clean up
- tmp = NULL;
- delete dlg;
- dlg = NULL;
- }
+ //clean up
+ tmp = NULL;
+ delete dlg;
+ dlg = NULL;
+ }
+ */
}
void ConfigWidget::deleteMPClicked(bool checked) {
- if(_mpAvailList == NULL)
- return;
+ if(_mpAvailList == NULL)
+ return;
- QList<QListWidgetItem*> list = _mpAvailList->selectedItems();
- for(int i=0;i<list.size(); i++) {
- // get the selected master profile
- QListWidgetItem* tmp =
_mpAvailList->takeItem(_mpAvailList->row(
list.at(i)));
- QString name = tmp->text();
- delete tmp;
- tmp = NULL;
+ QList<QListWidgetItem*> list = _mpAvailList->selectedItems();
+ for(int i=0;i<list.size(); i++) {
+ // get the selected master profile
+ QListWidgetItem* tmp =
_mpAvailList->takeItem(_mpAvailList->row(
list.at(i)));
+ QString name = tmp->text();
+ delete tmp;
+ tmp = NULL;
- //delete the background profile
- MasterProfile tempMp = _manager->getProfile(name);
- _manager->removeBackgroundProfile(tempMp.getBackgroundProfileName());
+ //delete the background profile
+ MasterProfile tempMp = _manager->getProfile(name);
+ _manager->removeBackgroundProfile(tempMp.getBackgroundProfileName());
- //delete the master profile
- _manager->removeProfile(name);
+ //delete the master profile
+ _manager->removeProfile(name);
- //now remove the master profile from selected list, if it is in there.
- int j=0;
- bool bDone = false;
- while(!bDone && j<_mpSelList->count()) {
- tmp = _mpSelList->item(j);
- if(tmp->text() == name) {
- bDone = true;
- _mpSelList->takeItem(j);
- delete tmp;
- tmp = NULL;
- }
+ //now remove the master profile from selected list, if it is in there.
+ int j=0;
+ bool bDone = false;
+ while(!bDone && j<_mpSelList->count()) {
+ tmp = _mpSelList->item(j);
+ if(tmp->text() == name) {
+ bDone = true;
+ _mpSelList->takeItem(j);
+ delete tmp;
+ tmp = NULL;
+ }
- j++;
- }
- }
+ j++;
+ }
+ }
}
void ConfigWidget::advancedChecked(bool checked) {
-// nada
+ // nada
}
//clears and then populates both MasterProfile lists.
void ConfigWidget::populateMPLists() {
- if(_mpAvailList == NULL || _mpSelList == NULL)
- return;
+ if(_mpAvailList == NULL || _mpSelList == NULL)
+ return;
- //available list
- _mpAvailList->clear();
- _mpAvailList->addItems(_manager->getAvailableProfiles());
+ //available list
+ _mpAvailList->clear();
+ _mpAvailList->addItems(_manager->getAvailableProfiles());
- //selected list
- _mpSelList->clear();
- _mpSelList->addItems(_manager->getSelectedProfiles());
+ //selected list
+ _mpSelList->clear();
+ _mpSelList->addItems(_manager->getSelectedProfiles());
}
//generates a widget that contains the available and selected
//master profile lists as well as the requisite buttons.
QWidget* ConfigWidget::genMPWidget() {
- QWidget* tempWidget = NULL;
- QPushButton* tempButton = NULL;
+ QWidget* tempWidget = NULL;
+ QPushButton* tempButton = NULL;
- QVBoxLayout* mpLayout = new QVBoxLayout();
+ QVBoxLayout* mpLayout = new QVBoxLayout();
- QHBoxLayout* listsLayout = new QHBoxLayout();
+ QHBoxLayout* listsLayout = new QHBoxLayout();
- _mpAvailList = new QListWidget();
- _mpAvailList->setSelectionMode(QAbstractItemView::ExtendedSelection);
- _mpAvailList->setToolTip(tr("This is the list of available configuration
profiles."));
+ _mpAvailList = new QListWidget();
+ _mpAvailList->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ _mpAvailList->setToolTip(tr("This is the list of available configuration
profiles."));
- listsLayout->addWidget(_mpAvailList);
+ listsLayout->addWidget(_mpAvailList);
- QVBoxLayout* listButtonLayout = new QVBoxLayout();
+ QVBoxLayout* listButtonLayout = new QVBoxLayout();
- tempButton = new QPushButton(">>");
- tempButton->setToolTip(tr("Click to add the items selected in the list of
available configuration profiles")+"\n"
- +tr("to the list of selected configuration profiles."));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(addListClicked(bool)));
- listButtonLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempButton = new QPushButton(">>");
+ tempButton->setToolTip(tr("Click to add the items selected in the list
of available configuration profiles")+"\n"
+ +tr("to the list of selected configuration profiles."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(addListClicked(bool)));
+ listButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
- tempButton = new QPushButton("<<");
- tempButton->setToolTip(tr("Click to remove the selected items in the list
of selected configuration profiles."));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(removeListClicked(bool)));
- listButtonLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempButton = new QPushButton("<<");
+ tempButton->setToolTip(tr("Click to remove the selected items in the
list of selected configuration profiles."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(removeListClicked(bool)));
+ listButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
- tempButton = new QPushButton(tr("Up"));
- tempButton->setToolTip(tr("Click to move the selected item in the list of
selected configuration profiles up in")+"\n"
- +tr("the order."));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(upListClicked(bool)));
- listButtonLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempButton = new QPushButton(tr("Up"));
+ tempButton->setToolTip(tr("Click to move the selected item in the list
of selected configuration profiles up in")+"\n"
+ +tr("the order."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(upListClicked(bool)));
+ listButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
- tempButton = new QPushButton(tr("Down"));
- tempButton->setToolTip(tr("Click to move the selected item in the list of
selected configuration profiles")+"\n"
- +tr("down in the order."));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(downListClicked(bool)));
- listButtonLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempButton = new QPushButton(tr("Down"));
+ tempButton->setToolTip(tr("Click to move the selected item in the list
of selected configuration profiles")+"\n"
+ +tr("down in the order."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(downListClicked(bool)));
+ listButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
- tempWidget = new QWidget();
- tempWidget->setLayout(listButtonLayout);
- listsLayout->addWidget(tempWidget);
- tempWidget = NULL;
+ tempWidget = new QWidget();
+ tempWidget->setLayout(listButtonLayout);
+ listsLayout->addWidget(tempWidget);
+ tempWidget = NULL;
- _mpSelList = new QListWidget();
- _mpSelList->setSelectionMode(QAbstractItemView::ExtendedSelection);
- _mpSelList->setToolTip(tr("This is the list of currently selected
configuration profiles."));
- listsLayout->addWidget(_mpSelList);
+ _mpSelList = new QListWidget();
+ _mpSelList->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ _mpSelList->setToolTip(tr("This is the list of currently selected
configuration profiles."));
+ listsLayout->addWidget(_mpSelList);
- tempWidget = new QWidget();
- tempWidget->setLayout(listsLayout);
- mpLayout->addWidget(tempWidget);
- tempWidget = NULL;
+ tempWidget = new QWidget();
+ tempWidget->setLayout(listsLayout);
+ mpLayout->addWidget(tempWidget);
+ tempWidget = NULL;
- //add/edit/delete buttons, stretch, history box
- QHBoxLayout* bottomButtonLayout = new QHBoxLayout();
+ //add/edit/delete buttons, stretch, history box
+ QHBoxLayout* bottomButtonLayout = new QHBoxLayout();
- tempButton = new QPushButton(tr("New"));
- tempButton->setToolTip(tr("Click to add a new configuration profile."));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(addMPClicked(bool)));
- bottomButtonLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempButton = new QPushButton(tr("New"));
+ tempButton->setToolTip(tr("Click to add a new configuration profile."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(addMPClicked(bool)));
+ bottomButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
- tempButton = new QPushButton(tr("Edit"));
- tempButton->setToolTip(tr("Click to edit the currently selected
configuration profile."));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(editMPClicked(bool)));
- bottomButtonLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempButton = new QPushButton(tr("Edit"));
+ tempButton->setToolTip(tr("Click to edit the currently selected
configuration profile."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(editMPClicked(bool)));
+ bottomButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
- tempButton = new QPushButton(tr("Delete"));
- tempButton->setToolTip(tr("Click to permanently remove the currently
selected configuration profile."));
- QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(deleteMPClicked(bool)));
- bottomButtonLayout->addWidget(tempButton);
- tempButton = NULL;
+ tempButton = new QPushButton(tr("Delete"));
+ tempButton->setToolTip(tr("Click to permanently remove the currently
selected configuration profile."));
+ QObject::connect(tempButton, SIGNAL(clicked(bool)), this,
SLOT(deleteMPClicked(bool)));
+ bottomButtonLayout->addWidget(tempButton);
+ tempButton = NULL;
- bottomButtonLayout->addStretch(0);
+ bottomButtonLayout->addStretch(0);
- //history box
- QGroupBox* randomBox = new QGroupBox(tr("Choose &Randomly"));
- randomBox->setCheckable(true);
- randomBox->setChecked(_manager->isRandomProfile());
- randomBox->setToolTip(tr("Enabling this will randomize the order in which
the configuration profiles will run."));
- QObject::connect(randomBox, SIGNAL(clicked(bool)), this,
SLOT(randomClicked(bool)));
+ //history box
+ QGroupBox* randomBox = new QGroupBox(tr("Choose &Randomly"));
+ randomBox->setCheckable(true);
+ randomBox->setChecked(_manager->isRandomProfile());
+ randomBox->setToolTip(tr("Enabling this will randomize the order in
which the configuration profiles will run."));
+ QObject::connect(randomBox, SIGNAL(clicked(bool)), this,
SLOT(randomClicked(bool)));
- QHBoxLayout* historyLayout = new QHBoxLayout();
- QLabel* historyLabel = new QLabel(tr("Size of History"));
- historyLabel->setToolTip(tr("The number of times before a configuration
profile can run again."));
- historyLayout->addWidget(historyLabel);
+ QHBoxLayout* historyLayout = new QHBoxLayout();
+ QLabel* historyLabel = new QLabel(tr("Size of History"));
+ historyLabel->setToolTip(tr("The number of times before a configuration
profile can run again."));
+ historyLayout->addWidget(historyLabel);
- _historyBox = new QSpinBox();
- _historyBox->setRange(0,10);
- _historyBox->setSingleStep(1);
- _historyBox->setValue(_manager->getProfileHistorySize());
- _historyBox->setToolTip(tr("The number of times before a configuration
profile can run again."));
- historyLayout->addWidget(_historyBox);
+ _historyBox = new QSpinBox();
+ _historyBox->setRange(0,10);
+ _historyBox->setSingleStep(1);
+ _historyBox->setValue(_manager->getProfileHistorySize());
+ _historyBox->setToolTip(tr("The number of times before a configuration
profile can run again."));
+ historyLayout->addWidget(_historyBox);
- randomBox->setLayout(historyLayout);
- bottomButtonLayout->addWidget(randomBox);
+ randomBox->setLayout(historyLayout);
+ bottomButtonLayout->addWidget(randomBox);
- tempWidget = new QWidget();
- tempWidget->setLayout(bottomButtonLayout);
- mpLayout->addWidget(tempWidget);
- tempWidget = NULL;
+ tempWidget = new QWidget();
+ tempWidget->setLayout(bottomButtonLayout);
+ mpLayout->addWidget(tempWidget);
+ tempWidget = NULL;
- tempWidget = new QWidget();
- tempWidget->setLayout(mpLayout);
- return tempWidget;
+ tempWidget = new QWidget();
+ tempWidget->setLayout(mpLayout);
+ return tempWidget;
}
//saves all data back to the configuration manager
void ConfigWidget::saveData() {
- //update list of selected profiles
- if(_mpSelList != NULL) {
- QStringList retVal;
- for(int i=0;i<_mpSelList->count();i++) {
- QListWidgetItem* tmp = _mpSelList->item(i);
- if(tmp != NULL) {
- retVal.append(tmp->text());
- }
- }
- _manager->setSelectedProfiles(retVal);
- }
+ //update list of selected profiles
+ if(_mpSelList != NULL) {
+ QStringList retVal;
+ for(int i=0;i<_mpSelList->count();i++) {
+ QListWidgetItem* tmp = _mpSelList->item(i);
+ if(tmp != NULL) {
+ retVal.append(tmp->text());
+ }
+ }
+ _manager->setSelectedProfiles(retVal);
+ }
- //update history size
- _manager->setProfileHistorySize(_historyBox->value());
+ //update history size
+ _manager->setProfileHistorySize(_historyBox->value());
- _manager->save();
+ _manager->save();
}
void ConfigWidget::profileNameChange(QString oldName, QString newName) {
- if(_mpAvailList == NULL)
- return;
+ if(_mpAvailList == NULL)
+ return;
- if(oldName != newName) {
- //it is an addition. Append to the available list.
- if(oldName == "") {
- _mpAvailList->addItem(newName);
- } else {
- //otherwise, we're replacing.
+ if(oldName != newName) {
+ //it is an addition. Append to the available list.
+ if(oldName == "") {
+ _mpAvailList->addItem(newName);
+ } else {
+ //otherwise, we're replacing.
- //search the list for the old name, remove it and
- //insert the new one in the same position.
- int j=0;
- bool bDone = false;
- while(!bDone && j < _mpAvailList->count()) {
- QListWidgetItem* tmp = _mpAvailList->item(j);
- if(tmp->text() == oldName) {
- bDone = true;
- //remove
- _mpAvailList->takeItem(j);
- delete tmp;
- tmp = NULL;
+ //search the list for the old name, remove it and
+ //insert the new one in the same position.
+ int j=0;
+ bool bDone = false;
+ while(!bDone && j < _mpAvailList->count()) {
+ QListWidgetItem* tmp = _mpAvailList->item(j);
+ if(tmp->text() == oldName) {
+ bDone = true;
+ //remove
+ _mpAvailList->takeItem(j);
+ delete tmp;
+ tmp = NULL;
- //insert
- _mpAvailList->insertItem(j, newName);
- }
+ //insert
+ _mpAvailList->insertItem(j, newName);
+ }
- j++;
- }
- // repeat on the list of selected items
- j=0;
- bDone = false;
- while(!bDone &&j<_mpSelList->count()) {
- QListWidgetItem* tmp = _mpSelList->item(j);
- if(tmp->text() == oldName) {
- bDone = true;
- //remove
- _mpSelList->takeItem(j);
- delete tmp;
- tmp = NULL;
+ j++;
+ }
+ // repeat on the list of selected items
+ j=0;
+ bDone = false;
+ while(!bDone &&j<_mpSelList->count()) {
+ QListWidgetItem* tmp = _mpSelList->item(j);
+ if(tmp->text() == oldName) {
+ bDone = true;
+ //remove
+ _mpSelList->takeItem(j);
+ delete tmp;
+ tmp = NULL;
- //insert
- _mpSelList->insertItem(j, newName);
- }
- j++;
- }
- }
+ //insert
+ _mpSelList->insertItem(j, newName);
}
+ j++;
+ }
+ }
+ }
}
void ConfigWidget::importClicked(bool checked) {
-// QMessageBox::information(this, _windowTitle, "Not implemented yet.",
QMessageBox::Ok);
- ImportExportDialog dlg(true);
+ QMessageBox::information(this, _windowTitle, "Not implemented yet.",
QMessageBox::Ok);
+ /*
+ ImportExportDialog dlg(true);
- // get file name to import from
- QString filename = QFileDialog::getOpenFileName(this, tr("Import Settings
From File"), QDir::homePath(),
- tr("Settings Files (*.xml)"));
+ // get file name to import from
+ QString filename = QFileDialog::getOpenFileName(this, tr("Import
Settings From File"), QDir::homePath(),
+ tr("Settings Files (*.xml)"));
- if(filename.isEmpty())
- return;
+ if(filename.isEmpty())
+ return;
- // create a temporary config manager and load
- // it with data from the import file.
- ConfigManager* tmpMgr = new ConfigManager();
- if(tmpMgr == NULL)
- return;
- tmpMgr->importFromFile(filename, false);
+ // create a temporary config manager and load
+ // it with data from the import file.
+ ConfigManager* tmpMgr = new ConfigManager();
+ if(tmpMgr == NULL)
+ return;
+ tmpMgr->importFromFile(filename, false);
- // populate dialog box
- QStringList bkgnds = tmpMgr->getAvailableProfiles();
- dlg.addSubItems("Configuration Profiles", bkgnds, true);
+ // populate dialog box
+ QStringList bkgnds = tmpMgr->getAvailableProfiles();
+ dlg.addSubItems("Configuration Profiles", bkgnds, true);
- QStringList palettes = tmpMgr->getPaletteNames();
- dlg.addSubItems("Palettes", palettes, true);
+ QStringList palettes = tmpMgr->getPaletteNames();
+ dlg.addSubItems("Palettes", palettes, true);
- // show dialog and get lists of checked items
- if(dlg.exec() == QDialog::Rejected) {
- delete tmpMgr;
- tmpMgr = NULL;
- return;
- }
- bkgnds = dlg.getSubItems("Configuration Profiles", true);
- palettes = dlg.getSubItems("Palettes", true);
+ // show dialog and get lists of checked items
+ if(dlg.exec() == QDialog::Rejected) {
+ delete tmpMgr;
+ tmpMgr = NULL;
+ return;
+ }
+ bkgnds = dlg.getSubItems("Configuration Profiles", true);
+ palettes = dlg.getSubItems("Palettes", true);
- // first, add in the palettes, since they don't
- // have any dependencies
- for(int i = 0; i<palettes.size(); i++) {
- IndexedPaletteProfile tmpPal = tmpMgr->getPaletteProfile(
palettes.at(i));
- _manager->addPalette(tmpPal);
- }
+ // first, add in the palettes, since they don't
+ // have any dependencies
+ for(int i = 0; i<palettes.size(); i++) {
+ IndexedPaletteProfile tmpPal =
tmpMgr->getPaletteProfile(
palettes.at(i));
+ _manager->addPalette(tmpPal);
+ }
- // now go through the MasterProfiles, adding sub profiles
- // it requires (including IndexedPaletteProfiles).
- for(int i = 0; i<bkgnds.size(); i++) {
- MasterProfile tmpMp = tmpMgr->getProfile(
bkgnds.at(i));
- // make sure the master profile doesn't exist, so that we don't
- // unnecessarily the other things. No need to check everything else
- // since the respective add routines will check before appending
- // to the lists.
- if(!_manager->doesProfileExist(tmpMp.getName())) {
- LensProfile* tmpLens =
tmpMgr->getLensProfile(tmpMp.getLensProfileName());
- _manager->addLensProfile(tmpLens);
- //debug?
- tmpLens = NULL;
- //end debug
- PlasmaFractalBackgroundProfile* tmpBkgnd =
(PlasmaFractalBackgroundProfile*)tmpMgr->getBackgroundProfile(tmpMp.getBackgroundProfileName());
- IndexedPaletteProfile tmpPal =
tmpMgr->getPaletteProfile(tmpBkgnd->getPaletteName());
- _manager->addPalette(tmpPal);
- _manager->addBackgroundProfile(*tmpBkgnd);
- _manager->addProfile(tmpMp);
- _mpAvailList->addItem(tmpMp.getName());
- }
- }
+ // now go through the MasterProfiles, adding sub profiles
+ // it requires (including IndexedPaletteProfiles).
+ for(int i = 0; i<bkgnds.size(); i++) {
+ MasterProfile tmpMp = tmpMgr->getProfile(
bkgnds.at(i));
+ // make sure the master profile doesn't exist, so that we don't
+ // unnecessarily the other things. No need to check everything else
+ // since the respective add routines will check before appending
+ // to the lists.
+ if(!_manager->doesProfileExist(tmpMp.getName())) {
+ LensProfile* tmpLens =
tmpMgr->getLensProfile(tmpMp.getLensProfileName());
+ _manager->addLensProfile(tmpLens);
+ //debug?
+ tmpLens = NULL;
+ //end debug
+ PlasmaFractalBackgroundProfile* tmpBkgnd =
(PlasmaFractalBackgroundProfile*)tmpMgr->getBackgroundProfile(tmpMp.getBackgroundProfileName());
+ IndexedPaletteProfile tmpPal =
tmpMgr->getPaletteProfile(tmpBkgnd->getPaletteName());
+ _manager->addPalette(tmpPal);
+ _manager->addBackgroundProfile(*tmpBkgnd);
+ _manager->addProfile(tmpMp);
+ _mpAvailList->addItem(tmpMp.getName());
+ }
+ }
***The diff for this file has been truncated for email.***
=======================================
--- /src/SpiralLenz/src/SpiralBackground.cpp Mon Mar 16 21:29:13 2009 UTC
+++ /src/SpiralLenz/src/SpiralBackground.cpp Mon Apr 27 00:56:58 2009 UTC
@@ -26,12 +26,27 @@
#include "SpiralBackground.h"
/**
- * Constructor takes the dimensions, a pointer to the palette,
- * whether to rotate the palette, and the palette color skip.
+ * Constructor takes the dimensions, a pointer to the algorithm,
+ * a pointer to the palette, whether to rotate the palette,
+ * and the palette color skip. This class takes responsibility for
+ * destroying both the algorithm and the palette.
+ * @param sizeX The width of the background.
+ * @param sizeY The height of the background.
+ * @param algorithm A pointer to the spiral algorithm.
+ * @param pal A pointer to the palette.
+ * @param bAnimatePalette Whether or not to animate the palette.
+ * @param paletteXSpeed The palette rotational speed in the primary
direction.
+ * @param paletteYSpeed The palette rotational speed in the secondary dir.
+ * @param genStepsPerTick The number of generation steps per tick.
*/
-SpiralBackground::SpiralBackground(int sizeX, int sizeY, IndexedPalette*
pal,
- bool bAnimatePalette, float paletteXSpeed,
- float paletteYSpeed) {
+SpiralBackground::SpiralBackground(int sizeX, int sizeY,
+ SpiralAlgorithm* algorithm,
+ IndexedPalette* pal, bool bAnimatePalette,
+ float paletteXSpeed, float paletteYSpeed,
+ int genStepsPerTick) {
+
+ // general defaults
+ _algorithm = NULL;
// base class specific
initIndexedPaletteBackground(sizeX,sizeY);
@@ -39,98 +54,39 @@
_bEnableAnimation = bAnimatePalette;
_xSpeed = paletteXSpeed;
_ySpeed = paletteYSpeed;
+ _algorithm = algorithm;
+ _numGenStepsPerTick = genStepsPerTick;
_bSetupFinished = false;
- // general defaults
- _numGenStepsPerTick = 0;
- _bRandomColor = false;
- _algorithm = NULL;
- _style = SINGLE;
-
- // SINGLE style specific
- _bLerpToDefault = false;
- _singleWidth = 1;
- // end SINGLE style
-
-
// initialize field to -1 (no color)
- for(int i=0;i<_height*_width;i++)
- {
+ if(_field != NULL) {
+ for(int i=0;i<_sizeX*_sizeY;i++) {
_field[i] = -1;
}
+ }
+ // initialize the algorithm
+ if(_algorithm != NULL) {
+ _algorithm->initialize(_field, sizeX, sizeY, _paletteWidth);
+ }
}
SpiralBackground::~SpiralBackground() {
destroyIndexedPaletteBackground();
}
-
-/**
- * Initializes the generator algorithm to generate a single-color
- * spiral of the specified width, rotating through the primary palette
- * direction as it extends outward. If bLerpToDefaultColor is true,
- * the palette color will be in the middle with, the default palette color
- * on the borders. If bRandomColor is true, the first color index is
- * randomly picked.
- * If genStepsPerTick is 0, then it will all be done in one swoop.
- */
-void SpiralBackground::genSingleColorSpiral(SpiralBackgroundShape shape,
- int genStepsPerTick, int width,
- bool bRandomColor,
- bool bLerpToDefaultColor) {
- _numGenStepsPerTick = genStepsPerTick;
- _bRandomColor = bRandomColor;
-
- _style = SINGLE;
- _singleWidth = width;
- _bLerpToDefaultColor = bLerpToDefaultColor;
-
- //_algorithm =
- //_shape = shape;
-}
-
-/**
- * Initializes the generator algorithm to generate a multi-color spiral,
- * that remains constant through the whole spiral. The width is the
- * width (primary axis) of the palette. If bRandomColor is true,
- * the initial index is randomly picked and the palette will be wrapped.
- * If genStepsPerTick is 0, then it will all be done in one swoop.
- */
-void SpiralBackground::genMultiColorSpiral(SpiralBackgroundShape shape,
- int genStepsPerTick,
- bool bRandomColor) {
- _numGenStepsPerTick = genStepsPerTick;
- _bRandomColor = bRandomColor;
-
- _style = MULTIWIDTH;
-
- //_shape = shape;
- //_algorithm =
-}
/**
* Finishes generating the spiral then rotates the palette when done.
*/
void SpiralBackground::clocktick() {
- if(_paletteWidth > 0)
- {
- if(!_bSetupFinished)
- {
- spiralGenStep();
- }
- else
- {
- rotateColorIndex();
- }
+ if(_paletteWidth > 0) {
+ if(!_bSetupFinished && _algorithm != NULL) {
+ if(_algorithm->calc(_numGenStepsPerTick))
+ _bSetupFinished = true;
+ } else {
+ rotateColorIndex();
}
-}
-
-/**
- * Performs one iteration of the fractal generation.
- */
-void SpiralBackground::spiralGenStep() {
- if(_algorithm.calc(_numGenStepsPerTick))
- _bSetupFinished = true;
+ }
}
=======================================
--- /src/SpiralLenz/src/SpiralBackground.h Mon Mar 16 21:29:13 2009 UTC
+++ /src/SpiralLenz/src/SpiralBackground.h Mon Apr 27 00:56:58 2009 UTC
@@ -39,74 +39,43 @@
#include "2d_bgnd_w_lens/globaldefs.h"
#include "2d_bgnd_w_lens/IndexedPaletteBackground.h"
-#include "SpiralBackgroundAlgorithm.h"
-#include "RectangularSpiral.h"
-
-enum SpiralBackgroundShape {
- POLAR, RECTANGULAR, DIAMOND, TRIANGULAR
-};
-
-enum SpiralBackgroundSytle {
- SINGLE, MULTIWIDTH
-};
+#include "spirals/SpiralAlgorithm.h"
class SpiralBackground : public IndexedPaletteBackground {
public:
/**
- * Constructor takes the dimensions, a pointer to the palette,
- * whether to rotate the palette, and the palette color skip.
+ * Constructor takes the dimensions, a pointer to the algorithm,
+ * a pointer to the palette, whether to rotate the palette,
+ * and the palette color skip. This class takes responsibility for
+ * destroying both the algorithm and the palette.
+ * @param sizeX The width of the background.
+ * @param sizeY The height of the background.
+ * @param algorithm A pointer to the spiral algorithm.
+ * @param pal A pointer to the palette.
+ * @param bAnimatePalette Whether or not to animate the palette.
+ * @param paletteXSpeed The palette rotational speed in the primary
direction.
+ * @param paletteYSpeed The palette rotational speed in the secondary
dir.
+ * @param genStepsPerTick The number of generation steps per tick.
*/
- SpiralBackground(int sizeX, int sizeY, IndexedPalette* pal,
- bool bAnimatePalette, float paletteXSpeed,
- float paletteYSpeed);
+ SpiralBackground(int sizeX, int sizeY, SpiralAlgorithm* algorithm,
+ IndexedPalette* pal, bool bAnimatePalette,
+ float paletteXSpeed, float paletteYSpeed,
+ int genStepsPerTick);
~SpiralBackground();
- /**
- * Initializes the generator algorithm to generate a single-color
- * spiral of the specified width, rotating through the primary palette
- * direction as it extends outward. If bLerpToDefaultColor is true,
- * the palette color will be in the middle with, the default palette
color
- * on the borders. If bRandomColor is true, the first color index is
- * randomly picked.
- * If genStepsPerTick is 0, then it will all be done in one swoop.
- */
- void genSingleColorSpiral(int genStepsPerTick, int width,
- bool bRandomColor, bool bLerpToDefaultColor);
-
- /**
- * Initializes the generator algorithm to generate a multi-color spiral,
- * that remains constant through the whole spiral. The width is the
- * width (primary axis) of the palette. If bRandomColor is true,
- * the initial index is randomly picked and the palette will be wrapped.
- * If genStepsPerTick is 0, then it will all be done in one swoop.
- */
- void genMultiColorSpiral(int genStepsPerTick, bool bRandomColor);
-
// *** Begin Extended Methods ***
/**
* Finishes generating the spiral then rotates the palette when done.
*/
- virtual void clocktick();
+ void clocktick();
// *** End Extended Methods ***
private:
- /**
- * Performs one iteration of the fractal generation.
- */
- void spiralGenStep();
-
int _numGenStepsPerTick;
- bool _bRandomColor;
-
- // specific to SINGLE style
- bool _bLerpToDefaultColor;
- int _singleWidth;
- // end specific to SINGLE style
- SpiralBackgroundShapeAlgorithm* _algorithm;
- SpiralBackgroundStyle _style;
+ SpiralAlgorithm* _algorithm;
};
#endif
=======================================
--- /src/SpiralLenz/src/SpiralBackgroundProfile.cpp Mon Mar 16 21:29:13
2009 UTC
+++ /src/SpiralLenz/src/SpiralBackgroundProfile.cpp Mon Apr 27 00:56:58
2009 UTC
@@ -25,35 +25,32 @@
#include <QtXml/QDomElement>
#include <QtXml/QDomText>
-//#include "../../common/utility/misc_funcs.h"
-
#include "utility/misc_funcs.h"
-#include "PlasmaFractalBackgroundProfile.h"
-#include "PlasmaFractal.h"
+#include "SpiralBackgroundProfile.h"
+#include "SpiralBackground.h"
+#include "spirals/SpiralAlgorithm.h"
-PlasmaFractalBackgroundProfile::PlasmaFractalBackgroundProfile() {
- _xmlTypeValue = "PlasmaFractalBackground";
+SpiralBackgroundProfile::SpiralBackgroundProfile() {
+ _xmlTypeValue = "SpiralBackground";
//defaults
_name = "Empty";
_palName = "";
- _coarseness = 1.0;
- _genStepsPerTick = 2048;
+ _genStepsPerTick = 100;
_bAnimatePalette = true;
_paletteXSpeed = 1;
_paletteYSpeed = 1;
- _bClampColorIndex = true;
}
-PlasmaFractalBackgroundProfile::~PlasmaFractalBackgroundProfile() {
+SpiralBackgroundProfile::~SpiralBackgroundProfile() {
+ // no es nada
}
-/* Attempts to load this background profile object from the
+/**
+ * Attempts to load this background profile object from the
* specified QDomNode.
*/
-BackgroundProfile* PlasmaFractalBackgroundProfile::load(QDomNode &node) {
- float tmpF;
- int tmpI;
+BackgroundProfile* SpiralBackgroundProfile::load(QDomNode &node) {
QDomElement tempElem;
//sanity check on the input
@@ -65,70 +62,68 @@
if(tempElem.isNull() || tempElem.text() != _xmlTypeValue)
return NULL;
- PlasmaFractalBackgroundProfile* retVal = new
PlasmaFractalBackgroundProfile();
+ SpiralBackgroundProfile* retVal = new SpiralBackgroundProfile();
+ if(retVal == NULL)
+ return NULL;
+
+ // load base
+ retVal->loadBase(node);
+
+ // derivative classes would load data here...
+
+ // return new profile
+ return retVal;
+}
+
+
+/**
+ * Attempts to load the base profile object from the
+ * specified QDomNode.
+ */
+void SpiralBackgroundProfile::loadBase(QDomNode &node) {
+ int tmpI;
+ QDomElement tempElem;
tempElem = node.firstChildElement("name");
if(!tempElem.isNull()) {
- retVal->_name = tempElem.text();
- }
-
- tempElem = node.firstChildElement("coarseness");
- if(!tempElem.isNull()) {
- tmpF = tempElem.text().toFloat();
- if(tmpF > 0.00 && tmpF < 10000.00) {
- retVal->_coarseness = tmpF;
- }
+ QString str = tempElem.text();
+ setName(str);
}
tempElem = node.firstChildElement("steps_per_tick");
if(!tempElem.isNull()) {
tmpI = tempElem.text().toInt();
- if(tmpI > 0 && tmpI < 30000) {
- retVal->_genStepsPerTick = tmpI;
- }
+ setGenStepsPerTick(tmpI);
}
tempElem = node.firstChildElement("anmiate_palette");
if(!tempElem.isNull()) {
QString param = tempElem.text();
- retVal->_bAnimatePalette = stringToBool(param);
+ setAnimatePalette(stringToBool(param));
}
tempElem = node.firstChildElement("palette_x_speed");
if(!tempElem.isNull()) {
tmpI = tempElem.text().toInt();
- if(tmpI >= 0 && tmpI < 30000) {
- retVal->_paletteXSpeed = tmpI;
- }
+ setPaletteXSpeed(tmpI);
}
tempElem = node.firstChildElement("palette_y_speed");
if(!tempElem.isNull()) {
tmpI = tempElem.text().toInt();
- if(tmpI >= 0 && tmpI < 30000) {
- retVal->_paletteYSpeed = tmpI;
- }
- }
-
- tempElem = node.firstChildElement("clamp_color");
- if(!tempElem.isNull()) {
- QString param = tempElem.text();
- retVal->_bClampColorIndex = stringToBool(param);
+ setPaletteYSpeed(tmpI);
}
tempElem = node.firstChildElement("palette");
if(!tempElem.isNull()) {
- retVal->_palName = tempElem.text();
+ setPaletteName(tempElem.text());
}
-
- return retVal;
}
-
-/*
+/**
* Returns a QDomNode object that represents this profile.
*/
-QDomNode PlasmaFractalBackgroundProfile::save(QDomDocument* doc) {
+QDomNode SpiralBackgroundProfile::save(QDomDocument* doc) {
QString tempStr;
QDomText tempNode;
QDomElement tempElem;
@@ -140,193 +135,192 @@
tempElem.appendChild(tempNode);
retVal.appendChild(tempElem);
+ // save base class values
+ saveBase(&retVal, doc);
+
+ // derivative clases would save data here
+
+ // return node.
+ return retVal;
+}
+
+
+/**
+ * Returns a QDomNode object that represents the base profile.
+ */
+void SpiralBackgroundProfile::saveBase(QDomElement* node, QDomDocument*
doc) {
+
+ QString tempStr;
+ QDomText tempNode;
+ QDomElement tempElem;
+
//name
tempNode = doc->createTextNode(_name);
tempElem = doc->createElement("name");
tempElem.appendChild(tempNode);
- retVal.appendChild(tempElem);
+ node->appendChild(tempElem);
- //coarseness
- tempStr.setNum(_coarseness);
- tempNode = doc->createTextNode(tempStr);
- tempElem = doc->createElement("coarseness");
- tempElem.appendChild(tempNode);
- retVal.appendChild(tempElem);
-
//steps per tick
tempStr.setNum(_genStepsPerTick);
tempNode = doc->createTextNode(tempStr);
tempElem = doc->createElement("steps_per_tick");
tempElem.appendChild(tempNode);
- retVal.appendChild(tempElem);
+ node->appendChild(tempElem);
//animate palette?
tempNode = doc->createTextNode(boolToString(_bAnimatePalette));
tempElem = doc->createElement("anmiate_palette");
tempElem.appendChild(tempNode);
- retVal.appendChild(tempElem);
+ node->appendChild(tempElem);
//palette X speed
tempStr.setNum(_paletteXSpeed);
tempNode = doc->createTextNode(tempStr);
tempElem = doc->createElement("palette_x_speed");
tempElem.appendChild(tempNode);
- retVal.appendChild(tempElem);
+ node->appendChild(tempElem);
//palette Y speed
tempStr.setNum(_paletteYSpeed);
tempNode = doc->createTextNode(tempStr);
tempElem = doc->createElement("palette_y_speed");
tempElem.appendChild(tempNode);
- retVal.appendChild(tempElem);
-
- //clamp color index?
- tempNode = doc->createTextNode(boolToString(_bClampColorIndex));
- tempElem = doc->createElement("clamp_color");
- tempElem.appendChild(tempNode);
- retVal.appendChild(tempElem);
+ node->appendChild(tempElem);
//palette name
tempNode = doc->createTextNode(_palName);
tempElem = doc->createElement("palette");
tempElem.appendChild(tempNode);
- retVal.appendChild(tempElem);
-
- return retVal;
+ node->appendChild(tempElem);
}
-/*
+/**
* Creates and returns a new background object.
*/
-Background* PlasmaFractalBackgroundProfile::getNewBackgroundObj(int
height, int width, QHash<QString, IndexedPaletteProfile*>* palHash) {
- return new PlasmaFractal(width, height,
- palHash->value(_palName)->createPalette(), _coarseness,
_genStepsPerTick,
- _bAnimatePalette, _paletteXSpeed, _paletteYSpeed, _bClampColorIndex);
+Background* SpiralBackgroundProfile::getNewBackgroundObj(int height, int
width,
+ QHash<QString, IndexedPaletteProfile*>* palHash) {
+
+ SpiralAlgorithm* alg = new SpiralAlgorithm();
+ if(alg == NULL)
+ return NULL;
+
+ return new SpiralBackground(width, height, alg,
+ palHash->value(_palName)->createPalette(),
+ _bAnimatePalette, _paletteXSpeed, _paletteYSpeed,
+ _genStepsPerTick);
}
-/*
+/**
* get/set palette name.
*/
-QString PlasmaFractalBackgroundProfile::getPaletteName() {
+QString SpiralBackgroundProfile::getPaletteName() {
return _palName;
}
-void PlasmaFractalBackgroundProfile::setPaletteName(QString paletteName) {
+void SpiralBackgroundProfile::setPaletteName(QString paletteName) {
_palName = paletteName;
}
-/*
- * get/set coarseness.
- */
-float PlasmaFractalBackgroundProfile::getCoarseness() {
- return _coarseness;
-}
-
-void PlasmaFractalBackgroundProfile::setCoarseness(float coarseness) {
- _coarseness = coarseness;
-}
-
-/*
+/**
* get/set steps per tick
*/
-int PlasmaFractalBackgroundProfile::getGenStepsPerTick() {
+int SpiralBackgroundProfile::getGenStepsPerTick() {
return _genStepsPerTick;
}
-void PlasmaFractalBackgroundProfile::setGenStepsPerTick(int
genStepsPerTick) {
- _genStepsPerTick = genStepsPerTick;
+void SpiralBackgroundProfile::setGenStepsPerTick(int genStepsPerTick) {
+ _genStepsPerTick = genStepsPerTick;
}
-/*
+/**
* Get/set animate palette.
*/
-bool PlasmaFractalBackgroundProfile::getAnimatePalette() {
+bool SpiralBackgroundProfile::getAnimatePalette() {
return _bAnimatePalette;
}
-void PlasmaFractalBackgroundProfile::setAnimatePalette(bool
bAnimatePalette) {
+void SpiralBackgroundProfile::setAnimatePalette(bool bAnimatePalette) {
_bAnimatePalette = bAnimatePalette;
}
-/*
+/**
* get/set palette x speed.
*/
-float PlasmaFractalBackgroundProfile::getPaletteXSpeed() {
+float SpiralBackgroundProfile::getPaletteXSpeed() {
return _paletteXSpeed;
}
-void PlasmaFractalBackgroundProfile::setPaletteXSpeed(float speed) {
- _paletteXSpeed = speed;
+void SpiralBackgroundProfile::setPaletteXSpeed(float speed) {
+ if(0.0 <= speed && speed <= 30000.0)
+ _paletteXSpeed = speed;
}
-/*
+/**
* get/set palette y speed.
*/
-float PlasmaFractalBackgroundProfile::getPaletteYSpeed() {
+float SpiralBackgroundProfile::getPaletteYSpeed() {
return _paletteYSpeed;
}
-void PlasmaFractalBackgroundProfile::setPaletteYSpeed(float speed) {
- _paletteYSpeed = speed;
+void SpiralBackgroundProfile::setPaletteYSpeed(float speed) {
+ if(0.0 <= speed && speed <= 30000.0)
+ _paletteYSpeed = speed;
}
-/*
- * Get/set clamp color index.
+/**
+ * Called whenever palette names change
*/
-bool PlasmaFractalBackgroundProfile::getClampColorIndex() {
- return _bClampColorIndex;
+void SpiralBackgroundProfile::paletteNameChanged(QString oldName,
+ QString newName) {
+ // if the palette name matches the old name, change the name.
+ if(_palName == oldName) {
+ _palName = newName;
+ }
}
-
-void PlasmaFractalBackgroundProfile::setClampColorIndex(bool
bClampColorIndex) {
- _bClampColorIndex = bClampColorIndex;
+
+/**
+ * Called whenever a palette is removed.
+ */
+void SpiralBackgroundProfile::paletteRemoved(QString palName) {
+ // if this palette has been removed, set current palette name to ""
+ if(_palName == palName) {
+ _palName = QString("");
+ }
}
-/*
- * Overloaded assignment operator
+/**
+ * Copies the base values of the specified profile to this profile.
*/
-PlasmaFractalBackgroundProfile&
PlasmaFractalBackgroundProfile::operator=(PlasmaFractalBackgroundProfile&
other) {
+void SpiralBackgroundProfile::baseCopy(SpiralBackgroundProfile& other) {
_name = other._name;
_palName = other._palName;
- _coarseness = other._coarseness;
_genStepsPerTick = other._genStepsPerTick;
_bAnimatePalette = other._bAnimatePalette;
_paletteXSpeed = other._paletteXSpeed;
_paletteYSpeed = other._paletteYSpeed;
- _bClampColorIndex = other._bClampColorIndex;
+
+}
+
+/**
+ * Overloaded assignment operator
+ */
+SpiralBackgroundProfile&
SpiralBackgroundProfile::operator=(SpiralBackgroundProfile& other) {
+
+ baseCopy(other);
return *this;
}
-/*
+/**
* Creates a new object with this object's settings.
*/
-BackgroundProfile* PlasmaFractalBackgroundProfile::clone() {
- PlasmaFractalBackgroundProfile* retVal = new
PlasmaFractalBackgroundProfile();
+BackgroundProfile* SpiralBackgroundProfile::clone() {
+ SpiralBackgroundProfile* retVal = new SpiralBackgroundProfile();
*retVal = *this;
return (BackgroundProfile*)retVal;
}
-/**
- * Called whenever palette names change
- */
-void PlasmaFractalBackgroundProfile::paletteNameChanged(QString oldName,
- QString newName) {
- // if the palette name matches the old name, change the name.
- if(_palName == oldName) {
- _palName = newName;
- }
-}
-
-/**
- * Called whenever a palette is removed.
- */
-void PlasmaFractalBackgroundProfile::paletteRemoved(QString palName) {
- // if this palette has been removed, set current palette name to ""
- if(_palName == palName) {
- _palName = QString("");
- }
-}
=======================================
--- /src/SpiralLenz/src/SpiralBackgroundProfile.h Mon Mar 16 21:29:13 2009
UTC
+++ /src/SpiralLenz/src/SpiralBackgroundProfile.h Mon Apr 27 00:56:58 2009
UTC
@@ -23,112 +23,140 @@
*/
/**
- * This background profile is responsible for setting up and returning a
new
- * PlasmaFractal background object.
+ * This is the base class for all spiral background profiles.
*
* @author jeff backus
- * @date 09/01/2007
+ * @date 03/23/2009
*/
-#ifndef __PLASMAFRACTALBACKGROUNDPROFILE_H__
-#define __PLASMAFRACTALBACKGROUNDPROFILE_H__
+#ifndef __SPIRALBACKGROUNDPROFILE_H__
+#define __SPIRALBACKGROUNDPROFILE_H__
#include <QString>
#include <QtXml/QDomNode>
#include <QtXml/QDomDocument>
+#include <QLayout>
-#include "../../common/2d_bgnd_w_lens/BackgroundProfile.h"
+#include "2d_bgnd_w_lens/BackgroundProfile.h"
-class PlasmaFractalBackgroundProfile : public BackgroundProfile {
+class SpiralBackgroundProfile : public BackgroundProfile {
-public:
- PlasmaFractalBackgroundProfile();
- ~PlasmaFractalBackgroundProfile();
+ public:
+ SpiralBackgroundProfile();
+ virtual ~SpiralBackgroundProfile();
- /* Attempts to load this background profile object from the
- * specified QDomNode.
- */
- BackgroundProfile* load(QDomNode &node);
+ /**
+ * Attempts to load this background profile object from the
+ * specified QDomNode.
+ */
+ virtual BackgroundProfile* load(QDomNode &node);
- /*
- * Returns a QDomNode object that represents this profile.
- */
- QDomNode save(QDomDocument* doc);
+ /**
+ * Returns a QDomNode object that represents this profile.
+ */
+ virtual QDomNode save(QDomDocument* doc);
- /*
- * Creates and returns a new background object.
- */
- Background* getNewBackgroundObj(int height, int width, QHash<QString,
IndexedPaletteProfile*>* palHash);
+ /**
+ * Creates and returns a new background object.
+ */
+ virtual Background* getNewBackgroundObj(int height, int width,
+ QHash<QString, IndexedPaletteProfile*>* palHash
+ );
- /*
- * get/set palette name.
- */
- QString getPaletteName();
- void setPaletteName(QString paletteName);
+ /**
+ * get/set palette name.
+ */
+ QString getPaletteName();
+ void setPaletteName(QString paletteName);
- /*
- * get/set coarseness.
- */
- float getCoarseness();
- void setCoarseness(float coarseness);
+ /**
+ * get/set steps per tick
+ */
+ int getGenStepsPerTick();
+ void setGenStepsPerTick(int genStepsPerTick);
- /*
- * get/set steps per tick
- */
- int getGenStepsPerTick();
- void setGenStepsPerTick(int genStepsPerTick);
+ /**
+ * Get/set animate palette.
+ */
+ bool getAnimatePalette();
+ void setAnimatePalette(bool bAnimatePalette);
- /*
- * Get/set animate palette.
- */
- bool getAnimatePalette();
- void setAnimatePalette(bool bAnimatePalette);
+ /**
+ * get/set palette x speed.
+ */
+ float getPaletteXSpeed();
+ void setPaletteXSpeed(float speed);
- /*
- * get/set palette x speed.
- */
- float getPaletteXSpeed();
- void setPaletteXSpeed(float speed);
+ /**
+ * get/set palette y speed.
+ */
+ float getPaletteYSpeed();
+ void setPaletteYSpeed(float speed);
+
+ /**
+ * Overloaded assignment operator.
+ */
+ virtual SpiralBackgroundProfile& operator=(SpiralBackgroundProfile&
other);
+
+ /**
+ * Creates a new object with this object's settings.
+ */
+ virtual BackgroundProfile* clone();
+
+ /**
+ * Called whenever palette names change
+ */
+ virtual void paletteNameChanged(QString oldName, QString newName);
+
+ /**
+ * Called whenever a palette is removed.
+ */
+ virtual void paletteRemoved(QString palName);
+
+ /**
+ * Retrieves the configuration QLayout. The receiver is
+ * responsible for deleting the QLayout, which in turn will delete
+ * all of the components it contains. Does not contain the base
+ * class information!
+ *
+ * @see SpiralBackgroundProfileWidget
+ *
+ * @param bCreateNewWidget If false, the last widget created will be
returned.
+ * If true or the first time this function is called, it will create a
new
+ * layout.
+ */
+ //virtual QLayout* getConfigPanel(bool bCreateNewPanel);
+
+ /**
+ * Transfers all of the data in the panel to the internal data
structures.
+ */
+ //virtual void saveGUIData();
- /*
- * get/set palette y speed.
- */
- float getPaletteYSpeed();
- void setPaletteYSpeed(float speed);
+ protected:
+ /**
+ * Attempts to load the base profile object from the
+ * specified QDomNode.
+ */
+ void loadBase(QDomNode &node);
- /*
- * Get/set clamp color index.
- */
- bool getClampColorIndex();
- void setClampColorIndex(bool bClampColorIndex);
+ /**
+ * Returns a QDomNode object that represents the base profile.
+ */
+ void saveBase(QDomElement* node, QDomDocument* doc);
- /*
- * Overloaded assignment operator.
- */
- PlasmaFractalBackgroundProfile& operator=(PlasmaFractalBackgroundProfile&
other);
+ /**
+ * Copies the base values of the specified profile to this profile.
+ */
+ void baseCopy(SpiralBackgroundProfile& other);
- /*
- * Creates a new object with this object's settings.
- */
- BackgroundProfile* clone();
+ QString _palName;
+ int _genStepsPerTick;
+ bool _bAnimatePalette;
+ float _paletteXSpeed;
+ float _paletteYSpeed;
- /**
- * Called whenever palette names change
- */
- virtual void paletteNameChanged(QString oldName, QString newName);
-
- /**
- * Called whenever a palette is removed.
- */
- virtual void paletteRemoved(QString palName);
+ // begin GUI related
+ QLayout* _configLayout;
-private:
- QString _palName;
- float _coarseness;
- int _genStepsPerTick;
- bool _bAnimatePalette;
- float _paletteXSpeed;
- float _paletteYSpeed;
- bool _bClampColorIndex;
};
#endif
=======================================
--- /src/SpiralLenz/src/project_specific_externs.cpp Mon Mar 16 21:29:13
2009 UTC
+++ /src/SpiralLenz/src/project_specific_externs.cpp Mon Apr 27 00:56:58
2009 UTC
@@ -28,10 +28,11 @@
#include <QString>
-#include "../../common/2d_bgnd_w_lens/BackgroundProfile.h"
-#include "../../common/2d_bgnd_w_lens/lens_engine/LensProfile.h"
-#include "../../common/2d_bgnd_w_lens/lens_engine/SphericalLensProfile.h"
+#include "2d_bgnd_w_lens/BackgroundProfile.h"
+#include "2d_bgnd_w_lens/lens_engine/LensProfile.h"
+#include "2d_bgnd_w_lens/lens_engine/SphericalLensProfile.h"
#include "SpiralBackgroundProfile.h"
+#include "RectangularSpiralBackgroundProfile.h"
/**
* This function will create an array that contains the profiles
@@ -42,7 +43,7 @@
BackgroundProfile** getBackgroundTypes(int* numProfiles) {
BackgroundProfile** retVal = NULL;
- *numProfiles = 1;
+ *numProfiles = 2;
retVal = new BackgroundProfile*[*numProfiles];
if(retVal == NULL) {
@@ -56,6 +57,14 @@
*numProfiles = 0;
return NULL;
}
+
+ retVal[1] = (BackgroundProfile*)
+ (new RectangularSpiralBackgroundProfile());
+
+ if(retVal[1] == NULL) {
+ *numProfiles = 0;
+ return NULL;
+ }
return retVal;
}
=======================================
--- /src/common/2d_bgnd_w_lens/Background.h Sun Jan 11 17:51:04 2009 UTC
+++ /src/common/2d_bgnd_w_lens/Background.h Mon Apr 27 00:56:58 2009 UTC
@@ -34,72 +34,72 @@
class Background {
-public:
- /**
- * Draws the whole Background.
- */
- virtual void drawBackground(screen_struct* screenObj);
+ public:
+ /**
+ * Draws the whole Background.
+ */
+ virtual void drawBackground(screen_struct* screenObj);
- /**
- * Whether or not the background should animate
- * itself (if it supports it)
- */
- void enableAnimation(bool bEnableAnimation);
+ /**
+ * Whether or not the background should animate
+ * itself (if it supports it)
+ */
+ void enableAnimation(bool bEnableAnimation);
- /**
- * Call this every tick to animate.
- * Must be overloaded by derived class.
- */
- virtual void clocktick();
+ /**
+ * Call this every tick to animate.
+ * Must be overloaded by derived class.
+ */
+ virtual void clocktick();
- /**
- * Used to set whether to show the fractal generation or not.
- * If so, the number of steps are shown per render pass.
- */
- //void setShowGeneration(bool bShowGen, int numPasses);
+ /**
+ * Used to set whether to show the fractal generation or not.
+ * If so, the number of steps are shown per render pass.
+ */
+ //void setShowGeneration(bool bShowGen, int numPasses);
- /**
- * Returns true if the background has finished whatever
- * setup it needs to do, animated or otherwise.
- */
- bool isSetupFinished();
+ /**
+ * Returns true if the background has finished whatever
+ * setup it needs to do, animated or otherwise.
+ */
+ bool isSetupFinished();
- /**
- * Constructor takes the background dimensions as
- * arguments.
- */
- Background(int sizeX, int sizeY);
+ /**
+ * Constructor takes the background dimensions as
+ * arguments.
+ */
+ Background(int sizeX, int sizeY);
- ~Background(void);
+ ~Background(void);
- //*** Begin Screen Related ***
- int getScreenWidth();
- int getScreenHeight();
- int getTextureWidth();
- int getTextureHeight();
- //*** End Screen Related
+ //*** Begin Screen Related ***
+ int getScreenWidth();
+ int getScreenHeight();
+ int getTextureWidth();
+ int getTextureHeight();
+ //*** End Screen Related
-protected:
- /**
- * Default constructor...
- */
- Background();
+ protected:
+ /**
+ * Default constructor...
+ */
+ Background();
- /**
- * Called from the constructor and does all of the work,
- * so that derived classes can call from their constructors.
- * sizeX and sizeY are the dimensions of the background, not
- * necessarily the size of the screen object, which has to
- * be a power of 2.
- */
- void initBackground(int sizeX, int sizeY);
+ /**
+ * Called from the constructor and does all of the work,
+ * so that derived classes can call from their constructors.
+ * sizeX and sizeY are the dimensions of the background, not
+ * necessarily the size of the screen object, which has to
+ * be a power of 2.
+ */
+ void initBackground(int sizeX, int sizeY);
- int _sizeX;
- int _sizeY;
+ int _sizeX;
+ int _sizeY;
- bool _bEnableAnimation;
+ bool _bEnableAnimation;
- bool _bSetupFinished;
+ bool _bSetupFinished;
};
#endif
=======================================
--- /src/common/2d_bgnd_w_lens/BackgroundProfile.cpp Sun Jan 11 17:51:04
2009 UTC
+++ /src/common/2d_bgnd_w_lens/BackgroundProfile.cpp Mon Apr 27 00:56:58
2009 UTC
@@ -23,6 +23,17 @@
*/
#include "BackgroundProfile.h"
+
+ /**
+ * Default constructor/destructor
+ */
+BackgroundProfile::BackgroundProfile() {
+ _name = "Uninitialized Base Backround Profile";
+ _xmlTypeValue = "Base Background Profile";
+}
+BackgroundProfile::~BackgroundProfile() {
+ // no es nada
+}
/* Attempts to load this background profile object from the
* specified QDomNode.
=======================================
--- /src/common/2d_bgnd_w_lens/BackgroundProfile.h Sun Jan 11 17:51:04 2009
UTC
+++ /src/common/2d_bgnd_w_lens/BackgroundProfile.h Mon Apr 27 00:56:58 2009
UTC
@@ -44,58 +44,64 @@
class BackgroundProfile {
-public:
- /* Attempts to load this background profile object from the
- * specified QDomNode.
- */
- virtual BackgroundProfile* load(QDomNode &node);
+ public:
+ /**
+ * Default constructor/destructor
+ */
+ BackgroundProfile();
+ virtual ~BackgroundProfile();
- /*
- * Returns a QDomNode object that represents this profile.
- */
- virtual QDomNode save(QDomDocument* doc);
+ /* Attempts to load this background profile object from the
+ * specified QDomNode.
+ */
+ virtual BackgroundProfile* load(QDomNode &node);
- /*
- * Creates and returns a new background object.
- */
- virtual Background* getNewBackgroundObj(int height, int width,
QHash<QString, IndexedPaletteProfile*>* palHash);
+ /*
+ * Returns a QDomNode object that represents this profile.
+ */
+ virtual QDomNode save(QDomDocument* doc);
- /**
- * Called whenever palette names change
- */
- virtual void paletteNameChanged(QString oldName, QString newName);
+ /*
+ * Creates and returns a new background object.
+ */
+ virtual Background* getNewBackgroundObj(int height, int width,
QHash<QString, IndexedPaletteProfile*>* palHash);
+
+ /**
+ * Called whenever palette names change
+ */
+ virtual void paletteNameChanged(QString oldName, QString newName);
- /**
- * Called whenever a palette is removed.
- */
- virtual void paletteRemoved(QString palName);
+ /**
+ * Called whenever a palette is removed.
+ */
+ virtual void paletteRemoved(QString palName);
- /*
- * Get/set the name of this profile.
- */
- void setName(QString &name);
- QString getName();
+ /*
+ * Get/set the name of this profile.
+ */
+ void setName(QString &name);
+ QString getName();
- /*
- * Returns the tag name used by Dom elements for all
- * subclasses of BackgroundProfile.
- */
- static QString getXMLTagName();
+ /*
+ * Returns the tag name used by Dom elements for all
+ * subclasses of BackgroundProfile.
+ */
+ static QString getXMLTagName();
- /*
- * Returns the type of BackgroundProfile.
- */
- QString getBackgroundType();
+ /*
+ * Returns the type of BackgroundProfile.
+ */
+ QString getBackgroundType();
- /*
- * Creates a new object with this object's settings.
- */
- virtual BackgroundProfile* clone();
+ /*
+ * Creates a new object with this object's settings.
+ */
+ virtual BackgroundProfile* clone();
-protected:
+ protected:
- QString _name;
- QString _xmlTypeValue; /* Needs set by subclasses!*/
+ QString _name;
+ QString _xmlTypeValue; /* Needs set by subclasses!*/
};
#endif
=======================================
--- /src/common/spirals/RectangularSpiralAlgorithm.cpp Mon Mar 16 21:29:13
2009 UTC
+++ /src/common/spirals/RectangularSpiralAlgorithm.cpp Mon Apr 27 00:56:58
2009 UTC
@@ -1,3 +1,9 @@
+
+// debug
+//#include <iostream>
+//using namespace std;
+// end debug
+
#include "RectangularSpiralAlgorithm.h"
/**
@@ -6,7 +12,66 @@
RectangularSpiralAlgorithm::RectangularSpiralAlgorithm() {
_cornerSeg = NULL;
_straightSeg = NULL;
+
+ _colorWidth = 1;
+ _emptyWidth = 0;
+ _bConstantColor = true;
+ _bRandomColor = false;
+ _bClockwise = false;
+ _bIncrementColor = true;
+ _currX = 0;
+ _currY = 0;
+ _nextIdx = 0;
+ _xSegs = 0;
+ _ySegs = 0;
+ _remainingSegs = 0;
+ _xMaxSegs = 0;
+ _yMaxSegs = 0;
+ _maxFieldIdx = 0;
+ _halfSegSize = 0;
}
+
+/**
+ * Constructor takes initialization parameters.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @param bRandomColor whether or not the initial color is randomly
selected.
+ * @param bIncrementColor whether to increment the color as it spirals out.
+ * @see calc()
+ */
+RectangularSpiralAlgorithm::RectangularSpiralAlgorithm(const int
colorWidth,
+ const int emptyWidth,
+ const bool bConstantColor,
+ const bool bRandomColor,
+ const bool bIncrementColor) {
+ _cornerSeg = NULL;
+ _straightSeg = NULL;
+
+ _currX = 0;
+ _currY = 0;
+ _nextIdx = 0;
+ _xSegs = 0;
+ _ySegs = 0;
+ _remainingSegs = 0;
+ _xMaxSegs = 0;
+ _yMaxSegs = 0;
+ _maxFieldIdx = 0;
+ _halfSegSize = 0;
+ _bClockwise = false;
+
+ _colorWidth = colorWidth;
+ _emptyWidth = emptyWidth;
+ _bConstantColor = bConstantColor;
+ _bRandomColor = bRandomColor;
+ _bIncrementColor = bIncrementColor;
+
+ if(_colorWidth < 0)
+ _colorWidth = 0;
+ if(_emptyWidth < 0)
+ _emptyWidth = 0;
+}
+
RectangularSpiralAlgorithm::~RectangularSpiralAlgorithm() {
if(_cornerSeg != NULL) {
@@ -25,19 +90,12 @@
* @param screenWidth the width of the screen in pixels.
* @param screenHeight the height of the screen in pixels.
* @param numColors the number of colors in the palette primary direction.
- * @param colorWidth the width of the strip of color.
- * @param emptyWidth the width of the default color region.
- * @param bConstantColor whether or not to hold the color index constant.
- * @param bRandomColor whether or not the initial color is randomly
selected.
* @see calc()
*/
-void RectangularSpiralAlgorithm::initialize(int* field, int screenWidth,
- int screenHeight, int numColors,
- int colorWidth, int emptyWidth,
- bool bConstantColor,
- bool bRandomColor) {
- initializeBase(field, screenWidth, screenHeight, numColors, colorWidth,
- colorHeight, bConstantColor);
+void RectangularSpiralAlgorithm::initialize(int* field, const int
screenWidth,
+ const int screenHeight,
+ const int numColors) {
+ initializeBase(field, screenWidth, screenHeight, numColors);
if(_height <= 0)
return;
@@ -46,58 +104,62 @@
if(_numColors <= 0)
return;
- calcSegs();
-
// set initial starting position
_currX = screenWidth / 2;
_currY = screenHeight / 2;
+ _maxFieldIdx = screenWidth * screenHeight - 1;
// pick initial color
- if(bRandomColor) {
+ if(_bRandomColor) {
_nextIdx = jrand() % numColors;
} else {
_nextIdx = 0;
}
// pick direction
- _dir = jrand() % 4;
+ _dir = (RectangularSpiralAlgorithmDir) (jrand() % 4);
_bClockwise = (jrand() % 2 == 0);
+ // begin debug
+ //cout<<"Forcing dir!"<<endl;
+ //_dir = RIGHT;
+ //_bClockwise = true;
+ // end debug
+
// set initial distances
switch(_dir) {
case UP:
- _bXPositive = _bClockwise;
- _xSegs = 2;
+ _xSegs = 1;
- _bYPositive = true;
- _ySegs = 1;
+ _ySegs = 0;
_remainingSegs = 1;
break;
case DOWN:
- _bXPositive = !_bClockwise;
- _xSegs = 2;
+ _xSegs = 1;
- _bYPositive = false;
- _ySegs = 1;
+ _ySegs = 0;
_remainingSegs = 1;
break;
case LEFT:
- _bXPositive = false;
- _xSegs = 1;
+ _xSegs = 0;
_remainingSegs = 1;
- _bYPositive = _bClockwise;
- _ySegs = 2;
+ _ySegs = 1;
break;
case RIGHT:
default:
- _bXPositive = true;
- _xSegs = 1;
+ _xSegs = 0;
_remainingSegs = 1;
- _bYPositive = !_bClockwise;
- _ySegs = 2;
+ _ySegs = 1;
}
+
+ // calculate segments
+ calcSegments();
+
+ // calculate stopping condition.
+ _xMaxSegs = _width / _segmentSize;
+ _yMaxSegs = _height / _segmentSize;
}
@@ -107,105 +169,120 @@
*/
bool RectangularSpiralAlgorithm::calc() {
if(_field == NULL)
- return;
+ return true;
if(_cornerSeg == NULL)
- return;
+ return true;
if(_straightSeg == NULL)
- return;
-
- int i;
+ return true;
/**
- * To Do:
+ * Algorithm:
* - Process a segment
* - Update _currX and/or _currY
* - Update color index, if necessary
* - Decrement _remainingSegs
- * - if _remainingSegs == 0:
+ * - if _remainingSegs == 1:
* - change _dir
- * - update polarities, current/next segs, and _remainingSegs.
+ * - update current/next segs and _remainingSegs.
*/
-
- // update color index
- if(!_bConstantColor) {
- _nextIdx = (_nextIdx+_segmentSize)%_numColors;
- }
- // update the number of remaining segments. If we hit 0,
- // time to change direction!
- _remainingSegs--;
- if(_remainingSegs <= 0) {
- // establish new direction
+ // draw a segment
+ if(_remainingSegs <= 1) {
+ // draw a corner segment
+ drawSegment(_cornerSeg);
+
+ //float halfSegSize = float(_segmentSize)/2;
+
+ // update position and reset _remainingSegs
switch(_dir) {
case UP:
- _dir = _bClockwise ? RIGHT : LEFT;
+ _currY += _halfSegSize;
+ if(_bClockwise) {
+ _currX += _halfSegSize;
+ _dir = RIGHT;
+ } else {
+ _currX -= _halfSegSize;
+ _dir = LEFT;
+ }
+ _ySegs++;
+ _remainingSegs = _xSegs;
break;
case DOWN:
- _dir = _bClockwise ? LEFT : RIGHT;
+ _currY -= _halfSegSize;
+ if(_bClockwise) {
+ _currX -= _halfSegSize;
+ _dir = LEFT;
+ } else {
+ _currX += _halfSegSize;
+ _dir = RIGHT;
+ }
+ _ySegs++;
+ _remainingSegs = _xSegs;
break;
case LEFT:
- _dir = _bClockwise ? UP : DOWN;
+ _currX -= _halfSegSize;
+ if(_bClockwise) {
+ _currY += _halfSegSize;
+ _dir = UP;
+ } else {
+ _currY -= _halfSegSize;
+ _dir = DOWN;
+ }
+ _xSegs++;
+ _remainingSegs = _ySegs;
break;
case RIGHT:
default:
- _dir = _bClockwise ? DOWN : UP;
+ _currX += _halfSegSize;
+ if(_bClockwise) {
+ _currY -= _halfSegSize;
+ _dir = DOWN;
+ } else {
+ _currY += _halfSegSize;
+ _dir = UP;
+ }
+ _xSegs++;
+ _remainingSegs = _ySegs;
}
- }
-
- /*
- // old
- // Check the remaining distance. If it is 0, then we are turning.
- if(_remainingSegs == 0) {
- int bevDim = _colorWidth+2*_emptyWidth;
-
- // move through the turn
+ // debug
+ //return true;
+ // end debug
+ } else {
+ // draw a straight segment
+ drawSegment(_straightSeg);
+
+ // update position
switch(_dir) {
case UP:
- // up to right or up to left is a counter-clockwise rotation
- _currY++;
- int tmpX = _currX;
- int tmpY = _currY*_width;
-
- if(_currY >= 0 && _currY < _height) {
- for(i=0; i<bevDim;i++) {
- if(tmpX >= 0 && _tmpX < _width) {
- int bevX = bevDim - _remainingTurn;
- int bevY = (bevDim - i - 1)*bevDim;
- if(_bevel[bevX + bevY] >= 0) {
- _field[tmpY+(tmpX++)] = _nextIdx + _bevel[bevX + bevY];
- } else {
- _field[tmpY+(tmpX++)] = -1;
- }
- }
- }
- }
+ _currY += _segmentSize;
break;
case DOWN:
- // down to right or down to left is a clockwise rotation
- _currY--;
- int tmpX = _currX;
- int tmpY = _currY*_width;
-
- if(_currY >= 0 && _currY < _height) {
- for(i=0; i<bevDim;i++) {
- if(tmpX >= 0 && _tmpX < _width) {
- int bevX = _remainingTurn;
- int bevY = (i)*bevDim;
- if(_bevel[bevX + bevY] >= 0) {
- _field[tmpY+(tmpX++)] = _nextIdx + _bevel[bevX + bevY];
- } else {
- _field[tmpY+(tmpX++)] = -1;
- }
- }
- }
- }
+ _currY -= _segmentSize;
break;
case LEFT:
+ _currX -= _segmentSize;
break;
case RIGHT:
default:
+ _currX += _segmentSize;
}
-*/
+ _remainingSegs--;
+ }
+
+ // update color index
+ if(!_bConstantColor) {
+ if(_bIncrementColor) {
+ _nextIdx = (_nextIdx+_segmentSize)%_numColors;
+ } else {
+ _nextIdx = _nextIdx - _segmentSize;
+ if(_nextIdx < 0) {
+ _nextIdx = _numColors - _nextIdx;
+ }
+ }
+ }
+
+ //return true;
+ return (_xSegs > _xMaxSegs) && (_ySegs > _yMaxSegs);
}
/**
@@ -228,6 +305,7 @@
// set the segment dimension
_segmentSize = _colorWidth + 2*_emptyWidth;
+ _halfSegSize = float(_segmentSize)/2.0;
// create space for the two segments
_straightSeg = new int[_segmentSize * _segmentSize];
@@ -236,10 +314,20 @@
_cornerSeg = new int[_segmentSize * _segmentSize];
if(_cornerSeg == NULL)
return;
+
+ int x, y, yCalc;
+
+ // init segment space
+ for(y=0;y<_segmentSize;y++) {
+ yCalc = y*_segmentSize;
+ for(x=0;x<_segmentSize;x++) {
+ _straightSeg[yCalc+x] = -1;
+ _cornerSeg[yCalc+x] = -1;
+ }
+ }
// build the straight segment. See comment in header file for more
// information.
- int x, y, yCalc, yInvCalc;
for(y=0;y<_segmentSize; y++) {
yCalc = y * _segmentSize;
for(x=0;x<_segmentSize;x++) {
@@ -252,7 +340,11 @@
if(_bConstantColor) {
_straightSeg[yCalc+x] = 0;
} else {
- _straightSeg[yCalc+x] = x;
+ if(_bIncrementColor) {
+ _straightSeg[yCalc+x] = x;
+ } else {
+ _straightSeg[yCalc+x] = _segmentSize - x - 1;
+ }
}
}
}
@@ -265,26 +357,119 @@
if(_bClockwise) {
for(y = 0; y<_segmentSize; y++) {
yCalc = y*_segmentSize;
- yInvCalc = (_segmentSize - y)*_segmentSize;
for(x = 0; x<_segmentSize; x++) {
if(x < y) {
_cornerSeg[yCalc+x] = _straightSeg[yCalc+x];
} else {
- _cornerSeg[yCalc+x] = _straightSeg[yInvCalc+(_segmentSize-x)];
+ _cornerSeg[yCalc+x] = _straightSeg[(_segmentSize -x -1)*_segmentSize
+ + (_segmentSize -y -1)];
}
}
}
} else {
for(y = 0; y<_segmentSize; y++) {
yCalc = y*_segmentSize;
- yInvCalc = (_segmentSize - y)*_segmentSize;
for(x = 0; x<_segmentSize; x++) {
- if(x < (_segmentSize-y)) {
+ if(x < _segmentSize-y-1) {
_cornerSeg[yCalc+x] = _straightSeg[yCalc+x];
} else {
- _cornerSeg[yCalc+x] = _straightSeg[yInvCalc+(_segmentSize-x)];
+ _cornerSeg[yCalc+x] = _straightSeg[x*_segmentSize + y];
}
}
}
}
}
+
+/**
+ * Rotates and draws the specified segment at (_currX,_currY) based
+ * on _dir.
+ */
+void RectangularSpiralAlgorithm::drawSegment(int* seg) {
+ if(seg == NULL)
+ return;
+
+ // first, we need to translate the _currX and _currY positions to
+ // the lower left-hand corner. Remember: (_currX,_currY) is the
+ // midpoint of the side opposite the direction we're going. i.e.
+ // (_currX,_currY) is the midpoint of the left side when going right.
+ float xCornerFloat, yCornerFloat;
+
+ switch(_dir) {
+ case UP:
+ xCornerFloat = _currX - _halfSegSize;
+ yCornerFloat = _currY;
+ break;
+ case DOWN:
+ xCornerFloat = _currX - _halfSegSize;
+ yCornerFloat = _currY - float(_segmentSize);
+ break;
+ case LEFT:
+ xCornerFloat = _currX - float(_segmentSize);
+ yCornerFloat = _currY - _halfSegSize;
+ break;
+ case RIGHT:
+ default:
+ xCornerFloat = _currX;
+ yCornerFloat = _currY - _halfSegSize;
+ }
+
+ // there seems to be a rounding error
+ if(xCornerFloat < 0.0) {
+ xCornerFloat -= 0.5;
+ }
+ if(yCornerFloat < 0.0) {
+ yCornerFloat -= 0.5;
+ }
+ int xCorner = xCornerFloat;
+ int yCorner = yCornerFloat;
+
+ // adjust yCorner to be ready for copying
+ int yCornerAdjusted = yCorner * _width;
+
+ // now copy from seg to _field. Modifying (x,y) in order
+ // to rotate:
+ // Rt: field(x,y) = seg( x, y)
+ // Up: field(x,y) = seg(-y, x)
+ // Lf: field(x,y) = seg(-x,-y)
+ // Dn: field(x,y) = seg( y,-x)
+
+ for(int i=0; i<_segmentSize; i++) {
+ int fieldY = i*_width;
+ for(int j=0; j<_segmentSize; j++) {
+ // set (x,y) = rot(j,i)
+ int x;
+ int y;
+ switch(_dir) {
+ case UP:
+ x = i;
+ y = _segmentSize-j-1;
+ break;
+ case DOWN:
+ x = _segmentSize-i-1;
+ y = j;
+ break;
+ case LEFT:
+ x = _segmentSize-j-1;
+ y = _segmentSize-i-1;
+ break;
+ case RIGHT:
+ default:
+ x = j;
+ y = i;
+ }
+
+ // copy
+ int ySeg = y*_segmentSize;
+ int fieldIdx = yCornerAdjusted+fieldY+xCorner+j;
+ if(0 <= xCorner+j && xCorner+j < _width &&
+ 0 <= yCorner+i && yCorner+i < _height &&
+ 0 <= ySeg+x && ySeg+x < _segmentSize*_segmentSize-1) {
+ if(seg[ySeg + x] < 0) {
+ _field[fieldIdx] = -1;
+ } else {
+ _field[fieldIdx] = (_nextIdx + seg[ySeg + x]) % _numColors;
+ }
+ }
+ }
+ }
+}
=======================================
--- /src/common/spirals/RectangularSpiralAlgorithm.h Mon Mar 16 21:29:13
2009 UTC
+++ /src/common/spirals/RectangularSpiralAlgorithm.h Mon Apr 27 00:56:58
2009 UTC
@@ -27,6 +27,7 @@
*/
#include "utility/misc_funcs.h"
+#include "SpiralAlgorithm.h"
#ifndef __RECTANGULARSPIRALALGORITHM_H__
#define __RECTANGULARSPIRALALGORITHM_H__
@@ -38,10 +39,23 @@
public:
/**
- * Constructor.
+ * Default constructor.
*/
RectangularSpiralAlgorithm();
+ /**
+ * Constructor takes initialization parameters.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @param bRandomColor whether or not the initial color is randomly
selected.
+ * @param bIncrementColor whether to increment the color as it spirals
out.
+ * @see calc()
+ */
+ RectangularSpiralAlgorithm(const int colorWidth, const int emptyWidth,
+ const bool bConstantColor, const bool bRandomColor,
+ const bool bIncrementColor);
+
~RectangularSpiralAlgorithm();
/**
@@ -50,15 +64,9 @@
* @param screenWidth the width of the screen in pixels.
* @param screenHeight the height of the screen in pixels.
* @param numColors the number of colors in the palette primary
direction.
- * @param colorWidth the width of the strip of color.
- * @param emptyWidth the width of the default color region.
- * @param bConstantColor whether or not to hold the color index constant.
- * @param bRandomColor whether or not the initial color is randomly
selected.
- * @see calc()
*/
- void initialize(int* field, int screenWidth, int screenHeight,
- int numColors, int colorWidth, int emptyWidth,
- bool bConstantColor, bool bRandomColor);
+ void initialize(int* field, const int screenWidth, const int
screenHeight,
+ const int numColors);
/**
* Completes one iteration of the algorithm. Returns true if the
algorithm
@@ -81,21 +89,38 @@
*/
void calcSegments();
+ /**
+ * Rotates and draws the specified segment at (_currX,_currY) based
+ * on _dir.
+ * @param seg Must be either _cornerSeg or _straightSeg.
+ */
+ void drawSegment(int* seg);
+
+ int _colorWidth;
+ int _emptyWidth;
+ bool _bConstantColor;
+ bool _bRandomColor;
+ bool _bIncrementColor;
+
int _segmentSize;
int* _cornerSeg;
int* _straightSeg;
RectangularSpiralAlgorithmDir _dir;
bool _bClockwise;
- int _currX;
- int _currY;
+ float _currX;
+ float _currY;
int _nextIdx;
- bool _bXPositive; //> either current or next polarity
- bool _bYPositive; //> either current or next polarity
int _xSegs; //> either current or next number of segments
int _ySegs; //> either current or next number of segments
- int _remainingSegs;
+ int _remainingSegs; //> Segments remaining to draw.
+ int _xMaxSegs; //> Maximum number of segments in the x direction.
+ int _yMaxSegs; //> Maximum number of segments in the y direction.
+
+ // These are to speed up some calculations, since they only need done
once.
+ int _maxFieldIdx; //> _sizeX * _sizeY - 1;
+ float _halfSegSize; //> _segmentSize / 2.0
};
=======================================
--- /src/common/spirals/SpiralAlgorithm.cpp Mon Mar 16 21:29:13 2009 UTC
+++ /src/common/spirals/SpiralAlgorithm.cpp Mon Apr 27 00:56:58 2009 UTC
@@ -8,9 +8,6 @@
_width = 0;
_height = 0;
_numColors = 0;
- _colorWidth = 1;
- _emptyWidth = 0;
- _bConstantColor = false;
}
SpiralAlgorithm::~SpiralAlgorithm() {
@@ -24,18 +21,13 @@
* @param screenWidth the width of the screen in pixels.
* @param screenHeight the height of the screen in pixels.
* @param numColors the number of colors in the palette primary
direction.
- * @param colorWidth the width of the strip of color.
- * @param emptyWidth the width of the default color region.
- * @param bConstantColor whether or not to hold the color index constant.
- * @param bRandomColor whether or not the initial color is randomly
selected.
* @see calc()
*/
-void SpiralAlgorithm::initialize(int* field, int screenWidth, int
screenHeight,
- int numColors, int colorWidth, int emptyWidth,
- bool bConstantColor, bool bRandomColor) {
+void SpiralAlgorithm::initialize(int* field, const int screenWidth,
+ const int screenHeight,
+ const int numColors) {
- initializeBase(field, screenWidth, screenHeight, numColors, colorWidth,
- colorHeight, bConstantColor);
+ initializeBase(field, screenWidth, screenHeight, numColors);
}
/**
@@ -51,7 +43,7 @@
* Completes up to numIterations iterations of the algorithm. If N <= 0,
* the algorithm will continue until finished.
*/
-bool SpiralAlgorithm::calc(int numIterations) {
+bool SpiralAlgorithm::calc(const int numIterations) {
for(int i=0; i<numIterations; i++) {
if(calc())
return true;
@@ -72,26 +64,14 @@
* @param screenWidth the width of the screen in pixels.
* @param screenHeight the height of the screen in pixels.
* @param numColors the number of colors in the palette primary
direction.
- * @param colorWidth the width of the strip of color.
- * @param emptyWidth the width of the default color region.
- * @param bConstantColor whether or not to hold the color index constant.
* @see initialize()
*/
-void SpiralAlgorithm::initializeBase(int* field, int screenWidth,
- int screenHeight, int numColors,
- int colorWidth, int emptyWidth,
- bool bConstantColor) {
+void SpiralAlgorithm::initializeBase(int* field, const int screenWidth,
+ const int screenHeight,
+ const int numColors) {
_field = field;
_width = screenWidth;
_height = screenHeight;
_numColors = numColors;
- _colorWidth = colorWidth;
- _emptyWidth = emptyWidth;
- _bConstantColor = bConstantColor;
-
- if(_colorWidth < 0)
- _colorWidth = 0;
- if(_emptyWidth < 0)
- _emptyWidth = 0;
}
=======================================
--- /src/common/spirals/SpiralAlgorithm.h Mon Mar 16 21:29:13 2009 UTC
+++ /src/common/spirals/SpiralAlgorithm.h Mon Apr 27 00:56:58 2009 UTC
@@ -26,15 +26,16 @@
* This is the base class for the spiral algorithms.
*/
-/*
-#include <stdlib.h>
-#include <ctime>
-using namespace std;
-*/
-
#ifndef __SPIRALALGORITHM_H__
#define __SPIRALALGORITHM_H__
+#ifdef _M_IX86
+#include <windows.h>
+#else
+//#include <stream.h>
+#include <stdlib.h>
+#endif
+
class SpiralAlgorithm {
public:
@@ -52,15 +53,10 @@
* @param screenWidth the width of the screen in pixels.
* @param screenHeight the height of the screen in pixels.
* @param numColors the number of colors in the palette primary
direction.
- * @param colorWidth the width of the strip of color.
- * @param emptyWidth the width of the default color region.
- * @param bConstantColor whether or not to hold the color index constant.
- * @param bRandomColor whether or not the initial color is randomly
selected.
* @see calc()
*/
- virtual void initialize(int* field, int screenWidth, int screenHeight,
- int numColors, int colorWidth, int emptyWidth,
- bool bConstantColor, bool bRandomColor);
+ virtual void initialize(int* field, const int screenWidth,
+ const int screenHeight, const int numColors);
/**
* Completes one iteration of the algorithm. Returns true if the
algorithm
@@ -75,7 +71,7 @@
* @return true if the spiral generation is complete.
* @see calc();
*/
- bool calc(int numIterations);
+ bool calc(const int numIterations);
/**
* This is a convenience function that is the same as calling calc(-1).
@@ -90,21 +86,16 @@
* @param screenWidth the width of the screen in pixels.
* @param screenHeight the height of the screen in pixels.
* @param numColors the number of colors in the palette primary
direction.
- * @param colorWidth the width of the strip of color.
- * @param emptyWidth the width of the default color region.
- * @param bConstantColor whether or not to hold the color index constant.
+ * @param bIncrementColor whether the colors increment as they spiral
out.
* @see initialize()
*/
- void initialize(int* field, int screenWidth, int screenHeight,
- int numColors, int colorWidth, int emptyWidth,
- bool bConstantColor);
+ void initializeBase(int* field, const int screenWidth, const int
screenHeight,
+ const int numColors);
int _width;
int _height;
int _numColors;
- int _colorWidth;
- int _emptyWidth;
- bool _bConstantColor;
+ int* _field;
};
#endif
=======================================
--- /src/common/utility/misc_funcs.cpp Sun Jan 11 17:51:04 2009 UTC
+++ /src/common/utility/misc_funcs.cpp Mon Apr 27 00:56:58 2009 UTC
@@ -103,3 +103,16 @@
return Qt::Unchecked;
}
+/**
+ * Rounds a float to the nearest whole number and casts to integer.
+ */
+int roundFtoI(const float& val) {
+ return (val < 0.0) ? int(val-0.5) : int(val+0.5);
+}
+
+/**
+ * Rounds a double to the nearest whole number and casts to integer.
+ */
+int roundDtoI(const double& val) {
+ return (val < 0.0) ? int(val-0.5) : int(val+0.5);
+}
=======================================
--- /src/common/utility/misc_funcs.h Sun Jan 11 17:51:04 2009 UTC
+++ /src/common/utility/misc_funcs.h Mon Apr 27 00:56:58 2009 UTC
@@ -24,6 +24,8 @@
#include <QString>
+//#ifndef __MISC_FUNCS_H__
+//#define __MISC_FUNCS_H__
/**
* Returns a random integer just like rand() does, however it will
* periodically reseed the generator using the current time.
@@ -55,3 +57,19 @@
* Converts the specified bool to Qt::CheckState.
*/
extern Qt::CheckState boolToCheckState(bool bVal);
+
+/**
+ * Rounds a float to the nearest whole number and casts to integer.
+ */
+extern int roundFtoI(const float& val);/* {
+ return (val < 0.0) ? int(val-0.5) : int(val+0.5);
+ }*/
+
+/**
+ * Rounds a double to the nearest whole number and casts to integer.
+ */
+extern int roundDtoI(const double& val);/* {
+ return (val < 0.0) ? int(val-0.5) : int(val+0.5);
+ }*/
+
+//#endif
==============================================================================
Revision: 55534db500ba
Author: Jeff Backus <
jeff....@gmail.com>
Date: Mon Apr 27 21:19:22 2009 UTC
Log: Added Point2D and Vector2D classes. Have not been tested! Need
to also
create unit tests for them. Which means creating a structure for unit
tests.
Should use Qt's unit test framework (one less set of libraries to install).
http://code.google.com/p/idlescreen/source/detail?r=55534db500ba
Added:
/src/common/utility/Point2D.cpp
/src/common/utility/Point2D.h
/src/common/utility/Vector2D.cpp
/src/common/utility/Vector2D.h
=======================================
--- /dev/null
+++ /src/common/utility/Point2D.cpp Mon Apr 27 21:19:22 2009 UTC
@@ -0,0 +1,79 @@
+/**
+ * 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) {
+ _x = x;
+ _y = y;
+}
+
+/**
+ * Deconstructor
+ */
+Point2D::~Point2D() {
+}
+
+/**
+ * Gets the x value.
+ */
+double Point2D::getX() {
+ return _x;
+}
+/**
+ * Sets the x value.
+ */
+void Point2D::setX(const double x=0.0) {
+ _x = x;
+}
+
+/**
+ * Gets the y value.
+ */
+double Point2D::getY() {
+ return _y;
+}
+/**
+ * Sets the y value.
+ */
+void Point2D::setY(const double y=0.0) {
+ _y = y;
+}
+
+Point2D& Point2D::operator=(const Point2D& other) {
+ // no need to check for self-assignment, since we're not
+ // allocating/deallocating memory.
+ _x = other._x;
+ _y = other._y;
+
+ return *this;
+}
+Point2D& Point2D::operator==(const Point2D& other) {
+ return (_x == other._x && _y == other._y);
+}
+Point2D& Point2D::operator!=(const Point2D& other) {
+ return !(*this == other);
+}
+Point2D& Point2D::operator*(const double val) {
+ Point2D retVal = *this;
+ retVal *= val;
+ return retVal;
+}
+Point2D& Point2D::operator/(const double val) {
+ Point2D retVal = *this;
+ retVal /= val;
+ return retVal;
+}
+Point2D& Point2D::operator*=(const double val) {
+ Point2D retVal = *this;
+ retVal._x *= val;
+ retVal._y *= val;
+ return retVal;
+}
+Point2D& Point2D::operator/=(const double val) {
+ Point2D retVal = *this;
+ retVal._x /= val;
+ retVal._y /= val;
+ return retVal;
+}
=======================================
--- /dev/null
+++ /src/common/utility/Point2D.h Mon Apr 27 21:19:22 2009 UTC
@@ -0,0 +1,99 @@
+/**
+ * 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 class represents a generic point in two dimensions. All internal
+ * values are stored as doubles.
+ */
+
+#include <iostream>
+#include <meth.h>
+
+using namespace std;
+
+#include "misc_funcs.h"
+
+#ifndef __POINT2D_H__
+#define __POINT2D_H__
+
+class Point2D {
+
+ public:
+
+ /**
+ * Constructor.
+ *
+ * @param x The initial x value of the vector.
+ * @param y The initial y value of the vector.
+ */
+ Point2D(const double x=0.0, const double y=0.0);
+
+ /**
+ * Deconstructor
+ */
+ ~Point2D();
+
+ /**
+ * Gets the x value.
+ */
+ double getX();
+ /**
+ * Sets the x value.
+ */
+ void setX(const double x=0.0);
+
+ /**
+ * Gets the y value.
+ */
+ double getY();
+ /**
+ * Sets the y value.
+ */
+ void setY(const double y=0.0);
+
+ Point2D& operator=(const Point2D& other);
+ Point2D& operator==(const Point2D& other);
+ Point2D& 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);
+
+ 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
=======================================
--- /dev/null
+++ /src/common/utility/Vector2D.cpp Mon Apr 27 21:19:22 2009 UTC
@@ -0,0 +1,239 @@
+
+#include "Vector2D.h"
+
+/**
+ * Constructor.
+ *
+ * @param x The initial x value of the vector.
+ * @param y The initial y value of the vector.
+ */
+Vector2D::Vector2D(const double x=0.0, const double y=0.0) {
+ _x = x;
+ _y = y;
+ _bIsNormalized = false;
+}
+
+/**
+ * Deconstructor
+ */
+Vector2D::~Vector2D() {
+}
+
+/**
+ * Gets the x value.
+ */
+double Vector2D::getX() {
+ return _x;
+}
+/**
+ * Sets the x value.
+ */
+void Vector2D::setX(const double x=0.0) {
+ _x = x;
+ _bIsNormalized = false;
+}
+
+/**
+ * Gets the y value.
+ */
+double Vector2D::getY() {
+ return _y;
+}
+/**
+ * Sets the y value.
+ */
+void Vector2D::setY(const double y=0.0) {
+ _y = y;
+ _bIsNormalized = false;
+}
+
+/**
+ * Gets the magnitude of the vector.
+ */
+double Vector2D::magnitude() {
+ if(_bIsNormalized) {
+ return 1.0;
+ } else {
+ return sqrt(_x*_x+_y*_y);
+ }
+}
+
+/**
+ * Gets the normal of this vector.
+ */
+Vector2D Vector2D::getNormal() {
+ Vector2D retVal;
+ // 2D case is easy!
+ retVal._x = -1.0*_y;
+ retVal._y = _x;
+
+ retVal.normalize();
+
+ return retVal;
+}
+
+/**
+ * Normalizes this vector.
+ */
+void Vector2D::normalize() {
+ if(!_bIsNormalized) {
+ double mag = magnitude();
+ _x = _x/mag;
+ _y = _y/mag;
+ _bIsNormalized = true;
+ }
+}
+
+/**
+ * Returns true if the specified vector is parallel to this vector.
+ */
+bool Vector2D::isParallelTo(const Vector2D other) {
+ Vector2D thisUnitV = *this;
+ Vector2D otherUnitV = other;
+ thisUnitV.normalize();
+ otherUnitV.normalize();
+
+ return
+ ( (thisUnitV._x == otherUnitV._x || thisUnitV._x ==
-1.0*otherUnitV._x) &&
+ (thisUnitV._y == otherUnitV._y || thisUnitV._y ==
-1.0*otherUnitV._y) );
+}
+
+/**
+ * Returns true if the specified vector is normal to this vector.
+ */
+bool Vector2D::isNormalTo(const Vector2D other) {
+ Vector2D otherNormV = other.getNormal();
+
+ return isParallel(otherNormV);
+}
+
+/**
+ * Returns the dot product of the specified vector with this vector.
+ */
+double Vector2D::dot(const Vector2D other) {
+ return (_x*other._x+_y*other._y);
+}
+
+/**
+ * Calculates the angle between the specified vector and this vector.
+ * Note: returns a value between [0, pi] or NaN if values are invalid.
+ */
+double Vector2D::getAngle(const Vector2D other) {
+
+ // we know that mag(v1)*mag(v2)*cos(theta)=normal(v1) dot v2
+ // thus theta = arccos( (normal(v1) dot v2) / ( mag(v1)*mag(v2) ) )
+ Vector2D norm = getNormal();
+ Vector2D otherUnitV = other;
+ otherUnitV.normalize(); // dealing with normal vectors makes the math
easy.
+
+ return acos(norm.dot(otherUnitV));
+}
+
+/**
+ * Checks to see if point B is on the line specified
+ * by this vector and point A.
+ *
+ * @param a A point known to be on the line.
+ * @param b The point to check.
+ */
+bool Vector2D::isOnLine(const Point2D a, const point2D b) {
+ // If the vector from point B to point A is parallel to vector V, then
+ // point B is on the line.
+ Vector2D v2 = b - a;
+ return isParallel(v2);
+}
+
+/**
+ * Finds the point of intersection of the line specified
+ * by this vector and point A and the line specified by
+ * vector V2 and point B. Returns false if the lines
+ * do not intersect. The resulting point is put into result.
+ * If result is NULL, the point will not be returned, but the
+ * function will still return true if the lines intersect or
+ * false if they do not.
+ *
+ * @param pA A point on the line specified by this vector.
+ * @param vB The vector describing the other line.
+ * @param pB A point on the line described by vector v.
+ * @param result The resulting point.
+ * @return True if the lines intersect, false if they do not.
+ */
+bool Vector2D::getIntersectingPt(const Point2D pA, const Vector2D vB,
+ const Point2D pB, Vector2D* result) {
+
+ double numer = vB._x*(pB.getY() - pA.getY()) -
+ vB._y*(pB.getX() - pA.getX());
+ double denom = vB._y*_x - vB._x*_y;
+ if(denom != 0) {
+ if(result != NULL) {
+ Vector2D vF = (*this) * (numer / denom);
+ result = pA + vF;
+ }
+ }
+ return false;
+}
+
+Vector2D& Vector2D::operator=(const Vector2D& other) {
+ // no need to check for self-assignment, since we're not
+ // allocating/deallocating memory.
+ _x = other._x;
+ _y = other._y;
+ _bIsNormalized = other._bIsNormalized;
+
+ return *this;
+}
+Vector2D& Vector2D::operator+(const Vector2D& other) {
+ Vector2D retVal = *this;
+ retVal += other;
+ return retVal;
+}
+Vector2D& Vector2D::operator*(const double val) {
+ Vector2D retVal = *this;
+ retVal *= val;
+ return retVal;
+}
+Vector2D& Vector2D::operator*(const double val, Vector2D& v) {
+ return v*val;
+}
+Vector2D& Vector2D::operator/(const double val) {
+ Vector2D retVal = *this;
+ retVal /= val;
+ return retVal;
+}
+Vector2D& Vector2D::operator+=(const Vector2D& other) {
+ Vector2D retVal = *this;
+ retVal._x += other._x;
+ retVal._y += other._y;
+ retVal._bIsNormalized = false;
+ return retVal;
+}
+Vector2D& Vector2D::operator*=(const double val) {
+ Vector2D retVal = *this;
+ retVal._x *= val;
+ retVal._y *= val;
+ retVal._bIsNormalized = false;
+ return retVal;
+}
+Vector2D& Vector2D::operator/=(const double val) {
+ Vector2D retVal = *this;
+ retVal *= (1.0/val);
+ return retVal;
+}
+Vector2D& Vector2D::operator==(const Vector2D& other) {
+ return (_x == other._x && _y == other._y);
+}
+Vector2D& Vector2D::operator!=(const Vector2D& other) {
+ return !(*this == other);
+
+}
+Vector2D& Vector2D::operator-=(const Vector2D& other) {
+ Vector2D otherInv = other * -1.0;
+ Vector2D retVal = *this;
+ retVal += otherInv;
+ return retVal;
+}
+Vector2D& Vector2D::operator-(const Vector2D& other) {
+ Vector2D retVal = *this;
+ retVal -= other;
+ return retVal;
+}
=======================================
--- /dev/null
+++ /src/common/utility/Vector2D.h Mon Apr 27 21:19:22 2009 UTC
@@ -0,0 +1,188 @@
+/**
+ * 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 class represents a generic vector in two dimensions. All internal
+ * values are stored as doubles.
+ */
+
+#include <iostream>
+#include <math.h>
+
+using namespace std;
+
+#include "misc_funcs.h"
+#include "Point2D.h"
+
+#ifndef __VECTOR2D_H__
+#define __VECTOR2D_H__
+
+class Vector2D {
+
+ public:
+
+ /**
+ * Constructor.
+ *
+ * @param x The initial x value of the vector.
+ * @param y The initial y value of the vector.
+ */
+ Vector2D(const double x=0.0, const double y=0.0);
+
+ /**
+ * Deconstructor
+ */
+ ~Vector2D();
+
+ /**
+ * Gets the x value.
+ */
+ double getX();
+ /**
+ * Sets the x value.
+ */
+ void setX(const double x=0.0);
+ /**
+ * Gets the y value.
+ */
+ double getY();
+
+
+ /**
+ * Sets the y value.
+ */
+ void setY(const double y=0.0);
+
+ /**
+ * Gets the magnitude of the vector.
+ */
+ double magnitude();
+
+ /**
+ * Gets the normal of this vector.
+ */
+ Vector2D getNormal();
+
+ /**
+ * Normalizes this vector.
+ */
+ void normalize();
+
+ /**
+ * Returns true if the specified vector is parallel to this vector.
+ */
+ bool isParallelTo(const Vector2D other);
+
+ /**
+ * Returns true if the specified vector is normal to this vector.
+ */
+ bool isNormalTo(const Vector2D other);
+
+ /**
+ * Returns the dot product of the specified vector with this vector.
+ */
+ double dot(const Vector2D other);
+
+ /**
+ * Calculates the angle between the specified vector and this vector.
+ */
+ double getAngle(const Vector2D other);
+
+ /**
+ * Checks to see if point B is on the line specified
+ * by this vector and point A.
+ *
+ * @param a A point known to be on the line.
+ * @param b The point to check.
+ */
+ bool isOnLine(const Point2D a, const point2D b);
+
+ /**
+ * Finds the point of intersection of the line specified
+ * by this vector and point A and the line specified by
+ * vector V2 and point B. Returns false if the lines
+ * do not intersect. The resulting point is put into result.
+ *
+ * @param a A point on the line specified by this vector.
+ * @param v2 The vector describing the other line.
+ * @param b A point on the line described by vector v.
+ * @param result The resulting point.
+ * @return True if the lines intersect, false if they do not.
+ */
+ bool getIntersectingPt(const Point2D pA, const Vector2D vB,
+ const Point2D pB, Vector2D* result);
+
+ Vector2D& operator=(const Vector2D& other);
+ Vector2D& operator+(const Vector2D& other);
+ Vector2D& operator*(const double val);
+ Vector2D& operator*(const double val, Vector2D& v);
+ Vector2D& operator/(const double val);
+ Vector2D& operator+=(const Vector2D& other);
+ Vector2D& operator*=(const double val);
+ Vector2D& operator/=(const double val);
+ Vector2D& operator==(const Vector2D& other);
+ Vector2D& operator!=(const Vector2D& other);
+ Vector2D& operator-=(const Vector2D& other);
+ Vector2D& operator-(const Vector2D& other);
+
+ private:
+ double _x;
+ double _y;
+
+ bool _bIsNormalized; //!< cuts down on excess calculations.
+};
+
+// **** Begin Friend definitions ****
+
+/**
+ * friend vector to dump to an ostream
+ */
+friend ostream& operator<<(ostream& os, const Vector2D& vector) {
+ os<<"("<<vector.getX()<<","<<vector.getY()<<")";
+ return os;
+}
+
+/**
+ * point subtraction results in a vector
+ */
+friend Vector2D& operator-(const Point2D& initial, const Point2D& final) {
+ double x = final.getX() - initial.getX();
+ double y = final.getY() - initial.getY();
+ Vector2D retVal(x, y);
+ return retVal;
+}
+
+/**
+ * A point plus a vector results in a new point.
+ */
+friend Point2D& operator+(const Point2D& p, const Vector2D& v) {
+ Point2D retVal;
+ retVal.setX(p.getX()+v.getX());
+ retVal.setY(p.getY()+v.getY());
+}
+friend Point2D& operator+(const Vector2D& v, const Point2D& p) {
+ return p+v;
+}
+
+#endif
==============================================================================
Revision: 87af136e877d
Author: Jeff Backus <
jeff....@gmail.com>
Date: Sun Aug 2 18:49:07 2009 UTC
Log: Still working on SpiralLenz. Won't compile yet. Committing so
that it is
easy to transfer to another machine. Also, fixed the bug in the Makefile
that
was fixed on /trunk in r206.
http://code.google.com/p/idlescreen/source/detail?r=87af136e877d
Added:
/src/SpiralLenz/src/SpiralBackgroundProfileWidget.h
/src/common/spirals/PolarSpiralAlgorithm.cpp
/src/common/spirals/PolarSpiralAlgorithm.h
Modified:
/Makefile.in
/src/SpiralLenz/project_files/SpiralLenz_glut.pro
/src/SpiralLenz/resource_files/defaults.xml
/src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp
/src/common/spirals/NgonSpiralAlgorithm.cpp
/src/common/spirals/NgonSpiralAlgorithm.h
/src/common/spirals/SpiralAlgorithm.cpp
/src/common/spirals/SpiralAlgorithm.h
=======================================
--- /dev/null
+++ /src/SpiralLenz/src/SpiralBackgroundProfileWidget.h Sun Aug 2 18:49:07
2009 UTC
@@ -0,0 +1,53 @@
+/**
+ * Copyright (c) 2008 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 class represents the configuration widget panels for the different
+ * spiral styles. Each profile is responsible for generating an
appropriate
+ * layout for this panel.
+ *
+ * @author jeff backus
+ * @date 04/03/2009
+ */
+
+#ifndef __SPIRALBACKGROUNDPROFILEWIDGET_H__
+#define __SPIRALBACKGROUNDPROFILEWIDGET_H__
+
+#include <QString>
+#include <QtXml/QDomNode>
+#include <QtXml/QDomDocument>
+#include <QWidget>
+
+#include "SpiralBackgroundProfile.h"
+
+class SpiralBackgroundProfileWidget : public QWidget {
+ Q_OBJECT
+
+public:
+ //constructor & destructor
+ ConfigWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
+ ~ConfigWidget();
+ private:
+
+};
=======================================
--- /dev/null
+++ /src/common/spirals/PolarSpiralAlgorithm.cpp Sun Aug 2 18:49:07 2009
UTC
@@ -0,0 +1,250 @@
+
+// debug
+#include <iostream>
+// end debug
+#include <math.h>
+using namespace std;
+
+#include "PolarSpiralAlgorithm.h"
+
+/**
+ * Constructor.
+ */
+PolarSpiralAlgorithm::PolarSpiralAlgorithm() {
+
+ // parameters
+ _colorWidth = 1;
+ _emptyWidth = 0;
+ _bConstantColor = true;
+ _bRandomColor = false;
+ _bIncrementColor = true;
+
+ // internals
+ _nextIdx = 0;
+ _currX = 0.0;
+ _currY = 0.0;
+ _rCoeff = 0.0;
+ _currR = 0.0;
+ _currTheta = 0.0;
+ _maxR = 0.0;
+
+ // misc constants
+ _maxFieldIdx = 0;
+ _screenXOffset = 0;
+ _screenYOffset = 0;
+}
+
+ /**
+ * Constructor takes initialization parameters.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @param bRandomColor whether or not the initial color is randomly
selected.
+ * @param bIncrementColor whether to increment the color as it spirals
out.
+ * @see calc()
+ */
+PolarSpiralAlgorithm::PolarSpiralAlgorithm(const int colorWidth,
+ const int emptyWidth,
+ const bool bConstantColor,
+ const bool bRandomColor,
+ const bool bIncrementColor) {
+
+ // empty constants until initialize(...) is called
+ _maxFieldIdx = 0;
+ _screenXOffset = 0;
+ _screenYOffset = 0;
+ _maxR = 0.0;
+
+ // initial values for internals
+ _nextIdx = 0;
+ _currX = 0.0;
+ _currY = 0.0;
+
+ // set parameters
+ _colorWidth = colorWidth;
+ _emptyWidth = emptyWidth;
+ _bConstantColor = bConstantColor;
+ _bRandomColor = bRandomColor;
+ _bIncrementColor = bIncrementColor;
+
+ if(_colorWidth < 0)
+ _colorWidth = 0;
+ if(_emptyWidth < 0)
+ _emptyWidth = 0;
+
+ // calculate misc constants
+ _segmentWidth = _colorWidth + (_emptyWidth<<1);
+
+ // calculate spiral constants and initial values
+ _rCoeff = double(_segmentWidth)/(2.0*SPIRALALGORITHM_PI);
+ _rCoeff *= (jrand() % 2 == 0) ? 1.0 : -1.0; // whether clockwise or not.
+ _currR = 0.0;
+
+ // for now, just start at 0.
+ _currTheta = 0.0;
+ _lastThetaStep = SPIRALALGORITHM_PI/16.0;
+
+}
+
+
+PolarSpiralAlgorithm::~PolarSpiralAlgorithm() {
+}
+
+/**
+ * Initializes the algorithm. Doesn't perform any actual generation.
+ * @param field The array of integers in which to generate the spiral
field.
+ * @param screenWidth the width of the screen in pixels.
+ * @param screenHeight the height of the screen in pixels.
+ * @param numColors the number of colors in the palette primary direction.
+ */
+void PolarSpiralAlgorithm::initialize(int* field, const int screenWidth,
+ const int screenHeight,
+ const int numColors) {
+ initializeBase(field, screenWidth, screenHeight, numColors);
+
+ if(_height <= 0)
+ return;
+ if(_width <= 0)
+ return;
+ if(_numColors <= 0)
+ return;
+
+ // calculate remaining internal constants
+ _maxFieldIdx = screenWidth * screenHeight - 1;
+ _screenXOffset = screenWidth>>1;
+ _screenYOffset = screenHeight>>1;
+
+ // calculate polar stopping condition.
+ _maxR = sqrt( _screenXOffset*_screenXOffset +
+ _screenYOffset*_screenYOffset);
+ if(_rCoeff < 0.0) {
+ _maxR *= -1.0;
+ }
+
+ // pick initial color
+ if(_bRandomColor) {
+ _nextIdx = jrand() % numColors;
+ } else {
+ _nextIdx = 0;
+ }
+
+ // begin debug
+ _stepCount = 128; //16;
+ // end debug
+
+}
+
+/**
+ * Completes one iteration of the algorithm. Returns true if the algorithm
+ * is completed.
+ */
+bool PolarSpiralAlgorithm::calc() {
+ if(_field == NULL)
+ return true;
+
+ if(_stepCount < 0)
+ return true;
+ //_stepCount--;
+
+ bool retVal = calcSpiral();
+
+ // set pixel to next color, if it is within the boundaries.
+ int px = roundDtoI(_currX)+_screenXOffset;
+ int py = roundDtoI(_currY)+_screenYOffset;
+ int fieldIdx = px+py*_width;
+ if(0 <= px && px < _width && 0 <= py && py < _height &&
+ fieldIdx < _maxFieldIdx) {
+ _field[fieldIdx] = _nextIdx;
+ }
+
+ // update color
+ if(!_bConstantColor) {
+ if(_bIncrementColor) {
+ _nextIdx = (_nextIdx+1)%_numColors;
+ } else {
+ _nextIdx = _nextIdx - 1;
+ if(_nextIdx < 0) {
+ _nextIdx = _numColors - _nextIdx;
+ }
+ }
+ }
+
+ return retVal;
+}
+
+/**
+ * Calculates a new X,Y using a polar spiral. Utilizes an adaptive
+ * algorithm to adjust thetaStep such that the new (x,y) value will
+ * be adjacent but not on the previous (x,y) value.
+ *
+ * @return True if the calculation is complete.
+ */
+bool PolarSpiralAlgorithm::calcSpiral() {
+ //cout<<"Entering calcSpiral"<<endl;
+ double newX;
+ double newY;
+ double newR;
+ double newTheta;
+ double newThetaStep = _lastThetaStep;
+
+ int iOldX = roundDtoI(_currX);
+ int iOldY = roundDtoI(_currY);
+ int iNewX;
+ int iNewY;
+
+ int escape_count = 0;
+ bool bDone = false;
+ while(!bDone) {
+ // update Theta
+ newTheta = _currTheta + newThetaStep;
+
+ // calculate the new R, X and Y
+ newR = _rCoeff * newTheta;
+ newX = newR * cos(newTheta);
+ newY = newR * sin(newTheta);
+
+ // check to see if we've calculated for an adjacent pixel
+ iNewX = roundDtoI(newX);
+ iNewY = roundDtoI(newY);
+ /*
+ cout<<"newX: "<<newX<<","<<iNewX<<endl;
+ cout<<"newY: "<<newY<<","<<iNewY<<endl;
+ cout<<"oldX: "<<*x<<","<<iOldX<<endl;
+ cout<<"oldY: "<<*y<<","<<iOldY<<endl;
+ */
+
+ bDone = true;
+ if(iNewX == iOldX && iNewY == iOldY) {
+ // theta too small
+ newThetaStep*=2.0;
+ bDone = false;
+ } else if(iNewX <= iOldX-2 || iOldX+2 <= iNewX ||
+ iNewY <= iOldY-2 || iOldY+2 <= iNewY) {
+ // theta too large
+ newThetaStep*=0.5;
+ bDone = false;
+ }
+
+ if(++escape_count >= 100) {
+ /*
+ cout<<"PolarSpiralAlgorithm::calcSpiral() Escape count
reached!"<<endl;
+ cout<<"maxR: "<<_maxR<<endl;
+ */
+ //exit(1);
+ //*r = _maxR+1.0;
+ _maxR = -1;
+ bDone = true;
+ }
+ }
+
+ // !!! NOTE NEED TO ADD IN CODE TO HANDLE _colorWidth
+
+ // send out values.
+ _currX = newX;
+ _currY = newY;
+ _currR = newR;
+ _currTheta = newTheta;
+ _lastThetaStep = newThetaStep;
+
+ return (_rCoeff < 0.0) ? (newR <= _maxR) : (newR >= _maxR);
+}
=======================================
--- /dev/null
+++ /src/common/spirals/PolarSpiralAlgorithm.h Sun Aug 2 18:49:07 2009 UTC
@@ -0,0 +1,113 @@
+/**
+ * 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 algorithm generates a polar spiral.
+ */
+
+#include "utility/misc_funcs.h"
+#include "SpiralAlgorithm.h"
+
+#ifndef __POLARSPIRALALGORITHM_H__
+#define __POLARSPIRALALGORITHM_H__
+
+class PolarSpiralAlgorithm : public SpiralAlgorithm {
+
+ public:
+
+ /**
+ * Default constructor.
+ */
+ PolarSpiralAlgorithm();
+
+ /**
+ * Constructor takes initialization parameters.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @param bRandomColor whether or not the initial color is randomly
selected.
+ * @param bIncrementColor whether to increment the color as it spirals
out.
+ * @see calc()
+ */
+ PolarSpiralAlgorithm(const int colorWidth, const int emptyWidth,
+ const bool bConstantColor, const bool bRandomColor,
+ const bool bIncrementColor);
+
+ ~PolarSpiralAlgorithm();
+
+ /**
+ * Initializes the algorithm. Doesn't perform any actual generation.
+ * @param field The array of integers in which to generate the spiral
field.
+ * @param screenWidth the width of the screen in pixels.
+ * @param screenHeight the height of the screen in pixels.
+ * @param numColors the number of colors in the palette primary
direction.
+ */
+ void initialize(int* field, const int screenWidth,
+ const int screenHeight, const int numColors);
+
+ /**
+ * Completes one iteration of the algorithm. Returns true if the
algorithm
+ * is completed.
+ */
+ bool calc();
+
+ private:
+ /**
+ * Calculates a new X,Y using a polar spiral. Utilizes an adaptive
+ * algorithm to adjust thetaStep such that the new (x,y) value will
+ * be adjacent but not on the previous (x,y) value.
+ * @return True if the calculation is complete.
+ */
+ bool calcSpiral();
+
+ // begin parameters
+ int _colorWidth;
+ int _emptyWidth;
+ bool _bConstantColor;
+ bool _bRandomColor;
+ bool _bIncrementColor;
+ // end parameters
+
+ double _rCoeff; // accounts for clockwise/counterclockwise!
+ double _currR;
+ double _currTheta;
+ double _lastThetaStep;
+ double _maxR; //!< polar stopping condition
+
+ double _currX;
+ double _currY;
+ int _nextIdx;
+
+ // begin constants to speed up calculations
+ int _screenXOffset;
+ int _screenYOffset;
+ int _segmentWidth;
+ int _maxFieldIdx; //> _sizeX * _sizeY - 1;
+ // end constants
+
+ // begin debug
+ int _stepCount;
+};
+
+#endif
=======================================
--- /Makefile.in Mon Apr 27 00:56:58 2009 UTC
+++ /Makefile.in Sun Aug 2 18:49:07 2009 UTC
@@ -60,7 +60,7 @@
$(MAKE) -f Makefile.PlasmaLenz_scr
bin/PlasmaLenz_glut : src/PlasmaLenz/project_files/PlasmaLenz_glut.pro
- cd $(srcdir)src/PlasmaLenz/project_files/ && $(QMAKE) PlasmaLenz_glut.pro
\
+ cd $(srcdir)/src/PlasmaLenz/project_files/ && $(QMAKE)
PlasmaLenz_glut.pro \
-o Makefile.PlasmaLenz_glut && \
$(MAKE) -f Makefile.PlasmaLenz_glut
=======================================
--- /src/SpiralLenz/project_files/SpiralLenz_glut.pro Mon Apr 27 00:56:58
2009 UTC
+++ /src/SpiralLenz/project_files/SpiralLenz_glut.pro Sun Aug 2 18:49:07
2009 UTC
@@ -20,6 +20,7 @@
SOURCES += $$COMMON_PATH/spirals/SpiralAlgorithm.cpp
SOURCES += $$COMMON_PATH/spirals/RectangularSpiralAlgorithm.cpp
SOURCES += $$COMMON_PATH/spirals/NgonSpiralAlgorithm.cpp
+SOURCES += $$COMMON_PATH/spirals/PolarSpiralAlgorithm.cpp
SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPalette.cpp
SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialog.cpp
@@ -63,6 +64,7 @@
HEADERS += $$COMMON_PATH/spirals/SpiralAlgorithm.h
HEADERS += $$COMMON_PATH/spirals/RectangularSpiralAlgorithm.h
HEADERS += $$COMMON_PATH/spirals/NgonSpiralAlgorithm.h
+HEADERS += $$COMMON_PATH/spirals/PolarSpiralAlgorithm.h
HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPalette.h
HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteDialog.h
=======================================
--- /src/SpiralLenz/resource_files/defaults.xml Mon Apr 27 00:56:58 2009 UTC
+++ /src/SpiralLenz/resource_files/defaults.xml Sun Aug 2 18:49:07 2009 UTC
@@ -3,11 +3,16 @@
<BackgroundProfile>
<type>RectangularSpiralBackground</type>
<name>Classic RGB Profile</name>
- <steps_per_tick>2048</steps_per_tick>
+ <steps_per_tick>1024</steps_per_tick>
<anmiate_palette>true</anmiate_palette>
<palette_x_speed>1</palette_x_speed>
<palette_y_speed>1</palette_y_speed>
<palette>Classic RGB Palette</palette>
+ <color_width>1</color_width>
+ <empty_width>1</empty_width>
+ <constant_color>false</constant_color>
+ <random_color>false</random_color>
+ <increment_color>false</increment_color>
</BackgroundProfile>
<IndexedPaletteProfile>
<name>Classic RGB Palette</name>
@@ -98,7 +103,8 @@
</MasterProfile>
<random_master_profiles>false</random_master_profiles>
<gpl_accepted>false</gpl_accepted>
- <master_profile_history_size>3</master_profile_history_size>
+ <master_profile_history_size>0</master_profile_history_size>
+ <master_profile_history/>
<selected_master_profile_list>
<selected_entry>
<name>Classic RGB</name>
=======================================
--- /src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp Mon Apr 27
00:56:58 2009 UTC
+++ /src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp Sun Aug 2
18:49:07 2009 UTC
@@ -37,6 +37,7 @@
// begin tmp
#include "spirals/NgonSpiralAlgorithm.h"
+#include "spirals/PolarSpiralAlgorithm.h"
// end tmp
RectangularSpiralBackgroundProfile::RectangularSpiralBackgroundProfile() {
@@ -255,9 +256,14 @@
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,
=======================================
--- /src/common/spirals/NgonSpiralAlgorithm.cpp Mon Apr 27 00:56:58 2009 UTC
+++ /src/common/spirals/NgonSpiralAlgorithm.cpp Sun Aug 2 18:49:07 2009 UTC
@@ -120,6 +120,9 @@
// calculate polar stopping condition.
_maxR = sqrt( _screenXOffset*_screenXOffset +
_screenYOffset*_screenYOffset);
+ if(_rCoeff < 0.0) {
+ _maxR *= -1.0;
+ }
// pick initial color
if(_bRandomColor) {
@@ -142,7 +145,7 @@
if(_field == NULL)
return true;
- if(_stepCount < 0)
+ if(_stepCount < 0)
return true;
//_stepCount--;
// if N is valid, use the N-gon spiral calculations.
@@ -153,7 +156,6 @@
} else {
retVal = calcSpiral(&_currX, &_currY, &_currR, &_currTheta,
&_lastThetaStep);
- //retVal = (_currR >= _maxR);
}
// set pixel to next color, if it is within the boundaries.
@@ -240,19 +242,25 @@
}
if(++escape_count >= 100) {
+ /*
cout<<"NgonSpiralAlgorithm::calcSpiral() Escape count
reached!"<<endl;
cout<<"maxR: "<<_maxR<<endl;
+ */
//exit(1);
//*r = _maxR+1.0;
_maxR = -1;
bDone = true;
}
}
+
+ // !!! NOTE NEED TO ADD IN CODE TO HANDLE _colorWidth
+
+ // send out values.
*x = newX;
*y = newY;
*r = newR;
*theta = newTheta;
*thetaStep = newThetaStep;
- return (newR >= _maxR);
+ return (_rCoeff < 0.0) ? (newR <= _maxR) : (newR >= _maxR);
}
=======================================
--- /src/common/spirals/NgonSpiralAlgorithm.h Mon Apr 27 00:56:58 2009 UTC
+++ /src/common/spirals/NgonSpiralAlgorithm.h Sun Aug 2 18:49:07 2009 UTC
@@ -27,17 +27,13 @@
* spiral algorithm is used.
*/
+#include "utility/Vector2D.h"
#include "utility/misc_funcs.h"
#include "SpiralAlgorithm.h"
#ifndef __NGONSPIRALALGORITHM_H__
#define __NGONSPIRALALGORITHM_H__
-//enum NgonSpiralAlgorithmDir { UP=0, DOWN=1, LEFT=2, RIGHT=3 };
-
-#define NGONSPIRAL_PI 3.14159265f
-#define NGONSPIRAL_MAX_N 20
-
class NgonSpiralAlgorithm : public SpiralAlgorithm {
public:
@@ -94,27 +90,6 @@
bool calcSpiral(double* x, double* y, double* r, double* theta,
double* thetaStep);
- /**
- * Calculates both the corner and "straight away" segments.
- * These segments are _segmentSize x _segmentSize in size.
- * They are also oriented such that (0,0) is the bottom left corner.
- * _straightSeg is such that it flows from left to right, and
- * _cornerSeg is such that it flows from right to up if _bClockwise
- * is false, or right to down if _bClockwise is true. Note that in
- * either case, the color index offset has not been properly modulo'd
- * and should be done so after being added to the current color index,
- * if _bConstantColor is false. In the case where _bConstantColor is
- * true, the index offset will always be 0.
- */
- //void calcSegments();
-
- /**
- * Rotates and draws the specified segment at (_currX,_currY) based
- * on _dir.
- * @param seg Must be either _cornerSeg or _straightSeg.
- */
- //void drawSegment(int* seg);
-
// begin parameters
int _n;
int _colorWidth;
@@ -128,7 +103,7 @@
double _rCoeff; // accounts for clockwise/counterclockwise!
double _currR;
double _currTheta;
- double _lastThetaStep;
+ double _thetaStep;
double _maxR; //!< polar stopping condition
// end spiral specific
=======================================
--- /src/common/spirals/SpiralAlgorithm.cpp Mon Apr 27 00:56:58 2009 UTC
+++ /src/common/spirals/SpiralAlgorithm.cpp Sun Aug 2 18:49:07 2009 UTC
@@ -44,11 +44,21 @@
* the algorithm will continue until finished.
*/
bool SpiralAlgorithm::calc(const int numIterations) {
+
+ int i=0;
+ bool bDone = false;
+ while(i++<numIterations && !bDone) {
+ bDone = calc();
+ }
+
+ return bDone;
+ /*
for(int i=0; i<numIterations; i++) {
if(calc())
return true;
}
return false;
+ */
}
/**
=======================================
--- /src/common/spirals/SpiralAlgorithm.h Mon Apr 27 00:56:58 2009 UTC
+++ /src/common/spirals/SpiralAlgorithm.h Sun Aug 2 18:49:07 2009 UTC
@@ -36,6 +36,8 @@
#include <stdlib.h>
#endif
+#define SPIRALALGORITHM_PI 3.14159265f
+
class SpiralAlgorithm {
public:
==============================================================================
Revision: 9af23b015ecb
Author: Jeff Backus <
jeff....@gmail.com>
Date: Sun Feb 7 22:05:58 2010 UTC
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=9af23b015ecb
Added:
/src/common/unit_tests/
unit_tests.pro
/src/common/unit_tests/unit_tests_main.cpp
/src/common/utility/unit_tests/Test_Point2D.cpp
/src/common/utility/unit_tests/Test_Point2D.h
Modified:
/Makefile.in
/src/SpiralLenz/project_files/SpiralLenz_glut.pro
/src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp
/src/common/utility/Point2D.cpp
/src/common/utility/Point2D.h
=======================================
--- /dev/null
+++ /src/common/unit_tests/
unit_tests.pro Sun Feb 7 22:05:58 2010 UTC
@@ -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
+++ /src/common/unit_tests/unit_tests_main.cpp Sun Feb 7 22:05:58 2010 UTC
@@ -0,0 +1,4 @@
+#include <QtTest/QtTest>
+#include "utility/unit_tests/Test_Point2D.h"
+
+QTEST_MAIN(Test_Point2D)
=======================================
--- /dev/null
+++ /src/common/utility/unit_tests/Test_Point2D.cpp Sun Feb 7 22:05:58
2010 UTC
@@ -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
+++ /src/common/utility/unit_tests/Test_Point2D.h Sun Feb 7 22:05:58 2010
UTC
@@ -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
=======================================
--- /Makefile.in Sun Aug 2 18:49:07 2009 UTC
+++ /Makefile.in Sun Feb 7 22:05:58 2010 UTC
@@ -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
=======================================
--- /src/SpiralLenz/project_files/SpiralLenz_glut.pro Sun Aug 2 18:49:07
2009 UTC
+++ /src/SpiralLenz/project_files/SpiralLenz_glut.pro Sun Feb 7 22:05:58
2010 UTC
@@ -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
=======================================
--- /src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp Sun Aug 2
18:49:07 2009 UTC
+++ /src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp Sun Feb 7
22:05:58 2010 UTC
@@ -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;
=======================================
--- /src/common/utility/Point2D.cpp Mon Apr 27 21:19:22 2009 UTC
+++ /src/common/utility/Point2D.cpp Sun Feb 7 22:05:58 2010 UTC
@@ -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;
}
=======================================
--- /src/common/utility/Point2D.h Mon Apr 27 21:19:22 2009 UTC
+++ /src/common/utility/Point2D.h Sun Feb 7 22:05:58 2010 UTC
@@ -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
==============================================================================
Revision: 3cfa3b6e29b2
Author: Jeff Backus <
jeff....@gmail.com>
Date: Mon Feb 8 02:40:30 2010 UTC
Log: Added unit tests for misc_funcs & Vector2D, but the still need a
lot of work.
Added a function to improve comparing floats/doubles with a variable
precision.
Rewrote the unit test main function to iterate through a QList of test
classes.
http://code.google.com/p/idlescreen/source/detail?r=3cfa3b6e29b2
Added:
/src/common/utility/unit_tests/Test_MiscFuncs.cpp
/src/common/utility/unit_tests/Test_MiscFuncs.h
/src/common/utility/unit_tests/Test_Vector2D.cpp
/src/common/utility/unit_tests/Test_Vector2D.h
Modified:
/src/common/unit_tests/
unit_tests.pro
/src/common/unit_tests/unit_tests_main.cpp
/src/common/utility/Point2D.cpp
/src/common/utility/Point2D.h
/src/common/utility/Vector2D.cpp
/src/common/utility/Vector2D.h
/src/common/utility/misc_funcs.cpp
/src/common/utility/misc_funcs.h
/src/common/utility/unit_tests/Test_Point2D.cpp
/src/common/utility/unit_tests/Test_Point2D.h
=======================================
--- /dev/null
+++ /src/common/utility/unit_tests/Test_MiscFuncs.cpp Mon Feb 8 02:40:30
2010 UTC
@@ -0,0 +1,81 @@
+/**
+ * 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_MiscFuncs.h"
+
+void Test_MiscFuncs::Test_Jrand() {
+ QFAIL("Not implemented yet!");
+}
+void Test_MiscFuncs::Test_BoolToString() {
+ QFAIL("Not implemented yet!");
+}
+void Test_MiscFuncs::Test_StringToBool() {
+ QFAIL("Not implemented yet!");
+}
+void Test_MiscFuncs::Test_DotProduct() {
+ QFAIL("Not implemented yet!");
+}
+void Test_MiscFuncs::Test_RandStr() {
+ QFAIL("Not implemented yet!");
+}
+void Test_MiscFuncs::Test_BoolToCheckState() {
+ QFAIL("Not implemented yet!");
+}
+void Test_MiscFuncs::Test_RoundFToI() {
+ QFAIL("Not implemented yet!");
+}
+void Test_MiscFuncs::Test_RoundDToI() {
+ QFAIL("Not implemented yet!");
+}
+void Test_MiscFuncs::Test_RelativeCompareF() {
+ QFAIL("Not implemented yet!");
+}
+void Test_MiscFuncs::Test_RelativeCompareD() {
+ QFAIL("Not implemented yet!");
+}
+
+/*
+void Test_MiscFuncs::Test_GetSetX() {
+ MiscFuncs 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);
+}
+*/
=======================================
--- /dev/null
+++ /src/common/utility/unit_tests/Test_MiscFuncs.h Mon Feb 8 02:40:30
2010 UTC
@@ -0,0 +1,53 @@
+/**
+ * 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 the functions in misc_funcs.
+ */
+
+#ifndef __TEST_MISC_FUNCS_H__
+#define __TEST_MISC_FUNCS_H__
+
+#include <QtTest/QtTest>
+#include "../misc_funcs.h"
+
+class Test_MiscFuncs: public QObject {
+ Q_OBJECT
+
+ private slots:
+ void Test_Jrand();
+ void Test_BoolToString();
+ void Test_StringToBool();
+ void Test_DotProduct();
+ void Test_RandStr();
+ void Test_BoolToCheckState();
+ void Test_RoundFToI();
+ void Test_RoundDToI();
+ void Test_RelativeCompareF();
+ void Test_RelativeCompareD();
+
+ private:
+};
+
+#endif
=======================================
--- /dev/null
+++ /src/common/utility/unit_tests/Test_Vector2D.cpp Mon Feb 8 02:40:30
2010 UTC
@@ -0,0 +1,646 @@
+/**
+ * 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_Vector2D.h"
+
+void Test_Vector2D::Test_GetSetX() {
+ Vector2D testVector;
+
+ // set to a positive number
+ testVector.setX(5.1);
+ QVERIFY(testVector.getX() == 5.1);
+ QVERIFY(testVector.getY() == 0.0);
+
+ // set to default
+ testVector.setX();
+ QVERIFY(testVector.getX() == 0.0);
+ QVERIFY(testVector.getY() == 0.0);
+
+ // set to a negative number
+ testVector.setX(-1000.4);
+ QVERIFY(testVector.getX() == -1000.4);
+ QVERIFY(testVector.getY() == 0.0);
+}
+
+void Test_Vector2D::Test_GetSetY() {
+ Vector2D testVector;
+
+ // set to a positive number
+ testVector.setY(7.2);
+ QVERIFY(testVector.getX() == 0.0);
+ QVERIFY(testVector.getY() == 7.2);
+
+ // set to default
+ testVector.setY();
+ QVERIFY(testVector.getX() == 0.0);
+ QVERIFY(testVector.getY() == 0.0);
+
+ // set to a negative number
+ testVector.setY(-1413.9);
+ QVERIFY(testVector.getX() == 0.0);
+ QVERIFY(testVector.getY() == -1413.9);
+}
+
+void Test_Vector2D::Test_SetValue() {
+ Vector2D testVector;
+ double xVal;
+ double yVal;
+
+ // set to positive numbers
+ xVal = 12.19;
+ yVal = 0.194;
+ testVector.setValue(xVal,yVal);
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // set to default
+ testVector.setValue();
+ QVERIFY(testVector.getX() == 0.0);
+ QVERIFY(testVector.getY() == 0.0);
+
+ // set to a negative number
+ xVal = -0.294;
+ yVal = -194.109;
+ testVector.setValue(xVal,yVal);
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+}
+
+void Test_Vector2D::Test_Constructor() {
+ // set to positive numbers
+ Vector2D testVectorA(5.4,7.2);
+ QVERIFY(testVectorA.getX() == 5.4);
+ QVERIFY(testVectorA.getY() == 7.2);
+
+ // set to default
+ Vector2D testVectorB;
+ QVERIFY(testVectorB.getX() == 0.0);
+ QVERIFY(testVectorB.getY() == 0.0);
+
+ // set to a negative number
+ Vector2D testVectorC(-5923.1,-21734.1);
+ QVERIFY(testVectorC.getX() == -5923.1);
+ QVERIFY(testVectorC.getY() == -21734.1);
+}
+void Test_Vector2D::Test_Magnitude() {
+ double xVal;
+ double yVal;
+
+ // both positive numbers
+ xVal = 1.92;
+ yVal = 0.32;
+ Vector2D testVectorA(xVal, yVal);
+ // we are assuming that the math function sqrt is ok...
+ QVERIFY(testVectorA.magnitude() == sqrt(xVal*xVal+yVal*yVal));
+
+ // x pos, y neg numbers
+ xVal = 274.13;
+ yVal = -192.68;
+ Vector2D testVectorB(xVal, yVal);
+ // we are assuming that the math function sqrt is ok...
+ QVERIFY(testVectorB.magnitude() == sqrt(xVal*xVal+yVal*yVal));
+
+ // x neg, y pos numbers
+ xVal = -0.719;
+ yVal = 1.768;
+ Vector2D testVectorC(xVal, yVal);
+ // we are assuming that the math function sqrt is ok...
+ QVERIFY(testVectorC.magnitude() == sqrt(xVal*xVal+yVal*yVal));
+
+ // both negative numbers
+ xVal = -173.43;
+ yVal = -297.67;
+ Vector2D testVectorD(xVal, yVal);
+ // we are assuming that the math function sqrt is ok...
+ QVERIFY(testVectorD.magnitude() == sqrt(xVal*xVal+yVal*yVal));
+
+ // set to default
+ Vector2D testVectorE;
+ QVERIFY(testVectorE.magnitude() == sqrt(0.0));
+}
+void Test_Vector2D::Test_Normalize() {
+ double xVal;
+ double yVal;
+
+ // both positive numbers
+ xVal = 1.92;
+ yVal = 0.32;
+ Vector2D testVectorA(xVal, yVal);
+ testVectorA.normalize();
+ QVERIFY(testVectorA.magnitude() == 1.0);
+
+ // x pos, y neg numbers
+ xVal = 274.13;
+ yVal = -192.68;
+ Vector2D testVectorB(xVal, yVal);
+ testVectorB.normalize();
+ QVERIFY(testVectorB.magnitude() == 1.0);
+
+ // x neg, y pos numbers
+ xVal = -0.719;
+ yVal = 1.768;
+ Vector2D testVectorC(xVal, yVal);
+ testVectorC.normalize();
+ QVERIFY(testVectorC.magnitude() == 1.0);
+
+ // both negative numbers
+ xVal = -173.43;
+ yVal = -297.67;
+ Vector2D testVectorD(xVal, yVal);
+ testVectorD.normalize();
+ QVERIFY(testVectorD.magnitude() == 1.0);
+
+ // set to default
+ Vector2D testVectorE;
+ testVectorE.normalize();
+ QVERIFY(testVectorE.magnitude() == 0.0);
+}
+void Test_Vector2D::Test_GetNormal() {
+ double xVal;
+ double yVal;
+ double mag;
+ Vector2D testVector;
+
+ // both positive numbers
+ xVal = 1.92;
+ yVal = 0.32;
+ mag = sqrt(xVal*xVal+yVal*yVal);
+ Vector2D testVectorA(xVal, yVal);
+ testVector = testVectorA.getNormal();
+ QVERIFY(testVector.getX() == yVal * -1.0/mag);
+ QVERIFY(testVector.getY() == xVal/mag);
+
+ // x pos, y neg numbers
+ xVal = 274.13;
+ yVal = -192.68;
+ mag = sqrt(xVal*xVal+yVal*yVal);
+ Vector2D testVectorB(xVal, yVal);
+ testVector = testVectorB.getNormal();
+ QVERIFY(testVector.getX() == yVal * -1.0/mag);
+ QVERIFY(testVector.getY() == xVal/mag);
+
+ // x neg, y pos numbers
+ xVal = -0.719;
+ yVal = 1.768;
+ mag = sqrt(xVal*xVal+yVal*yVal);
+ Vector2D testVectorC(xVal, yVal);
+ testVector = testVectorC.getNormal();
+ QVERIFY(testVector.getX() == yVal * -1.0/mag);
+ QVERIFY(testVector.getY() == xVal/mag);
+
+ // both negative numbers
+ xVal = -173.43;
+ yVal = -297.67;
+ mag = sqrt(xVal*xVal+yVal*yVal);
+ Vector2D testVectorD(xVal, yVal);
+ testVector = testVectorD.getNormal();
+ QVERIFY(testVector.getX() == yVal * -1.0/mag);
+ QVERIFY(testVector.getY() == xVal/mag);
+
+ // set to default
+ Vector2D testVectorE;
+ testVector = testVectorE.getNormal();
+ QVERIFY(testVector.getX() == 0.0);
+ QVERIFY(testVector.getY() == 0.0);
+}
+void Test_Vector2D::Test_Dot() {
+ double xValA, xValB;
+ double yValA, yValB;
+ double dot;
+ Vector2D testVectorA;
+ Vector2D testVectorB;
+
+ // all positive numbers
+ xValA = 1.92;
+ yValA = 0.32;
+ xValB = 272.1;
+ yValB = 173.9;
+ dot = xValA*xValB+yValA*yValB;
+ testVectorA.setValue(xValA, yValA);
+ testVectorB.setValue(xValB, yValB);
+ QVERIFY(testVectorA.dot(testVectorB) == dot);
+
+ // x pos, one y neg numbers
+ xValA = 731.4;
+ yValA = 173.61;
+ xValB = 14.93;
+ yValB = -56.173;
+ dot = xValA*xValB+yValA*yValB;
+ testVectorA.setValue(xValA, yValA);
+ testVectorB.setValue(xValB, yValB);
+ QVERIFY(testVectorA.dot(testVectorB) == dot);
+
+ // one x neg, y pos numbers
+ xValA = -0.7193;
+ yValA = 0.361;
+ xValB = 1.934;
+ yValB = 1.431;
+ dot = xValA*xValB+yValA*yValB;
+ testVectorA.setValue(xValA, yValA);
+ testVectorB.setValue(xValB, yValB);
+ QVERIFY(testVectorA.dot(testVectorB) == dot);
+
+ // all negative numbers
+ xValA = -17.31;
+ yValA = -16.21;
+ xValB = -0.932;
+ yValB = -0.871;
+ dot = xValA*xValB+yValA*yValB;
+ testVectorA.setValue(xValA, yValA);
+ testVectorB.setValue(xValB, yValB);
+ QVERIFY(testVectorA.dot(testVectorB) == dot);
+
+ // one set to default
+ xValA = 1.92;
+ yValA = 0.32;
+ xValB = 0.0;
+ yValB = 0.0;
+ dot = xValA*xValB+yValA*yValB;
+ testVectorA.setValue(xValA, yValA);
+ testVectorB.setValue();
+ QVERIFY(testVectorA.dot(testVectorB) == dot);
+
+ // both set to default
+ dot = 0.0;
+ testVectorA.setValue();
+ testVectorB.setValue();
+ QVERIFY(testVectorA.dot(testVectorB) == dot);
+}
+
+void Test_Vector2D::Test_IsParallelTo() {
+ Vector2D testVectorA;
+ Vector2D testVectorB;
+
+ // both positive slopes
+ testVectorA.setValue(3.3,5.7);
+ testVectorB.setValue(3.3*9.7,5.7*9.7);
+ QVERIFY(testVectorA.isParallelTo(testVectorB));
+ QVERIFY(testVectorB.isParallelTo(testVectorA));
+
+ // one positive, one negative
+ testVectorA.setValue(-4.7,6.9);
+ testVectorB.setValue(4.7*191.6,6.9*191.6);
+ QVERIFY(testVectorA.isParallelTo(testVectorB));
+ QVERIFY(testVectorB.isParallelTo(testVectorA));
+
+ // both negative
+ testVectorA.setValue(-12.1,17.73);
+ testVectorB.setValue(-12.1*4.6,17.73*4.6);
+ QVERIFY(testVectorA.isParallelTo(testVectorB));
+ QVERIFY(testVectorB.isParallelTo(testVectorA));
+
+ // not parallel
+ testVectorA.setValue(6.7,9.1);
+ testVectorB.setValue(6.7*13.4,9.1*8.3);
+ QVERIFY(!testVectorA.isParallelTo(testVectorB));
+ QVERIFY(!testVectorB.isParallelTo(testVectorA));
+
+ // one set to default
+ testVectorA.setValue(17.1,4.3);
+ testVectorB.setValue();
+ QVERIFY(!testVectorA.isParallelTo(testVectorB));
+ QVERIFY(!testVectorB.isParallelTo(testVectorA));
+
+ // both set to default
+ testVectorA.setValue();
+ testVectorB.setValue();
+ QVERIFY(!testVectorA.isParallelTo(testVectorB));
+ QVERIFY(!testVectorB.isParallelTo(testVectorA));
+}
+
+void Test_Vector2D::Test_IsNormalTo() {
+ Vector2D testVectorA;
+ Vector2D testVectorB;
+
+ // direct normal
+ testVectorA.setValue(3.3,5.7);
+ testVectorB.setValue(5.7,-3.3);
+ QVERIFY(testVectorA.isNormalTo(testVectorB));
+ QVERIFY(testVectorB.isNormalTo(testVectorA));
+
+ // with one scaled
+ testVectorA.setValue(3.3,5.7);
+ testVectorB.setValue(5.7*9.7,-3.3*9.7);
+ QVERIFY(testVectorA.isNormalTo(testVectorB));
+ QVERIFY(testVectorB.isNormalTo(testVectorA));
+
+ // direct normal, the other direction
+ testVectorA.setValue(4.7,6.9);
+ testVectorB.setValue(-6.9,4.7);
+ QVERIFY(testVectorA.isNormalTo(testVectorB));
+ QVERIFY(testVectorB.isNormalTo(testVectorA));
+
+ // normal with multiplier, the other direction
+ testVectorA.setValue(4.7,6.9);
+ testVectorB.setValue(-6.9*119.31,4.7*119.31);
+ QVERIFY(testVectorA.isNormalTo(testVectorB));
+ QVERIFY(testVectorB.isNormalTo(testVectorA));
+
+ // try a set of parallel vectors...
+ testVectorA.setValue(12.1,17.73);
+ testVectorB.setValue(12.1*4.6,17.73*4.6);
+ QVERIFY(!testVectorA.isNormalTo(testVectorB));
+ QVERIFY(!testVectorB.isNormalTo(testVectorA));
+
+ // not normal
+ testVectorA.setValue(6.7,9.1);
+ testVectorB.setValue(-9.1*13.4,6.7*8.3);
+ QVERIFY(!testVectorA.isNormalTo(testVectorB));
+ QVERIFY(!testVectorB.isNormalTo(testVectorA));
+
+ // one set to default
+ testVectorA.setValue(17.1,4.3);
+ testVectorB.setValue();
+ QVERIFY(!testVectorA.isNormalTo(testVectorB));
+ QVERIFY(!testVectorB.isNormalTo(testVectorA));
+
+ // both set to default
+ testVectorA.setValue();
+ testVectorB.setValue();
+ QVERIFY(!testVectorA.isNormalTo(testVectorB));
+ QVERIFY(!testVectorB.isNormalTo(testVectorA));
+}
+
+void Test_Vector2D::Test_OperatorSet() {
+ Vector2D testVector;
+
+ // set to positive numbers
+ Vector2D testVectorA(5.4,7.2);
+ testVector = testVectorA;
+ QVERIFY(testVector.getX() == testVectorA.getX());
+ QVERIFY(testVector.getY() == testVectorA.getY());
+
+ // set to default
+ Vector2D testVectorB;
+ testVector = testVectorB;
+ QVERIFY(testVector.getX() == testVectorB.getX());
+ QVERIFY(testVector.getY() == testVectorB.getY());
+
+ // set to a negative number
+ Vector2D testVectorC(-5923.1,-21734.1);
+ testVector = testVectorC;
+ QVERIFY(testVector.getX() == testVectorC.getX());
+ QVERIFY(testVector.getY() == testVectorC.getY());
+}
+
+void Test_Vector2D::Test_OperatorEqual() {
+ Vector2D testVectorA(5.4,7.2);
+ Vector2D testVectorB;
+ Vector2D testVectorC(-5923.1,-21734.1);
+
+ Vector2D testVector = testVectorA;
+ QVERIFY(testVector == testVectorA);
+ QVERIFY(!(testVector == testVectorB));
+ QVERIFY(!(testVector == testVectorC));
+
+ testVector = testVectorB;
+ QVERIFY(!(testVector == testVectorA));
+ QVERIFY(testVector == testVectorB);
+ QVERIFY(!(testVector == testVectorC));
+
+ testVector = testVectorC;
+ QVERIFY(!(testVector == testVectorA));
+ QVERIFY(!(testVector == testVectorB));
+ QVERIFY(testVector == testVectorC);
+}
+
+void Test_Vector2D::Test_OperatorNotEqual() {
+ Vector2D testVectorA(5.4,7.2);
+ Vector2D testVectorB;
+ Vector2D testVectorC(-5923.1,-21734.1);
+
+ Vector2D testVector = testVectorA;
+ QVERIFY(!(testVector != testVectorA));
+ QVERIFY(testVector != testVectorB);
+ QVERIFY(testVector != testVectorC);
+
+ testVector = testVectorB;
+ QVERIFY(testVector != testVectorA);
+ QVERIFY(!(testVector != testVectorB));
+ QVERIFY(testVector != testVectorC);
+
+ testVector = testVectorC;
+ QVERIFY(testVector != testVectorA);
+ QVERIFY(testVector != testVectorB);
+ QVERIFY(!(testVector != testVectorC));
+}
+
+void Test_Vector2D::Test_OperatorOstream() {
+ double xVal;
+ double yVal;
+
+ // set to positive numbers
+ xVal = 56.4;
+ yVal = 17.2;
+
+ Vector2D testVector(xVal, yVal);
+ ostringstream testOSSA(ostringstream::out);
+ testOSSA.precision(15);
+ testOSSA << testVector;
+ 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;
+
+ testVector.setValue(xVal, yVal);
+ ostringstream testOSSB(ostringstream::out);
+ testOSSB.precision(15);
+ testOSSB << testVector;
+ string testStrB = testOSSB.str();
+
+ ostringstream controlOSSB(ostringstream::out);
+ controlOSSB.precision(15);
+ controlOSSB << "("<<xVal<<","<<yVal<<")";
+ string controlStrB = controlOSSB.str();
+
+ QVERIFY(testStrB == controlStrB);
+}
+
+#ifdef __NEEDS_DEBUGGING__
+
+void Test_Vector2D::Test_OperatorMultiply() {
+ double xVal = 5.4;
+ double yVal = 7.2;
+ double mul;
+ Vector2D testVector(xVal, yVal);
+
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // Positive number
+ mul = 4.91;
+ testVector = testVector * mul;
+ xVal *= mul;
+ yVal *= mul;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // Negative number
+ mul = -0.15;
+ testVector = testVector * mul;
+ xVal *= mul;
+ yVal *= mul;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // Zero
+ mul = 0.0;
+ testVector = testVector * mul;
+ xVal *= mul;
+ yVal *= mul;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+}
+
+void Test_Vector2D::Test_OperatorDivide() {
+ double xVal = 32.149;
+ double yVal = 91.43;
+ double div;
+ Vector2D testVector(xVal, yVal);
+
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // Positive number
+ div = 0.7291;
+ testVector = testVector / div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // Negative number
+ div = -15.941;
+ testVector = testVector / div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // One
+ div = 1.0;
+ testVector = testVector / div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // Zero
+ div = 0.0;
+ testVector = testVector / div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+}
+
+void Test_Vector2D::Test_OperatorMultiplyEqual() {
+ double xVal = 1.19;
+ double yVal = 910.14;
+ double mul;
+ Vector2D testVector(xVal, yVal);
+
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // Positive number
+ mul = 0.1234613;
+ testVector *= mul;
+ xVal *= mul;
+ yVal *= mul;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // Negative number
+ mul = -7234.19;
+ testVector *= mul;
+ xVal *= mul;
+ yVal *= mul;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // Zero
+ mul = 0.0;
+ testVector *= mul;
+ xVal *= mul;
+ yVal *= mul;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+}
+
+void Test_Vector2D::Test_OperatorDivideEqual() {
+ double xVal = 12.1;
+ double yVal = 0.7143;
+ double div;
+ Vector2D testVector(xVal, yVal);
+
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // Positive number
+ div = 71.45;
+ testVector /= div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // Negative number
+ div = -0.941613;
+ testVector /= div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // One
+ div = 1.0;
+ testVector /= div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+
+ // Zero
+ div = 0.0;
+ testVector /= div;
+ xVal /= div;
+ yVal /= div;
+ QVERIFY(testVector.getX() == xVal);
+ QVERIFY(testVector.getY() == yVal);
+}
+#endif
+
=======================================
--- /dev/null
+++ /src/common/utility/unit_tests/Test_Vector2D.h Mon Feb 8 02:40:30 2010
UTC
@@ -0,0 +1,64 @@
+/**
+ * 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_VECTOR2D_H__
+#define __TEST_VECTOR2D_H__
+
+#include <QtTest/QtTest>
+#include "../Vector2D.h"
+
+class Test_Vector2D: public QObject {
+ Q_OBJECT
+
+ private slots:
+ void Test_GetSetX();
+ void Test_GetSetY();
+ void Test_SetValue();
+ void Test_Constructor();
+ void Test_Magnitude();
+ void Test_Normalize();
+ void Test_GetNormal();
+ void Test_Dot();
+ void Test_IsParallelTo();
+ void Test_IsNormalTo();
+
+ 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
=======================================
--- /src/common/unit_tests/
unit_tests.pro Sun Feb 7 22:05:58 2010 UTC
+++ /src/common/unit_tests/
unit_tests.pro Mon Feb 8 02:40:30 2010 UTC
@@ -20,15 +20,19 @@
# Input
SOURCES = unit_tests_main.cpp
+SOURCES += $$COMMON_PATH/utility/misc_funcs.cpp
+SOURCES += $$COMMON_PATH/utility/unit_tests/Test_MiscFuncs.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
+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/misc_funcs.h
+HEADERS += $$COMMON_PATH/utility/unit_tests/Test_MiscFuncs.h
+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
+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
=======================================
--- /src/common/unit_tests/unit_tests_main.cpp Sun Feb 7 22:05:58 2010 UTC
+++ /src/common/unit_tests/unit_tests_main.cpp Mon Feb 8 02:40:30 2010 UTC
@@ -1,4 +1,35 @@
#include <QtTest/QtTest>
+#include <QList>
+#include "utility/unit_tests/Test_MiscFuncs.h"
#include "utility/unit_tests/Test_Point2D.h"
+#include "utility/unit_tests/Test_Vector2D.h"
-QTEST_MAIN(Test_Point2D)
+int main(int argc, char** argv) {
+ QObject* tmpObj;
+ QList<QObject*> testObjs;
+
+ // Add test objects to the list.
+ tmpObj = new Test_MiscFuncs();
+ if(tmpObj != NULL)
+ testObjs.append(tmpObj);
+
+ tmpObj = new Test_Point2D();
+ if(tmpObj != NULL)
+ testObjs.append(tmpObj);
+
+ tmpObj = new Test_Vector2D();
+ if(tmpObj != NULL)
+ testObjs.append(tmpObj);
+
+ // Iterate through tests, incrementing
+ // retVal for every failure
+ int retVal = 0;
+ for(int i=0; i<testObjs.size(); i++) {
+ tmpObj = testObjs.at(i);
+ if(tmpObj != NULL) {
+ retVal += QTest::qExec(tmpObj, argc, argv);
+ }
+ }
+
+ return retVal;
+}
=======================================
--- /src/common/utility/Point2D.cpp Sun Feb 7 22:05:58 2010 UTC
+++ /src/common/utility/Point2D.cpp Mon Feb 8 02:40:30 2010 UTC
@@ -21,8 +21,40 @@
*
http://trolltech.com/
*
*/
+#include "misc_funcs.h"
#include "Point2D.h"
+// Set default value of the global epsilon
+double Point2D::DEFAULT_EPSILON = 0.0000001;
+
+/**
+ * Sets the default epsilon value.
+ */
+void Point2D::setDefaultEpsilon(const double& epsilon) {
+ DEFAULT_EPSILON = epsilon;
+}
+
+/**
+ * Gets the default epsilon value.
+ */
+double Point2D::getDefaultEpsilon() {
+ return DEFAULT_EPSILON;
+}
+
+/**
+ * Sets the epsilon value for this object.
+ */
+void Point2D::setEpsilon(const double &epsilon) {
+ _epsilon = epsilon;
+}
+
+/**
+ * Gets the epsilon value for this object.
+ */
+double Point2D::getEpsilon() {
+ return _epsilon;
+}
+
/**
* Constructor.
*
@@ -32,6 +64,7 @@
Point2D::Point2D(const double x, const double y) {
_x = x;
_y = y;
+ _epsilon = DEFAULT_EPSILON;
}
/**
@@ -84,7 +117,8 @@
}
bool Point2D::operator==(const Point2D& other) {
- return (_x == other._x && _y == other._y);
+ return (relativeCompare(1.0+_x, 1.0+other._x, _epsilon) &&
+ relativeCompare(1.0+_y,1.0+other._y, _epsilon));
}
bool Point2D::operator!=(const Point2D& other) {
return !(*this == other);
=======================================
--- /src/common/utility/Point2D.h Sun Feb 7 22:05:58 2010 UTC
+++ /src/common/utility/Point2D.h Mon Feb 8 02:40:30 2010 UTC
@@ -77,6 +77,26 @@
*/
void setValue(const double x=0.0, const double y=0.0);
+ /**
+ * Sets the default epsilon value.
+ */
+ static void setDefaultEpsilon(const double& epsilon);
+
+ /**
+ * Gets the default epsilon value.
+ */
+ static double getDefaultEpsilon();
+
+ /**
+ * Sets the epsilon value for this object.
+ */
+ void setEpsilon(const double &epsilon);
+
+ /**
+ * Gets the epsilon value for this object.
+ */
+ double getEpsilon();
+
Point2D& operator=(const Point2D& other);
bool operator==(const Point2D& other);
bool operator!=(const Point2D& other);
@@ -91,6 +111,9 @@
private:
double _x;
double _y;
+
+ double _epsilon;
+ static double DEFAULT_EPSILON;
};
#endif
=======================================
--- /src/common/utility/Vector2D.cpp Mon Apr 27 21:19:22 2009 UTC
+++ /src/common/utility/Vector2D.cpp Mon Feb 8 02:40:30 2010 UTC
@@ -1,16 +1,48 @@
-
+#include "misc_funcs.h"
#include "Vector2D.h"
+// Set default value of the global epsilon
+double Vector2D::DEFAULT_EPSILON = 0.0000001;
+
+/**
+ * Sets the default epsilon value.
+ */
+void Vector2D::setDefaultEpsilon(const double& epsilon) {
+ DEFAULT_EPSILON = epsilon;
+}
+
+/**
+ * Gets the default epsilon value.
+ */
+double Vector2D::getDefaultEpsilon() {
+ return DEFAULT_EPSILON;
+}
+
+/**
+ * Sets the epsilon value for this object.
+ */
+void Vector2D::setEpsilon(const double &epsilon) {
+ _epsilon = epsilon;
+}
+
+/**
+ * Gets the epsilon value for this object.
+ */
+double Vector2D::getEpsilon() {
+ return _epsilon;
+}
+
/**
* Constructor.
*
* @param x The initial x value of the vector.
* @param y The initial y value of the vector.
*/
-Vector2D::Vector2D(const double x=0.0, const double y=0.0) {
+Vector2D::Vector2D(const double x, const double y) {
_x = x;
_y = y;
_bIsNormalized = false;
+ _epsilon = DEFAULT_EPSILON;
}
/**
@@ -28,7 +60,7 @@
/**
* Sets the x value.
*/
-void Vector2D::setX(const double x=0.0) {
+void Vector2D::setX(const double x) {
_x = x;
_bIsNormalized = false;
}
@@ -42,10 +74,21 @@
/**
* Sets the y value.
*/
-void Vector2D::setY(const double y=0.0) {
+void Vector2D::setY(const double y) {
_y = y;
_bIsNormalized = false;
}
+
+/**
+ * Sets the x & y values.
+ *
+ * @param x The x value of the vector.
+ * @param y The y value of the vector.
+ */
+void Vector2D::setValue(const double x, const double y) {
+ _x = x;
+ _y = y;
+}
/**
* Gets the magnitude of the vector.
@@ -78,11 +121,21 @@
void Vector2D::normalize() {
if(!_bIsNormalized) {
double mag = magnitude();
- _x = _x/mag;
- _y = _y/mag;
- _bIsNormalized = true;
+ if(!relativeCompare(mag, 0.0, _epsilon)) {
+ _x = _x/mag;
+ _y = _y/mag;
+ _bIsNormalized = true;
+ }
}
}
+
+/**
+ * Returns the dot product of the specified vector with this vector.
+ */
+double Vector2D::dot(const Vector2D other) {
+ return (_x*other._x+_y*other._y);
+}
+
/**
* Returns true if the specified vector is parallel to this vector.
@@ -94,26 +147,42 @@
otherUnitV.normalize();
return
- ( (thisUnitV._x == otherUnitV._x || thisUnitV._x ==
-1.0*otherUnitV._x) &&
- (thisUnitV._y == otherUnitV._y || thisUnitV._y ==
-1.0*otherUnitV._y) );
+ ( relativeCompare(thisUnitV.magnitude(), 1.0, _epsilon) &&
+ relativeCompare(otherUnitV.magnitude(), 1.0, _epsilon) &&
+ (relativeCompare(thisUnitV._x, otherUnitV._x, _epsilon) ||
+ relativeCompare(thisUnitV._x, 1.0*otherUnitV._x, _epsilon)) &&
+ (relativeCompare(thisUnitV._y, otherUnitV._y, _epsilon) ||
+ relativeCompare(thisUnitV._y, 1.0*otherUnitV._y, _epsilon)) );
}
/**
* Returns true if the specified vector is normal to this vector.
*/
bool Vector2D::isNormalTo(const Vector2D other) {
- Vector2D otherNormV = other.getNormal();
+ Vector2D thisV = *this;
+ Vector2D otherNormV = other;
- return isParallel(otherNormV);
+ return thisV.isParallelTo(otherNormV.getNormal());
}
-/**
- * Returns the dot product of the specified vector with this vector.
- */
-double Vector2D::dot(const Vector2D other) {
- return (_x*other._x+_y*other._y);
+Vector2D& Vector2D::operator=(const Vector2D& other) {
+ // no need to check for self-assignment, since we're not
+ // allocating/deallocating memory.
+ _x = other._x;
+ _y = other._y;
+ _bIsNormalized = other._bIsNormalized;
+
+ return *this;
}
+bool Vector2D::operator==(const Vector2D& other) {
+ return (relativeCompare(_x, other._x, _epsilon) &&
+ relativeCompare(_y, other._y, _epsilon));
+}
+bool Vector2D::operator!=(const Vector2D& other) {
+ return !(*this == other);
+}
+#ifdef __NEEDS_DEBUGING__
/**
* Calculates the angle between the specified vector and this vector.
* Note: returns a value between [0, pi] or NaN if values are invalid.
@@ -173,67 +242,78 @@
return false;
}
-Vector2D& Vector2D::operator=(const Vector2D& other) {
- // no need to check for self-assignment, since we're not
- // allocating/deallocating memory.
- _x = other._x;
- _y = other._y;
- _bIsNormalized = other._bIsNormalized;
-
+Vector2D& Vector2D::operator+(const Vector2D& other) {
+ *this += other;
return *this;
}
-Vector2D& Vector2D::operator+(const Vector2D& other) {
- Vector2D retVal = *this;
- retVal += other;
- return retVal;
-}
Vector2D& Vector2D::operator*(const double val) {
- Vector2D retVal = *this;
- retVal *= val;
- return retVal;
+ *this *= val;
+ return *this;
}
Vector2D& Vector2D::operator*(const double val, Vector2D& v) {
return v*val;
}
Vector2D& Vector2D::operator/(const double val) {
- Vector2D retVal = *this;
- retVal /= val;
- return retVal;
+ *this /= val;
+ return *this;
}
Vector2D& Vector2D::operator+=(const Vector2D& other) {
- Vector2D retVal = *this;
- retVal._x += other._x;
- retVal._y += other._y;
- retVal._bIsNormalized = false;
- return retVal;
+ _x += other._x;
+ _y += other._y;
+ _bIsNormalized = false;
+ return *this;
}
Vector2D& Vector2D::operator*=(const double val) {
- Vector2D retVal = *this;
- retVal._x *= val;
- retVal._y *= val;
- retVal._bIsNormalized = false;
- return retVal;
+ _x *= val;
+ _y *= val;
+ _bIsNormalized = false;
+ return *this;
}
Vector2D& Vector2D::operator/=(const double val) {
- Vector2D retVal = *this;
- retVal *= (1.0/val);
- return retVal;
-}
-Vector2D& Vector2D::operator==(const Vector2D& other) {
- return (_x == other._x && _y == other._y);
-}
-Vector2D& Vector2D::operator!=(const Vector2D& other) {
- return !(*this == other);
-
+ *this *= (1.0/val);
+ return *this;
}
Vector2D& Vector2D::operator-=(const Vector2D& other) {
Vector2D otherInv = other * -1.0;
- Vector2D retVal = *this;
- retVal += otherInv;
- return retVal;
+ *this += otherInv;
+ return *this;
}
Vector2D& Vector2D::operator-(const Vector2D& other) {
- Vector2D retVal = *this;
- retVal -= other;
+ *this -= other;
+ return *this;
+}
+
+// **** Begin Friend definitions ****
+
+/**
+ * point subtraction results in a vector
+ */
+Vector2D& operator-(const Point2D& initial, const Point2D& final) {
+ double x = final.getX() - initial.getX();
+ double y = final.getY() - initial.getY();
+ Vector2D retVal(x, y);
return retVal;
}
+
+/**
+ * A point plus a vector results in a new point.
+ */
+Point2D& operator+(const Point2D& p, const Vector2D& v) {
+ Point2D retVal;
+ retVal.setX(p.getX()+v.getX());
+ retVal.setY(p.getY()+v.getY());
+}
+Point2D& operator+(const Vector2D& v, const Point2D& p) {
+ return p+v;
+}
+#endif
+
+/**
+ * friend vector to dump to an ostream
+ */
+ostream& operator<<(ostream& os, const Vector2D& vector) {
+ Vector2D tmp = vector;
+ os<<"("<<tmp.getX()<<","<<tmp.getY()<<")";
+ return os;
+}
+
=======================================
--- /src/common/utility/Vector2D.h Mon Apr 27 21:19:22 2009 UTC
+++ /src/common/utility/Vector2D.h Mon Feb 8 02:40:30 2010 UTC
@@ -59,21 +59,30 @@
* Gets the x value.
*/
double getX();
+
/**
* Sets the x value.
*/
void setX(const double x=0.0);
+
/**
* Gets the y value.
*/
double getY();
-
/**
* Sets the y value.
*/
void setY(const double y=0.0);
+ /**
+ * Sets the x & y values.
+ *
+ * @param x The x value of the vector.
+ * @param y The y value of the vector.
+ */
+ void setValue(const double x=0.0, const double y=0.0);
+
/**
* Gets the magnitude of the vector.
*/
@@ -89,6 +98,11 @@
*/
void normalize();
+ /**
+ * Returns the dot product of the specified vector with this vector.
+ */
+ double dot(const Vector2D other);
+
/**
* Returns true if the specified vector is parallel to this vector.
*/
@@ -100,10 +114,30 @@
bool isNormalTo(const Vector2D other);
/**
- * Returns the dot product of the specified vector with this vector.
+ * Sets the default epsilon value.
*/
- double dot(const Vector2D other);
+ static void setDefaultEpsilon(const double& epsilon);
+
+ /**
+ * Gets the default epsilon value.
+ */
+ static double getDefaultEpsilon();
+ /**
+ * Sets the epsilon value for this object.
+ */
+ void setEpsilon(const double &epsilon);
+
+ /**
+ * Gets the epsilon value for this object.
+ */
+ double getEpsilon();
+
+ Vector2D& operator=(const Vector2D& other);
+ bool operator==(const Vector2D& other);
+ bool operator!=(const Vector2D& other);
+
+#ifdef __NEEDS_DEBUGGING__
/**
* Calculates the angle between the specified vector and this vector.
*/
@@ -118,6 +152,15 @@
*/
bool isOnLine(const Point2D a, const point2D b);
+ /**
+ * Checks to see if point B is on the line specified
+ * by this vector and point A.
+ *
+ * @param a A point known to be on the line.
+ * @param b The point to check.
+ */
+ Point2D getPoint(const Point2D a, const double distance=1.0);
+
/**
* Finds the point of intersection of the line specified
* by this vector and point A and the line specified by
@@ -133,56 +176,30 @@
bool getIntersectingPt(const Point2D pA, const Vector2D vB,
const Point2D pB, Vector2D* result);
- Vector2D& operator=(const Vector2D& other);
Vector2D& operator+(const Vector2D& other);
+ Vector2D& operator-(const Vector2D& other);
Vector2D& operator*(const double val);
Vector2D& operator*(const double val, Vector2D& v);
Vector2D& operator/(const double val);
Vector2D& operator+=(const Vector2D& other);
Vector2D& operator*=(const double val);
Vector2D& operator/=(const double val);
- Vector2D& operator==(const Vector2D& other);
- Vector2D& operator!=(const Vector2D& other);
Vector2D& operator-=(const Vector2D& other);
- Vector2D& operator-(const Vector2D& other);
+
+ friend Vector2D& operator-(const Point2D& initial, const Point2D& final);
+ friend Point2D& operator+(const Point2D& p, const Vector2D& v);
+ friend Point2D& operator+(const Vector2D& v, const Point2D& p);
+#endif
+ friend ostream& operator<<(ostream& os, const Vector2D& vector);
private:
double _x;
double _y;
bool _bIsNormalized; //!< cuts down on excess calculations.
+
+ double _epsilon;
+ static double DEFAULT_EPSILON;
};
-
-// **** Begin Friend definitions ****
-
-/**
- * friend vector to dump to an ostream
- */
-friend ostream& operator<<(ostream& os, const Vector2D& vector) {
- os<<"("<<vector.getX()<<","<<vector.getY()<<")";
- return os;
-}
-
-/**
- * point subtraction results in a vector
- */
-friend Vector2D& operator-(const Point2D& initial, const Point2D& final) {
- double x = final.getX() - initial.getX();
- double y = final.getY() - initial.getY();
- Vector2D retVal(x, y);
- return retVal;
-}
-
-/**
- * A point plus a vector results in a new point.
- */
-friend Point2D& operator+(const Point2D& p, const Vector2D& v) {
- Point2D retVal;
- retVal.setX(p.getX()+v.getX());
- retVal.setY(p.getY()+v.getY());
-}
-friend Point2D& operator+(const Vector2D& v, const Point2D& p) {
- return p+v;
-}
#endif
=======================================
--- /src/common/utility/misc_funcs.cpp Mon Apr 27 00:56:58 2009 UTC
+++ /src/common/utility/misc_funcs.cpp Mon Feb 8 02:40:30 2010 UTC
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <ctime>
+//#include <iostream>
using namespace std;
#include <QString>
@@ -116,3 +117,25 @@
int roundDtoI(const double& val) {
return (val < 0.0) ? int(val-0.5) : int(val+0.5);
}
+
+/**
+ * Compares to doubles using the specified precision.
+ */
+bool relativeCompare(const double& A, const double& B,
+ const double& epsilon) {
+ double tmpA = (A > 0.0) ? A : -1.0 * A;
+ double tmpB = (B > 0.0) ? B : -1.0 * B;
+ double delta = (tmpA > tmpB) ? tmpA - tmpB : tmpB - tmpA;
+ return (delta <= epsilon);
+}
+
+/**
+ * Compares to floats using the specified precision.
+ */
+bool relativeCompare(const float& A, const float& B,
+ const float& epsilon) {
+ float tmpA = (A > 0.0) ? A : -1.0 * A;
+ float tmpB = (B > 0.0) ? B : -1.0 * B;
+ float delta = (tmpA > tmpB) ? tmpA - tmpB : tmpB - tmpA;
+ return (delta <= epsilon);
+}
=======================================
--- /src/common/utility/misc_funcs.h Mon Apr 27 00:56:58 2009 UTC
+++ /src/common/utility/misc_funcs.h Mon Feb 8 02:40:30 2010 UTC
@@ -72,4 +72,16 @@
return (val < 0.0) ? int(val-0.5) : int(val+0.5);
}*/
+/**
+ * Compares to doubles using the specified precision.
+ */
+extern bool relativeCompare(const double& A, const double& B,
+ const double& epsilon);
+
+/**
+ * Compares to floats using the specified precision.
+ */
+extern bool relativeCompare(const float& A, const float& B,
+ const float& epsilon);
+
//#endif
=======================================
--- /src/common/utility/unit_tests/Test_Point2D.cpp Sun Feb 7 22:05:58
2010 UTC
+++ /src/common/utility/unit_tests/Test_Point2D.cpp Mon Feb 8 02:40:30
2010 UTC
@@ -108,6 +108,23 @@
QVERIFY(testPointC.getY() == -21734.1);
}
+void Test_Point2D::Test_Epsilon() {
+ Point2D testPointA;
+
+ // get/set Defaults
+ double defVal = 0.0000001;
+ QVERIFY(testPointA.getDefaultEpsilon() == defVal);
+ testPointA.setDefaultEpsilon(0.001);
+ QVERIFY(testPointA.getDefaultEpsilon() == 0.001);
+
+ Point2D testPointB;
+ QVERIFY(testPointB.getEpsilon() == 0.001);
+ testPointB.setEpsilon(0.0007);
+ QVERIFY(testPointB.getEpsilon() == 0.0007);
+
+ // return to default
+ testPointA.setDefaultEpsilon(defVal);
+}
void Test_Point2D::Test_OperatorSet() {
Point2D testPoint;
=======================================
--- /src/common/utility/unit_tests/Test_Point2D.h Sun Feb 7 22:05:58 2010
UTC
+++ /src/common/utility/unit_tests/Test_Point2D.h Mon Feb 8 02:40:30 2010
UTC
@@ -40,6 +40,7 @@
void Test_GetSetY();
void Test_SetValue();
void Test_Constructor();
+ void Test_Epsilon();
void Test_OperatorSet();
void Test_OperatorEqual();
void Test_OperatorNotEqual();
==============================================================================
Revision: f059e2e49913
Author: Jeff Backus <
jeff....@gmail.com>
Date: Thu Feb 11 02:19:00 2010 UTC
Log: Made a lot of progress with Vector2D and its unit test. Have one
more
function to go!
http://code.google.com/p/idlescreen/source/detail?r=f059e2e49913
Modified:
/src/common/utility/Point2D.h
/src/common/utility/Vector2D.cpp
/src/common/utility/Vector2D.h
/src/common/utility/unit_tests/Test_Vector2D.cpp
/src/common/utility/unit_tests/Test_Vector2D.h
=======================================
--- /src/common/utility/Point2D.h Mon Feb 8 02:40:30 2010 UTC
+++ /src/common/utility/Point2D.h Thu Feb 11 02:19:00 2010 UTC
@@ -57,7 +57,7 @@
/**
* Gets the x value.
*/
- double getX();
+ double getX();
/**
* Sets the x value.
*/
=======================================
--- /src/common/utility/Vector2D.cpp Mon Feb 8 02:40:30 2010 UTC
+++ /src/common/utility/Vector2D.cpp Thu Feb 11 02:19:00 2010 UTC
@@ -174,29 +174,56 @@
return *this;
}
-bool Vector2D::operator==(const Vector2D& other) {
- return (relativeCompare(_x, other._x, _epsilon) &&
- relativeCompare(_y, other._y, _epsilon));
-}
-bool Vector2D::operator!=(const Vector2D& other) {
- return !(*this == other);
-}
-#ifdef __NEEDS_DEBUGING__
/**
* Calculates the angle between the specified vector and this vector.
* Note: returns a value between [0, pi] or NaN if values are invalid.
+ * If one or both of the vectors has a length of zero, a value of
+ * 0.0 is returned.
*/
double Vector2D::getAngle(const Vector2D other) {
// we know that mag(v1)*mag(v2)*cos(theta)=normal(v1) dot v2
// thus theta = arccos( (normal(v1) dot v2) / ( mag(v1)*mag(v2) ) )
- Vector2D norm = getNormal();
+ Vector2D norm = *this;
Vector2D otherUnitV = other;
+ norm.normalize();
otherUnitV.normalize(); // dealing with normal vectors makes the math
easy.
+ if(norm.magnitude() != 1.0 || otherUnitV.magnitude() != 1.0) {
+ return 0.0;
+ }
+
return acos(norm.dot(otherUnitV));
}
+
+/**
+ * Rotates the vector by the angle radians.
+ */
+void Vector2D::rotate(const double angle) {
+ double newX = _x*cos(angle)-_y*sin(angle);
+ double newY = _x*sin(angle)+_y*cos(angle);
+
+ _x = newX;
+ _y = newY;
+}
+
+
+/**
+ * Returns the point that is described by traveling along a scaled
+ * version of this vector from the specified point. Note that
+ * this vector is not normalized beforehand.
+ *
+ * @param a Origination point.
+ * @param scalar The amount to scale this vector by first.
+ */
+Point2D Vector2D::getPoint(const Point2D a, const double scalar) {
+ Point2D retVal = a;
+ retVal.setX(retVal.getX()+scalar*_x);
+ retVal.setY(retVal.getY()+scalar*_y);
+
+ return retVal;
+}
/**
* Checks to see if point B is on the line specified
@@ -205,11 +232,23 @@
* @param a A point known to be on the line.
* @param b The point to check.
*/
-bool Vector2D::isOnLine(const Point2D a, const point2D b) {
+bool Vector2D::isOnLine(const Point2D a, const Point2D b) {
+ // check to see if the points are the same. If so, easy peasy!
+ Point2D copyA = a;
+ if(copyA == b) {
+ return true;
+ }
+
+ // create a replica and ensure that its magnitude isn't 0.0.
+ Vector2D replica = *this;
+ if(relativeCompare(replica.magnitude(),0.0, _epsilon)) {
+ return true;
+ }
// If the vector from point B to point A is parallel to vector V, then
- // point B is on the line.
- Vector2D v2 = b - a;
- return isParallel(v2);
+ // point B is on the line.
+ Vector2D v2;
+ v2 = b - a;
+ return replica.isParallelTo(v2);
}
/**
@@ -228,30 +267,43 @@
* @return True if the lines intersect, false if they do not.
*/
bool Vector2D::getIntersectingPt(const Point2D pA, const Vector2D vB,
- const Point2D pB, Vector2D* result) {
+ const Point2D pB, Point2D& result) {
- double numer = vB._x*(pB.getY() - pA.getY()) -
- vB._y*(pB.getX() - pA.getX());
- double denom = vB._y*_x - vB._x*_y;
+ Point2D rPA = pA;
+ Point2D rPB = pB;
+ Vector2D rVB = vB;
+ double numer = rVB._x*(rPB.getY() - rPA.getY()) -
+ rVB._y*(rPB.getX() - rPA.getX());
+ double denom = rVB._y*_x - rVB._x*_y;
if(denom != 0) {
- if(result != NULL) {
- Vector2D vF = (*this) * (numer / denom);
- result = pA + vF;
- }
+ Vector2D vF = (*this) * (numer / denom);
+ result = rPA + vF;
}
return false;
}
+
+bool Vector2D::operator==(const Vector2D& other) {
+ return (relativeCompare(_x, other._x, _epsilon) &&
+ relativeCompare(_y, other._y, _epsilon));
+}
+bool Vector2D::operator!=(const Vector2D& other) {
+ return !(*this == other);
-Vector2D& Vector2D::operator+(const Vector2D& other) {
- *this += other;
- return *this;
}
Vector2D& Vector2D::operator*(const double val) {
*this *= val;
return *this;
}
-Vector2D& Vector2D::operator*(const double val, Vector2D& v) {
- return v*val;
+Vector2D& Vector2D::operator*=(const double val) {
+ _x *= val;
+ _y *= val;
+ _bIsNormalized = false;
+ return *this;
+}
+
+Vector2D& Vector2D::operator+(const Vector2D& other) {
+ *this += other;
+ return *this;
}
Vector2D& Vector2D::operator/(const double val) {
*this /= val;
@@ -263,18 +315,15 @@
_bIsNormalized = false;
return *this;
}
-Vector2D& Vector2D::operator*=(const double val) {
- _x *= val;
- _y *= val;
- _bIsNormalized = false;
- return *this;
-}
Vector2D& Vector2D::operator/=(const double val) {
- *this *= (1.0/val);
+ _x /= val;
+ _y /= val;
+ _bIsNormalized = false;
return *this;
}
Vector2D& Vector2D::operator-=(const Vector2D& other) {
- Vector2D otherInv = other * -1.0;
+ Vector2D otherInv = other;
+ otherInv *= -1.0;
*this += otherInv;
return *this;
}
@@ -285,28 +334,41 @@
// **** Begin Friend definitions ****
+Vector2D operator*(const double val, const Vector2D& v) {
+ Vector2D tmp = v;
+ return tmp*val;
+}
+
/**
- * point subtraction results in a vector
+ * A point plus a vector results in a new point.
*/
-Vector2D& operator-(const Point2D& initial, const Point2D& final) {
- double x = final.getX() - initial.getX();
- double y = final.getY() - initial.getY();
- Vector2D retVal(x, y);
+Point2D operator+(const Point2D& p, const Vector2D& v) {
+ Vector2D repV = v;
+ Point2D retVal = repV.getPoint(p,1.0);
+ return retVal;
+}
+
+Point2D operator+(const Vector2D& v, const Point2D& p) {
+ Vector2D repV = v;
+ Point2D retVal = repV.getPoint(p,1.0);
+ return retVal;
+}
+
+Point2D operator-(const Point2D& p, const Vector2D& v) {
+ Vector2D repV = v;
+ Point2D retVal = repV.getPoint(p,-1.0);
return retVal;
}
/**
- * A point plus a vector results in a new point.
+ * point subtraction results in a vector
*/
-Point2D& operator+(const Point2D& p, const Vector2D& v) {
- Point2D retVal;
- retVal.setX(p.getX()+v.getX());
- retVal.setY(p.getY()+v.getY());
-}
-Point2D& operator+(const Vector2D& v, const Point2D& p) {
- return p+v;
+Vector2D operator-(const Point2D& final, const Point2D& initial) {
+ Point2D f = final;
+ Point2D i = initial;
+ Vector2D retVal(f.getX() - i.getX(),f.getY() - i.getY());
+ return retVal;
}
-#endif
/**
* friend vector to dump to an ostream
@@ -316,4 +378,3 @@
os<<"("<<tmp.getX()<<","<<tmp.getY()<<")";
return os;
}
-
=======================================
--- /src/common/utility/Vector2D.h Mon Feb 8 02:40:30 2010 UTC
+++ /src/common/utility/Vector2D.h Thu Feb 11 02:19:00 2010 UTC
@@ -113,6 +113,38 @@
*/
bool isNormalTo(const Vector2D other);
+ /**
+ * Calculates the angle between the specified vector and this vector.
+ * Note: returns a value between [0, pi] or NaN if values are invalid.
+ * If one or both of the vectors has a length of zero, a value of
+ * 0.0 is returned.
+ */
+ double getAngle(const Vector2D other);
+
+ /**
+ * Rotates the vector by the angle radians.
+ */
+ void rotate(const double angle);
+
+ /**
+ * Returns the point that is described by traveling along a scaled
+ * version of this vector from the specified point. Note that
+ * this vector is not normalized beforehand.
+ *a
+ * @param a Origination point.
+ * @param scalar The amount to scale this vector by first.
+ */
+ Point2D getPoint(const Point2D a, const double scalar=1.0);
+
+ /**
+ * Checks to see if point B is on the line specified
+ * by this vector and point A.
+ *
+ * @param a A point known to be on the line.
+ * @param b The point to check.
+ */
+ bool isOnLine(const Point2D a, const Point2D b);
+
/**
* Sets the default epsilon value.
*/
@@ -137,30 +169,6 @@
bool operator==(const Vector2D& other);
bool operator!=(const Vector2D& other);
-#ifdef __NEEDS_DEBUGGING__
- /**
- * Calculates the angle between the specified vector and this vector.
- */
- double getAngle(const Vector2D other);
-
- /**
- * Checks to see if point B is on the line specified
- * by this vector and point A.
- *
- * @param a A point known to be on the line.
- * @param b The point to check.
- */
- bool isOnLine(const Point2D a, const point2D b);
-
- /**
- * Checks to see if point B is on the line specified
- * by this vector and point A.
- *
- * @param a A point known to be on the line.
- * @param b The point to check.
- */
- Point2D getPoint(const Point2D a, const double distance=1.0);
-
/**
* Finds the point of intersection of the line specified
* by this vector and point A and the line specified by
@@ -174,22 +182,17 @@
* @return True if the lines intersect, false if they do not.
*/
bool getIntersectingPt(const Point2D pA, const Vector2D vB,
- const Point2D pB, Vector2D* result);
+ const Point2D pB, Point2D& result);
- Vector2D& operator+(const Vector2D& other);
- Vector2D& operator-(const Vector2D& other);
Vector2D& operator*(const double val);
- Vector2D& operator*(const double val, Vector2D& v);
+ Vector2D& operator*=(const double val);
Vector2D& operator/(const double val);
+ Vector2D& operator/=(const double val);
+ Vector2D& operator+(const Vector2D& other);
Vector2D& operator+=(const Vector2D& other);
- Vector2D& operator*=(const double val);
- Vector2D& operator/=(const double val);
+ Vector2D& operator-(const Vector2D& other);
Vector2D& operator-=(const Vector2D& other);
- friend Vector2D& operator-(const Point2D& initial, const Point2D& final);
- friend Point2D& operator+(const Point2D& p, const Vector2D& v);
- friend Point2D& operator+(const Vector2D& v, const Point2D& p);
-#endif
friend ostream& operator<<(ostream& os, const Vector2D& vector);
private:
@@ -202,4 +205,12 @@
static double DEFAULT_EPSILON;
};
+
+// global functions related to this class
+extern Vector2D operator*(const double val, const Vector2D& v);
+extern Point2D operator+(const Point2D& p, const Vector2D& v);
+extern Point2D operator+(const Vector2D& v, const Point2D& p);
+extern Point2D operator-(const Point2D& p, const Vector2D& v);
+extern Vector2D operator-(const Point2D& final, const Point2D& initial);
+
#endif
=======================================
--- /src/common/utility/unit_tests/Test_Vector2D.cpp Mon Feb 8 02:40:30
2010 UTC
+++ /src/common/utility/unit_tests/Test_Vector2D.cpp Thu Feb 11 02:19:00
2010 UTC
@@ -385,6 +385,195 @@
QVERIFY(!testVectorA.isNormalTo(testVectorB));
QVERIFY(!testVectorB.isNormalTo(testVectorA));
}
+
+void Test_Vector2D::Test_GetAngle() {
+ Vector2D testVectorA;
+ Vector2D testVectorB;
+
+ // Parallel vectors
+ double angle = 0.0;
+ double mag = 3.5;
+ testVectorA.setValue(1.0,0.0);
+ testVectorB.setValue(mag*cos(angle),mag*sin(angle));
+ QVERIFY(relativeCompare(testVectorA.getAngle(testVectorB),angle,
1.0e-6));
+ QVERIFY(relativeCompare(testVectorB.getAngle(testVectorA),angle,
1.0e-6));
+
+ // Perpendicular vectors
+ angle = 1.570763;
+ mag = 17.4;
+ testVectorA.setValue(1.0,0.0);
+ testVectorB.setValue(mag*cos(angle),mag*sin(angle));
+ QVERIFY(relativeCompare(testVectorA.getAngle(testVectorB),angle,
1.0e-6));
+ QVERIFY(relativeCompare(testVectorB.getAngle(testVectorA),angle,
1.0e-6));
+
+ // Acute vectors
+ angle = 0.478115;
+ mag = 0.653;
+ testVectorA.setValue(1.0,0.0);
+ testVectorB.setValue(mag*cos(angle),mag*sin(angle));
+ QVERIFY(relativeCompare(testVectorA.getAngle(testVectorB),angle,
1.0e-6));
+ QVERIFY(relativeCompare(testVectorB.getAngle(testVectorA),angle,
1.0e-6));
+
+ // Obtuse vectors
+ angle = 3.071099;
+ mag = 19273.1;
+ testVectorA.setValue(1.0,0.0);
+ testVectorB.setValue(mag*cos(angle),mag*sin(angle));
+ QVERIFY(relativeCompare(testVectorA.getAngle(testVectorB),angle,
1.0e-6));
+ QVERIFY(relativeCompare(testVectorB.getAngle(testVectorA),angle,
1.0e-6));
+
+ // both set to default
+ angle = 0.0;
+ testVectorA.setValue();
+ testVectorB.setValue();
+ QVERIFY(relativeCompare(testVectorA.getAngle(testVectorB),angle,
1.0e-6));
+ QVERIFY(relativeCompare(testVectorB.getAngle(testVectorA),angle,
1.0e-6));
+}
+
+void Test_Vector2D::Test_Rotate() {
+ Vector2D testVector;
+ double angle;
+ double x;
+ double y;
+ // Parallel vectors
+ angle = 0.0;
+ x = 1.345;
+ y = 2.714;
+ testVector.setValue(x,y);
+ testVector.rotate(angle);
+ QVERIFY(relativeCompare(testVector.getX(),x*cos(angle)-y*sin(angle),
1.0e-6));
+ QVERIFY(relativeCompare(testVector.getY(),x*sin(angle)+y*cos(angle),
1.0e-6));
+
+ // perpendicular vectors
+ angle = 1.570796;
+ x = 1.345;
+ y = 2.714;
+ testVector.setValue(x,y);
+ testVector.rotate(angle);
+ QVERIFY(relativeCompare(testVector.getX(),x*cos(angle)-y*sin(angle),
1.0e-6));
+ QVERIFY(relativeCompare(testVector.getY(),x*sin(angle)+y*cos(angle),
1.0e-6));
+
+ // 180 degrees
+ angle = 3.1415927;
+ x = 1.345;
+ y = 2.714;
+ testVector.setValue(x,y);
+ testVector.rotate(angle);
+ QVERIFY(relativeCompare(testVector.getX(),x*cos(angle)-y*sin(angle),
1.0e-6));
+ QVERIFY(relativeCompare(testVector.getY(),x*sin(angle)+y*cos(angle),
1.0e-6));
+
+ // some positive angle
+ angle = 0.558505;
+ x = 1.345;
+ y = 2.714;
+ testVector.setValue(x,y);
+ testVector.rotate(angle);
+ QVERIFY(relativeCompare(testVector.getX(),x*cos(angle)-y*sin(angle),
1.0e-6));
+ QVERIFY(relativeCompare(testVector.getY(),x*sin(angle)+y*cos(angle),
1.0e-6));
+
+ // some negative angle
+ angle = -0.558505;
+ x = 1.345;
+ y = 2.714;
+ testVector.setValue(x,y);
+ testVector.rotate(angle);
+ QVERIFY(relativeCompare(testVector.getX(),x*cos(angle)-y*sin(angle),
1.0e-6));
+ QVERIFY(relativeCompare(testVector.getY(),x*sin(angle)+y*cos(angle),
1.0e-6));
+
+ // set to default
+ angle = 1.954769;
+ testVector.setValue();
+ testVector.rotate(angle);
+ QVERIFY(relativeCompare(testVector.getX(),0.0, 1.0e-6));
+ QVERIFY(relativeCompare(testVector.getY(),0.0, 1.0e-6));
+}
+
+void Test_Vector2D::Test_GetPoint() {
+ Vector2D vector;
+ Point2D origin;
+ Point2D result;
+ double scalar;
+
+ // simple case
+ vector.setValue(1.0,1.0);
+ origin.setValue(2.0,5.0);
+ scalar = 12.0;
+ result = vector.getPoint(origin, scalar);
+ QVERIFY(relativeCompare(result.getX(),vector.getX()*scalar+origin.getX(),
+ 1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),vector.getY()*scalar+origin.getY(),
+ 1.0e-6));
+
+ // fractional case
+ vector.setValue(10.0,10.0);
+ origin.setValue(17.3,91.4);
+ scalar = 0.5;
+ result = vector.getPoint(origin, scalar);
+ QVERIFY(relativeCompare(result.getX(),vector.getX()*scalar+origin.getX(),
+ 1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),vector.getY()*scalar+origin.getY(),
+ 1.0e-6));
+
+ // negative case
+ vector.setValue(1.0,1.0);
+ vector.normalize();
+ origin.setValue(0.0,0.0);
+ scalar = -1914.1341;
+ result = vector.getPoint(origin, scalar);
+ QVERIFY(relativeCompare(result.getX(),vector.getX()*scalar+origin.getX(),
+ 1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),vector.getY()*scalar+origin.getY(),
+ 1.0e-6));
+
+ // default case
+ vector.setValue();
+ origin.setValue();
+ scalar = 12.0;
+ result = vector.getPoint(origin, scalar);
+ QVERIFY(relativeCompare(result.getX(),0.0, 1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),0.0, 1.0e-6));
+
+}
+
+void Test_Vector2D::Test_IsOnLine() {
+ Vector2D vector;
+ Point2D origin;
+ Point2D testPoint;
+
+ // positive slope
+ vector.setValue(1.0,1.0);
+ origin.setValue(2.0,5.0);
+ testPoint.setValue(4.7,7.7);
+ QVERIFY(vector.isOnLine(origin,testPoint));
+
+ // negative slope
+ vector.setValue(1.0,1.0);
+ origin.setValue(2.0,5.0);
+ testPoint.setValue(-1.3,1.7);
+ QVERIFY(vector.isOnLine(origin,testPoint));
+
+ // not on line
+ vector.setValue(1.0,1.0);
+ origin.setValue(2.0,5.0);
+ testPoint.setValue(4.7,5.7);
+ QVERIFY(!vector.isOnLine(origin,testPoint));
+
+ // same point
+ vector.setValue(1.0,1.0);
+ origin.setValue(2.0,5.0);
+ testPoint.setValue(2.0,5.0);
+ QVERIFY(vector.isOnLine(origin,testPoint));
+
+ // default vector
+ vector.setValue();
+ origin.setValue(2.0,5.0);
+ testPoint.setValue(2.0,5.0);
+ QVERIFY(vector.isOnLine(origin,testPoint));
+}
+
+void Test_Vector2D::Test_GetIntersectingPt() {
+ QFAIL("Not implemented yet!");
+}
void Test_Vector2D::Test_OperatorSet() {
Vector2D testVector;
@@ -449,6 +638,359 @@
QVERIFY(testVector != testVectorB);
QVERIFY(!(testVector != testVectorC));
}
+
+void Test_Vector2D::Test_OperatorScalarMultiplyEqual() {
+ Vector2D testVector;
+ double scalar;
+ double x;
+ double y;
+
+ // simple case
+ x = 17.234;
+ y = 1.1091;
+ scalar = 0.9324;
+ testVector.setValue(x,y);
+ testVector *= scalar;
+ QVERIFY(relativeCompare(testVector.getX(),x*scalar,1.0e-6));
+ QVERIFY(relativeCompare(testVector.getY(),y*scalar,1.0e-6));
+
+ // scalar is 0.0
+ x = 17.234;
+ y = 1.1091;
+ scalar = 0.0;
+ testVector.setValue(x,y);
+ testVector *= scalar;
+ QVERIFY(relativeCompare(testVector.getX(),0.0,1.0e-6));
+ QVERIFY(relativeCompare(testVector.getY(),0.0,1.0e-6));
+
+ // vector is default
+ scalar = 0.9324;
+ testVector.setValue();
+ testVector *= scalar;
+ QVERIFY(relativeCompare(testVector.getX(),0.0,1.0e-6));
+ QVERIFY(relativeCompare(testVector.getY(),0.0,1.0e-6));
+}
+
+void Test_Vector2D::Test_OperatorScalarMultiply() {
+ Vector2D testVector;
+ Vector2D result;
+ double scalar;
+ double x;
+ double y;
+
+ // Test V * S
+ // simple case
+ x = 17.234;
+ y = 1.1091;
+ scalar = 0.9324;
+ testVector.setValue(x,y);
+ result = testVector * scalar;
+ QVERIFY(relativeCompare(result.getX(),x*scalar,1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),y*scalar,1.0e-6));
+
+ // scalar is 0.0
+ x = 17.234;
+ y = 1.1091;
+ scalar = 0.0;
+ testVector.setValue(x,y);
+ result = testVector * scalar;
+ QVERIFY(relativeCompare(result.getX(),x*scalar,1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),y*scalar,1.0e-6));
+
+ // vector is default
+ scalar = 0.9324;
+ testVector.setValue();
+ result = testVector * scalar;
+ QVERIFY(relativeCompare(result.getX(),0.0,1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),0.0,1.0e-6));
+
+ // Test S * V
+ // simple case
+ x = -0.9134;
+ y = 21.234;
+ scalar = 17.143;
+ testVector.setValue(x,y);
+ result = scalar * testVector;
+ QVERIFY(relativeCompare(result.getX(),x*scalar,1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),y*scalar,1.0e-6));
+
+ // scalar is 0.0
+ x = -0.9134;
+ y = 21.234;
+ scalar = 0.0;
+ testVector.setValue(x,y);
+ result = scalar * testVector;
+ QVERIFY(relativeCompare(result.getX(),x*scalar,1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),y*scalar,1.0e-6));
+
+ // vector is default
+ scalar = 17.143;
+ testVector.setValue();
+ result = scalar * testVector;
+ QVERIFY(relativeCompare(result.getX(),0.0,1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),0.0,1.0e-6));
+}
+
+void Test_Vector2D::Test_OperatorScalarDivideEqual() {
+ Vector2D testVector;
+ double scalar;
+ double x;
+ double y;
+
+ // simple case
+ x = 17.234;
+ y = 1.1091;
+ scalar = 0.9324;
+ testVector.setValue(x,y);
+ testVector /= scalar;
+ QVERIFY(relativeCompare(testVector.getX(),x/scalar,1.0e-6));
+ QVERIFY(relativeCompare(testVector.getY(),y/scalar,1.0e-6));
+
+ // scalar is 0.0
+ x = 17.234;
+ y = 1.1091;
+ scalar = 0.0;
+ testVector.setValue(x,y);
+ testVector /= scalar;
+ QVERIFY(testVector.getX() == x/scalar);
+ QVERIFY(testVector.getY() == y/scalar);
+
+ // vector is default
+ scalar = 0.9324;
+ testVector.setValue();
+ testVector /= scalar;
+ QVERIFY(relativeCompare(testVector.getX(),0.0,1.0e-6));
+ QVERIFY(relativeCompare(testVector.getY(),0.0,1.0e-6));
+}
+
+void Test_Vector2D::Test_OperatorScalarDivision() {
+ Vector2D testVector;
+ Vector2D result;
+ double scalar;
+ double x;
+ double y;
+
+ // simple case
+ x = 17.234;
+ y = 1.1091;
+ scalar = 0.9324;
+ testVector.setValue(x,y);
+ result = testVector / scalar;
+ QVERIFY(relativeCompare(result.getX(),x/scalar,1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),y/scalar,1.0e-6));
+
+ // scalar is 0.0
+ x = 17.234;
+ y = 1.1091;
+ scalar = 0.0;
+ testVector.setValue(x,y);
+ result = testVector / scalar;
+ QVERIFY(testVector.getX() == x/scalar);
+ QVERIFY(testVector.getY() == y/scalar);
+
+ // vector is default
+ scalar = 0.9324;
+ testVector.setValue();
+ result = testVector / scalar;
+ QVERIFY(relativeCompare(result.getX(),0.0,1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),0.0,1.0e-6));
+}
+
+void Test_Vector2D::Test_VectorAddEqual() {
+ Vector2D testVectorA;
+ Vector2D testVectorB;
+ double x;
+ double y;
+
+ // simple case
+ x = 1.7324;
+ y = 9.1534;
+ testVectorA.setValue(x,y);
+ testVectorB.setValue(0.8234,17.2341);
+ testVectorA += testVectorB;
+ QVERIFY(relativeCompare(testVectorA.getX(),testVectorB.getX()+x,1.0e-6));
+ QVERIFY(relativeCompare(testVectorA.getY(),testVectorB.getY()+y,1.0e-6));
+
+ // rhs is default
+ x = 1.7324;
+ y = 9.1534;
+ testVectorA.setValue(x,y);
+ testVectorB.setValue();
+ testVectorA += testVectorB;
+ QVERIFY(relativeCompare(testVectorA.getX(),x,1.0e-6));
+ QVERIFY(relativeCompare(testVectorA.getY(),y,1.0e-6));
+
+ // lhs is default
+ testVectorA.setValue();
+ testVectorB.setValue(0.8234,17.2341);
+ testVectorA += testVectorB;
+ QVERIFY(relativeCompare(testVectorA.getX(),testVectorB.getX(),1.0e-6));
+ QVERIFY(relativeCompare(testVectorA.getY(),testVectorB.getY(),1.0e-6));
+}
+
+void Test_Vector2D::Test_VectorAddition() {
+ Vector2D testVectorA;
+ Vector2D testVectorB;
+ Vector2D result;
+ double x;
+ double y;
+
+ // simple case
+ x = 1.7324;
+ y = 9.1534;
+ testVectorA.setValue(x,y);
+ testVectorB.setValue(0.8234,17.2341);
+ result = testVectorA + testVectorB;
+ QVERIFY(relativeCompare(result.getX(),x+testVectorB.getX(),1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),y+testVectorB.getY(),1.0e-6));
+
+ // rhs is default
+ x = 1.7324;
+ y = 9.1534;
+ testVectorA.setValue(x,y);
+ testVectorB.setValue();
+ result = testVectorA + testVectorB;
+ QVERIFY(relativeCompare(result.getX(),x+testVectorB.getX(),1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),y+testVectorB.getY(),1.0e-6));
+
+ // lhs is default
+ testVectorA.setValue();
+ testVectorB.setValue(0.8234,17.2341);
+ result = testVectorA + testVectorB;
+ QVERIFY(relativeCompare(result.getX(),0.0+testVectorB.getX(),1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),0.0+testVectorB.getY(),1.0e-6));
+}
+
+void Test_Vector2D::Test_VectorSubEqual() {
+ Vector2D testVectorA;
+ Vector2D testVectorB;
+ Vector2D result;
+ double x;
+ double y;
+
+ // simple case
+ x = 1.7324;
+ y = 9.1534;
+ testVectorA.setValue(x,y);
+ testVectorB.setValue(0.8234,17.2341);
+ testVectorA -= testVectorB;
+ QVERIFY(relativeCompare(testVectorA.getX(),x-testVectorB.getX(),1.0e-6));
+ QVERIFY(relativeCompare(testVectorA.getY(),y-testVectorB.getY(),1.0e-6));
+
+ // rhs is default
+ x = 1.7324;
+ y = 9.1534;
+ testVectorA.setValue(x,y);
+ testVectorB.setValue();
+ testVectorA -= testVectorB;
+ QVERIFY(relativeCompare(testVectorA.getX(),x-testVectorB.getX(),1.0e-6));
+ QVERIFY(relativeCompare(testVectorA.getY(),y-testVectorB.getY(),1.0e-6));
+
+ // lhs is default
+ testVectorA.setValue();
+ testVectorB.setValue(0.8234,17.2341);
+ testVectorA -= testVectorB;
+
QVERIFY(relativeCompare(testVectorA.getX(),0.0-testVectorB.getX(),1.0e-6));
+
QVERIFY(relativeCompare(testVectorA.getY(),0.0-testVectorB.getY(),1.0e-6));
+}
+
+void Test_Vector2D::Test_VectorSubtraction() {
+ Vector2D testVectorA;
+ Vector2D testVectorB;
+ Vector2D result;
+ double x;
+ double y;
+
+ // simple case
+ x = 1.7324;
+ y = 9.1534;
+ testVectorA.setValue(x,y);
+ testVectorB.setValue(0.8234,17.2341);
+ result = testVectorA - testVectorB;
+ QVERIFY(relativeCompare(result.getX(),x-testVectorB.getX(),1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),y-testVectorB.getY(),1.0e-6));
+
+ // rhs is default
+ x = 1.7324;
+ y = 9.1534;
+ testVectorA.setValue(x,y);
+ testVectorB.setValue();
+ result = testVectorA - testVectorB;
+ QVERIFY(relativeCompare(result.getX(),x-testVectorB.getX(),1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),y-testVectorB.getY(),1.0e-6));
+
+ // lhs is default
+ testVectorA.setValue();
+ testVectorB.setValue(0.8234,17.2341);
+ result = testVectorA - testVectorB;
+ QVERIFY(relativeCompare(result.getX(),0.0-testVectorB.getX(),1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),0.0-testVectorB.getY(),1.0e-6));
+}
+
+void Test_Vector2D::Test_PointVectorAddition() {
+ Point2D p;
+ Point2D result;
+ Vector2D v;
+
+ // Test_GetPoint() tests most of the functionality...
+
+ // P+V case
+ p.setValue(27.123, 191.143);
+ v.setValue(13.2341, 17.0981);
+ result = p+v;
+ QVERIFY(relativeCompare(result.getX(),p.getX()+v.getX(), 1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),p.getY()+v.getY(), 1.0e-6));
+
+ // V+P case
+ p.setValue(0.324, -0.4231);
+ v.setValue(1.723, 9.2341);
+ result = v+p;
+ QVERIFY(relativeCompare(result.getX(),p.getX()+v.getX(), 1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),p.getY()+v.getY(), 1.0e-6));
+}
+
+void Test_Vector2D::Test_PointVectorSubtraction() {
+ Point2D p;
+ Point2D result;
+ Vector2D v;
+
+ // Test_GetPoint() tests most of the functionality...
+
+ // P-V case
+ p.setValue(27.123, 191.143);
+ v.setValue(13.2341, 17.0981);
+ result = p-v;
+ QVERIFY(relativeCompare(result.getX(),p.getX()-v.getX(), 1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),p.getY()-v.getY(), 1.0e-6));
+
+}
+
+void Test_Vector2D::Test_PointSubtraction() {
+ Point2D a;
+ Point2D b;
+ Vector2D result;
+
+ // positive case
+ a.setValue(1.4, 5.7);
+ b.setValue(6.7, 23.9);
+ result = b - a;
+ QVERIFY(relativeCompare(result.getX(),b.getX()-a.getX(), 1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),b.getY()-a.getY(), 1.0e-6));
+
+ // negative case
+ a.setValue(6.7, 23.9);
+ b.setValue(1.4, 5.7);
+ result = b - a;
+ QVERIFY(relativeCompare(result.getX(),b.getX()-a.getX(), 1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),b.getY()-a.getY(), 1.0e-6));
+
+ // both defaults case
+ a.setValue();
+ b.setValue();
+ result = b - a;
+ QVERIFY(relativeCompare(result.getX(),b.getX()-a.getX(), 1.0e-6));
+ QVERIFY(relativeCompare(result.getY(),b.getY()-a.getY(), 1.0e-6));
+}
void Test_Vector2D::Test_OperatorOstream() {
double xVal;
@@ -489,158 +1031,3 @@
QVERIFY(testStrB == controlStrB);
}
-#ifdef __NEEDS_DEBUGGING__
-
-void Test_Vector2D::Test_OperatorMultiply() {
- double xVal = 5.4;
- double yVal = 7.2;
- double mul;
- Vector2D testVector(xVal, yVal);
-
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // Positive number
- mul = 4.91;
- testVector = testVector * mul;
- xVal *= mul;
- yVal *= mul;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // Negative number
- mul = -0.15;
- testVector = testVector * mul;
- xVal *= mul;
- yVal *= mul;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // Zero
- mul = 0.0;
- testVector = testVector * mul;
- xVal *= mul;
- yVal *= mul;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-}
-
-void Test_Vector2D::Test_OperatorDivide() {
- double xVal = 32.149;
- double yVal = 91.43;
- double div;
- Vector2D testVector(xVal, yVal);
-
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // Positive number
- div = 0.7291;
- testVector = testVector / div;
- xVal /= div;
- yVal /= div;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // Negative number
- div = -15.941;
- testVector = testVector / div;
- xVal /= div;
- yVal /= div;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // One
- div = 1.0;
- testVector = testVector / div;
- xVal /= div;
- yVal /= div;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // Zero
- div = 0.0;
- testVector = testVector / div;
- xVal /= div;
- yVal /= div;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-}
-
-void Test_Vector2D::Test_OperatorMultiplyEqual() {
- double xVal = 1.19;
- double yVal = 910.14;
- double mul;
- Vector2D testVector(xVal, yVal);
-
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // Positive number
- mul = 0.1234613;
- testVector *= mul;
- xVal *= mul;
- yVal *= mul;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // Negative number
- mul = -7234.19;
- testVector *= mul;
- xVal *= mul;
- yVal *= mul;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // Zero
- mul = 0.0;
- testVector *= mul;
- xVal *= mul;
- yVal *= mul;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-}
-
-void Test_Vector2D::Test_OperatorDivideEqual() {
- double xVal = 12.1;
- double yVal = 0.7143;
- double div;
- Vector2D testVector(xVal, yVal);
-
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // Positive number
- div = 71.45;
- testVector /= div;
- xVal /= div;
- yVal /= div;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // Negative number
- div = -0.941613;
- testVector /= div;
- xVal /= div;
- yVal /= div;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // One
- div = 1.0;
- testVector /= div;
- xVal /= div;
- yVal /= div;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-
- // Zero
- div = 0.0;
- testVector /= div;
- xVal /= div;
- yVal /= div;
- QVERIFY(testVector.getX() == xVal);
- QVERIFY(testVector.getY() == yVal);
-}
-#endif
-
=======================================
--- /src/common/utility/unit_tests/Test_Vector2D.h Mon Feb 8 02:40:30 2010
UTC
+++ /src/common/utility/unit_tests/Test_Vector2D.h Thu Feb 11 02:19:00 2010
UTC
@@ -46,16 +46,26 @@
void Test_Dot();
void Test_IsParallelTo();
void Test_IsNormalTo();
+ void Test_GetAngle();
+ void Test_Rotate();
+ void Test_GetPoint();
+ void Test_IsOnLine();
+ void Test_GetIntersectingPt();
void Test_OperatorSet();
void Test_OperatorEqual();
void Test_OperatorNotEqual();
- /*
- void Test_OperatorMultiply();
- void Test_OperatorDivide();
- void Test_OperatorMultiplyEqual();
- void Test_OperatorDivideEqual();
- */
+ void Test_OperatorScalarMultiplyEqual();
+ void Test_OperatorScalarMultiply();
+ void Test_OperatorScalarDivideEqual();
+ void Test_OperatorScalarDivision();
+ void Test_VectorAddEqual();
+ void Test_VectorAddition();
+ void Test_VectorSubEqual();
+ void Test_VectorSubtraction();
+ void Test_PointVectorAddition();
+ void Test_PointVectorSubtraction();
+ void Test_PointSubtraction();
void Test_OperatorOstream();
private:
==============================================================================
Revision: ee3dfa30733e
Author: Jeff Backus <
jeff....@gmail.com>
Date: Sat Feb 13 23:17:14 2010 UTC
Log: Finished Vector2D tests and debugging.
http://code.google.com/p/idlescreen/source/detail?r=ee3dfa30733e
Modified:
/src/common/unit_tests/unit_tests_main.cpp
/src/common/utility/Point2D.cpp
/src/common/utility/Vector2D.cpp
/src/common/utility/Vector2D.h
/src/common/utility/unit_tests/Test_Vector2D.cpp
/src/common/utility/unit_tests/Test_Vector2D.h
=======================================
--- /src/common/unit_tests/unit_tests_main.cpp Mon Feb 8 02:40:30 2010 UTC
+++ /src/common/unit_tests/unit_tests_main.cpp Sat Feb 13 23:17:14 2010 UTC
@@ -1,3 +1,6 @@
+#include <iostream>
+using namespace std;
+
#include <QtTest/QtTest>
#include <QList>
#include "utility/unit_tests/Test_MiscFuncs.h"
@@ -31,5 +34,6 @@
}
}
+ cout<<"=---> Total Tests Failed: "<<retVal<<endl;
return retVal;
}
=======================================
--- /src/common/utility/Point2D.cpp Mon Feb 8 02:40:30 2010 UTC
+++ /src/common/utility/Point2D.cpp Sat Feb 13 23:17:14 2010 UTC
@@ -117,8 +117,8 @@
}
bool Point2D::operator==(const Point2D& other) {
- return (relativeCompare(1.0+_x, 1.0+other._x, _epsilon) &&
- relativeCompare(1.0+_y,1.0+other._y, _epsilon));
+ return (relativeCompare(_x, other._x, _epsilon) &&
+ relativeCompare(_y,other._y, _epsilon));
}
bool Point2D::operator!=(const Point2D& other) {
return !(*this == other);
=======================================
--- /src/common/utility/Vector2D.cpp Thu Feb 11 02:19:00 2010 UTC
+++ /src/common/utility/Vector2D.cpp Sat Feb 13 23:17:14 2010 UTC
@@ -7,7 +7,7 @@
/**
* Sets the default epsilon value.
*/
-void Vector2D::setDefaultEpsilon(const double& epsilon) {
+void Vector2D::setDefaultEpsilon(const double epsilon) {
DEFAULT_EPSILON = epsilon;
}
@@ -21,7 +21,7 @@
/**
* Sets the epsilon value for this object.
*/
-void Vector2D::setEpsilon(const double &epsilon) {
+void Vector2D::setEpsilon(const double epsilon) {
_epsilon = epsilon;
}
@@ -132,7 +132,7 @@
/**
* Returns the dot product of the specified vector with this vector.
*/
-double Vector2D::dot(const Vector2D other) {
+double Vector2D::dot(const Vector2D& other) {
return (_x*other._x+_y*other._y);
}
@@ -140,7 +140,7 @@
/**
* Returns true if the specified vector is parallel to this vector.
*/
-bool Vector2D::isParallelTo(const Vector2D other) {
+bool Vector2D::isParallelTo(const Vector2D& other) {
Vector2D thisUnitV = *this;
Vector2D otherUnitV = other;
thisUnitV.normalize();
@@ -158,7 +158,7 @@
/**
* Returns true if the specified vector is normal to this vector.
*/
-bool Vector2D::isNormalTo(const Vector2D other) {
+bool Vector2D::isNormalTo(const Vector2D& other) {
Vector2D thisV = *this;
Vector2D otherNormV = other;
@@ -181,7 +181,7 @@
* If one or both of the vectors has a length of zero, a value of
* 0.0 is returned.
*/
-double Vector2D::getAngle(const Vector2D other) {
+double Vector2D::getAngle(const Vector2D& other) {
// we know that mag(v1)*mag(v2)*cos(theta)=normal(v1) dot v2
// thus theta = arccos( (normal(v1) dot v2) / ( mag(v1)*mag(v2) ) )
@@ -217,13 +217,43 @@
* @param a Origination point.
* @param scalar The amount to scale this vector by first.
*/
-Point2D Vector2D::getPoint(const Point2D a, const double scalar) {
+Point2D Vector2D::getPoint(const Point2D& a, const double scalar) {
Point2D retVal = a;
retVal.setX(retVal.getX()+scalar*_x);
retVal.setY(retVal.getY()+scalar*_y);
return retVal;
}
+
+/**
+ * Calculates the distance from point a to point b. If point b is
+ * not on the line described by this vector and point a, NaN is returned.
+ */
+double Vector2D::getDistanceToPoint(const Point2D& a, const Point2D& b) {
+ Point2D inA = a;
+ Point2D inB = b;
+
+ // check to ensure points aren't the same.
+ if(inA == inB) {
+ return 0.0;
+ }
+
+ // Check to ensure point is on line
+ Vector2D replica = *this;
+ if(replica.isOnLine(inA, inB)) {
+ // use the first dimension that isn't 0.0. If both are, then return
+ // NAN (shouldn't get to that point).
+ if(!relativeCompare(_x, 0.0, _epsilon)) {
+ return (inB.getX()-inA.getX())/_x;
+ } else if(!relativeCompare(_y, 0.0, _epsilon)) {
+ return (inB.getY()-inA.getY())/_y;
+ } else {
+ return NAN;
+ }
+ }
+ // not the same line, return NaN.
+ return NAN;
+}
/**
* Checks to see if point B is on the line specified
@@ -232,7 +262,7 @@
* @param a A point known to be on the line.
* @param b The point to check.
*/
-bool Vector2D::isOnLine(const Point2D a, const Point2D b) {
+bool Vector2D::isOnLine(const Point2D& a, const Point2D& b) {
// check to see if the points are the same. If so, easy peasy!
Point2D copyA = a;
if(copyA == b) {
@@ -241,15 +271,43 @@
// create a replica and ensure that its magnitude isn't 0.0.
Vector2D replica = *this;
+ replica.normalize();
if(relativeCompare(replica.magnitude(),0.0, _epsilon)) {
return true;
}
+
// If the vector from point B to point A is parallel to vector V, then
// point B is on the line.
Vector2D v2;
v2 = b - a;
return replica.isParallelTo(v2);
}
+
+double Vector2D::getIntersectingMul(const Point2D& pA, const Vector2D& vB,
+ const Point2D& pB) {
+
+ Point2D rPA = pA;
+ Point2D rPB = pB;
+ Vector2D rVB = vB;
+ Vector2D rVA = *this;
+
+ // calculate the denominator of the intersect formula. If it is 0,
+ // then the lines are parallel or one or both vectors are undefined.
+ double denom = rVB._y*rVA._x - rVB._x*rVA._y;
+ if(!relativeCompare(denom,0.0, _epsilon)) {
+ // if the points are the same, then return the point.
+ if(rPA == rPB) {
+ return 0.0;
+ } else {
+ // otherwise, calculate the intersection point.
+ double numer = rVB._x*(rPA.getY() - rPB.getY()) -
+ rVB._y*(rPA.getX() - rPB.getX());
+ return (numer / denom);
+ }
+ }
+ // lines are parallel or vectors are undefined.
+ return NAN;
+}
/**
* Finds the point of intersection of the line specified
@@ -266,19 +324,21 @@
* @param result The resulting point.
* @return True if the lines intersect, false if they do not.
*/
-bool Vector2D::getIntersectingPt(const Point2D pA, const Vector2D vB,
- const Point2D pB, Point2D& result) {
+bool Vector2D::getIntersectingPt(const Point2D& pA, const Vector2D& vB,
+ const Point2D& pB, Point2D& result) {
+
+ double mul = getIntersectingMul(pA, vB, pB);
- Point2D rPA = pA;
- Point2D rPB = pB;
- Vector2D rVB = vB;
- double numer = rVB._x*(rPB.getY() - rPA.getY()) -
- rVB._y*(rPB.getX() - rPA.getX());
- double denom = rVB._y*_x - rVB._x*_y;
- if(denom != 0) {
- Vector2D vF = (*this) * (numer / denom);
- result = rPA + vF;
+ if(!isnan(mul)) {
+ Vector2D rV = *this;
+ rV *= mul;
+ result = pA;
+ result = pA + rV;
+ return true;
}
+
+ result.setX(NAN);
+ result.setY(NAN);
return false;
}
=======================================
--- /src/common/utility/Vector2D.h Thu Feb 11 02:19:00 2010 UTC
+++ /src/common/utility/Vector2D.h Sat Feb 13 23:17:14 2010 UTC
@@ -101,17 +101,17 @@
/**
* Returns the dot product of the specified vector with this vector.
*/
- double dot(const Vector2D other);
+ double dot(const Vector2D& other);
/**
* Returns true if the specified vector is parallel to this vector.
*/
- bool isParallelTo(const Vector2D other);
+ bool isParallelTo(const Vector2D& other);
/**
* Returns true if the specified vector is normal to this vector.
*/
- bool isNormalTo(const Vector2D other);
+ bool isNormalTo(const Vector2D& other);
/**
* Calculates the angle between the specified vector and this vector.
@@ -119,7 +119,7 @@
* If one or both of the vectors has a length of zero, a value of
* 0.0 is returned.
*/
- double getAngle(const Vector2D other);
+ double getAngle(const Vector2D& other);
/**
* Rotates the vector by the angle radians.
@@ -134,7 +134,13 @@
* @param a Origination point.
* @param scalar The amount to scale this vector by first.
*/
- Point2D getPoint(const Point2D a, const double scalar=1.0);
+ Point2D getPoint(const Point2D& a, const double scalar=1.0);
+
+ /**
+ * Calculates the distance from point a to point b. If point b is
+ * not on the line described by this vector and point a, NaN is returned.
+ */
+ double getDistanceToPoint(const Point2D& a, const Point2D& b);
/**
* Checks to see if point B is on the line specified
@@ -143,12 +149,42 @@
* @param a A point known to be on the line.
* @param b The point to check.
*/
- bool isOnLine(const Point2D a, const Point2D b);
+ bool isOnLine(const Point2D& a, const Point2D& b);
+
+ /**
+ * Finds the point of intersection of the line specified
+ * by this vector and point A and the line specified by
+ * vector V2 and point B. Returns false if the lines
+ * do not intersect. The resulting point is put into result.
+ *
+ * @param a A point on the line specified by this vector.
+ * @param v2 The vector describing the other line.
+ * @param b A point on the line described by vector v.
+ * @param result The resulting point.
+ * @return the multiplier, or NAN if lines don't intersect.
+ */
+ double getIntersectingMul(const Point2D& pA, const Vector2D& vB,
+ const Point2D& pB);
+
+ /**
+ * Finds the point of intersection of the line specified
+ * by this vector and point A and the line specified by
+ * vector V2 and point B. Returns false if the lines
+ * do not intersect. The resulting point is put into result.
+ *
+ * @param a A point on the line specified by this vector.
+ * @param v2 The vector describing the other line.
+ * @param b A point on the line described by vector v.
+ * @param result The resulting point.
+ * @return True if the lines intersect, false if they do not.
+ */
+ bool getIntersectingPt(const Point2D& pA, const Vector2D& vB,
+ const Point2D& pB, Point2D& result);
/**
* Sets the default epsilon value.
*/
- static void setDefaultEpsilon(const double& epsilon);
+ static void setDefaultEpsilon(const double epsilon);
/**
* Gets the default epsilon value.
@@ -158,7 +194,7 @@
/**
* Sets the epsilon value for this object.
*/
- void setEpsilon(const double &epsilon);
+ void setEpsilon(const double epsilon);
/**
* Gets the epsilon value for this object.
@@ -169,21 +205,6 @@
bool operator==(const Vector2D& other);
bool operator!=(const Vector2D& other);
- /**
- * Finds the point of intersection of the line specified
- * by this vector and point A and the line specified by
- * vector V2 and point B. Returns false if the lines
- * do not intersect. The resulting point is put into result.
- *
- * @param a A point on the line specified by this vector.
- * @param v2 The vector describing the other line.
- * @param b A point on the line described by vector v.
- * @param result The resulting point.
- * @return True if the lines intersect, false if they do not.
- */
- bool getIntersectingPt(const Point2D pA, const Vector2D vB,
- const Point2D pB, Point2D& result);
-
Vector2D& operator*(const double val);
Vector2D& operator*=(const double val);
Vector2D& operator/(const double val);
=======================================
--- /src/common/utility/unit_tests/Test_Vector2D.cpp Thu Feb 11 02:19:00
2010 UTC
+++ /src/common/utility/unit_tests/Test_Vector2D.cpp Sat Feb 13 23:17:14
2010 UTC
@@ -534,6 +534,46 @@
QVERIFY(relativeCompare(result.getY(),0.0, 1.0e-6));
}
+
+void Test_Vector2D::Test_GetDistanceToPoint() {
+ Vector2D vector;
+ Point2D origin;
+ Point2D testPoint;
+
+ // positive slope, point on line
+ vector.setValue(1.0,1.0);
+ origin.setValue(2.0,5.0);
+ testPoint.setValue(5.3,8.3);
+ QVERIFY(relativeCompare(vector.getDistanceToPoint(origin, testPoint),
+ 3.3, 1e-6));
+
+ // positive slope, point not on line
+ vector.setValue(1.0,1.0);
+ origin.setValue(2.0,5.0);
+ testPoint.setValue(5.3,7.3);
+ QVERIFY(isnan(vector.getDistanceToPoint(origin, testPoint)));
+
+ // vertical vector
+ vector.setValue(4.0,0.0);
+ origin.setValue(2.0,5.0);
+ testPoint.setValue(0.3,5.0);
+ QVERIFY(relativeCompare(vector.getDistanceToPoint(origin, testPoint),
+ -1.7/4.0, 1e-6));
+
+ // horizontal vector
+ vector.setValue(0.0,1.7);
+ origin.setValue(7.1,5.0);
+ testPoint.setValue(7.1,8.3);
+ QVERIFY(relativeCompare(vector.getDistanceToPoint(origin, testPoint),
+ 3.3/1.7, 1e-6));
+
+ // default vector
+ // positive slope, point on line
+ vector.setValue();
+ origin.setValue(2.0,5.0);
+ testPoint.setValue(5.3,8.3);
+ QVERIFY(isnan(vector.getDistanceToPoint(origin, testPoint)));
+}
void Test_Vector2D::Test_IsOnLine() {
Vector2D vector;
@@ -571,8 +611,104 @@
QVERIFY(vector.isOnLine(origin,testPoint));
}
-void Test_Vector2D::Test_GetIntersectingPt() {
- QFAIL("Not implemented yet!");
+void Test_Vector2D::Test_Intersections() {
+ Vector2D vA;
+ Vector2D vB;
+ Point2D pA;
+ Point2D pB;
+ Point2D pI;
+ bool bResult;
+
+ // 60 degree case, multiplier
+ vA.setValue(1.0,1.0);
+ pA.setValue(2.0,3.0);
+ vB.setValue(1.0,1.0);
+ vB.rotate(1.047198);
+ pB.setValue(-4.0,5.0);
+ bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ QVERIFY(relativeCompare(vA.getIntersectingMul(pA, vB, pB),-4.3093987,
1e-6));
+
+ // Normal case
+ vA.setValue(1.0,1.0);
+ pA.setValue(2.0,3.0);
+ vB.setValue(-1.0,1.0);
+ pB.setValue(-4.0,1.0);
+ bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ QVERIFY(bResult);
+ QVERIFY(relativeCompare(pI.getX(),-2.0, 1e-6));
+ QVERIFY(relativeCompare(pI.getY(),-1.0, 1e-6));
+
+ // Parallel case
+ vA.setValue(1.0,2.0);
+ pA.setValue(4.0,1.0);
+ vB.setValue(8.0,16.0);
+ pB.setValue(17.0,15.0);
+ bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ QVERIFY(!bResult);
+ QVERIFY(isnan(pI.getX()));
+ QVERIFY(isnan(pI.getY()));
+
+ // Normal case, same point
+ vA.setValue(1.0,4.0);
+ pA.setValue(7.0,9.0);
+ vB.setValue(-4.0,1.0);
+ pB.setValue(7.0,9.0);
+ bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ QVERIFY(bResult);
+ QVERIFY(relativeCompare(pI.getX(),7.0, 1e-6));
+ QVERIFY(relativeCompare(pI.getY(),9.0, 1e-6));
+
+ // Parallel case, same point
+ vA.setValue(1.0,1.0);
+ pA.setValue(2.0,3.0);
+ vB.setValue(1.0,1.0);
+ pB.setValue(-4.0,5.0);
+ bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ QVERIFY(!bResult);
+ QVERIFY(isnan(pI.getX()));
+ QVERIFY(isnan(pI.getY()));
+
+ // 60 degree case
+ vA.setValue(1.0,1.0);
+ pA.setValue(2.0,3.0);
+ vB.setValue(1.0,1.0);
+ vB.rotate(1.047198);
+ pB.setValue(-4.0,5.0);
+ bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ QVERIFY(bResult);
+ QVERIFY(relativeCompare(pI.getX(),-2.3093987, 1e-6));
+ QVERIFY(relativeCompare(pI.getY(),-1.3093987, 1e-6));
+
+ // 60 degree case, same point
+ vA.setValue(1.0,1.0);
+ pA.setValue(2.0,3.0);
+ vB.setValue(1.0,1.0);
+ vB.rotate(1.047198);
+ pB.setValue(2.0,3.0);
+ bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ QVERIFY(bResult);
+ QVERIFY(relativeCompare(pI.getX(),2.0, 1e-6));
+ QVERIFY(relativeCompare(pI.getY(),3.0, 1e-6));
+
+ // first vector is default
+ vA.setValue();
+ pA.setValue(2.0,3.0);
+ vB.setValue(-1.0,1.0);
+ pB.setValue(-4.0,5.0);
+ bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ QVERIFY(!bResult);
+ QVERIFY(isnan(pI.getX()));
+ QVERIFY(isnan(pI.getY()));
+
+ // second vector is default
+ vA.setValue(1.7,4.9);
+ pA.setValue(2.0,3.0);
+ vB.setValue();
+ pB.setValue(-4.0,5.0);
+ bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ QVERIFY(!bResult);
+ QVERIFY(isnan(pI.getX()));
+ QVERIFY(isnan(pI.getY()));
}
void Test_Vector2D::Test_OperatorSet() {
=======================================
--- /src/common/utility/unit_tests/Test_Vector2D.h Thu Feb 11 02:19:00 2010
UTC
+++ /src/common/utility/unit_tests/Test_Vector2D.h Sat Feb 13 23:17:14 2010
UTC
@@ -49,8 +49,9 @@
void Test_GetAngle();
void Test_Rotate();
void Test_GetPoint();
+ void Test_GetDistanceToPoint();
void Test_IsOnLine();
- void Test_GetIntersectingPt();
+ void Test_Intersections();
void Test_OperatorSet();
void Test_OperatorEqual();
==============================================================================
Revision: 4d296da626db
Author: Jeff Backus <
jeff....@gmail.com>
Date: Sat Feb 20 16:25:28 2010 UTC
Log: More work on SpiralLenz. The current algorithm looks ok. Need
to change
it back to the "concentric rings" approach, with some modifications.
http://code.google.com/p/idlescreen/source/detail?r=4d296da626db
Modified:
/src/SpiralLenz/project_files/SpiralLenz_glut.pro
/src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp
/src/common/spirals/NgonSpiralAlgorithm.cpp
/src/common/spirals/NgonSpiralAlgorithm.h
/src/common/utility/Vector2D.cpp
/src/common/utility/Vector2D.h
/src/common/utility/unit_tests/Test_Vector2D.cpp
=======================================
--- /src/SpiralLenz/project_files/SpiralLenz_glut.pro Sun Feb 7 22:05:58
2010 UTC
+++ /src/SpiralLenz/project_files/SpiralLenz_glut.pro Sat Feb 20 16:25:28
2010 UTC
@@ -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
@@ -30,6 +30,8 @@
SOURCES +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidgetItem.cpp
SOURCES +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidgetSplitDlg.cpp
SOURCES += $$COMMON_PATH/IndexedPalette/IndexedPaletteProfile.cpp
+SOURCES += $$COMMON_PATH/utility/Vector2D.cpp
+SOURCES += $$COMMON_PATH/utility/Point2D.cpp
SOURCES += $$COMMON_PATH/utility/misc_funcs.cpp
SOURCES += $$COMMON_PATH/utility/ImportExportDialog.cpp
SOURCES += $$COMMON_PATH/utility/HelpDialog.cpp
@@ -63,7 +65,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
@@ -74,6 +76,8 @@
HEADERS +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidgetItem.h
HEADERS +=
$$COMMON_PATH/IndexedPalette/IndexedPaletteEditorTableWidgetSplitDlg.h
HEADERS += $$COMMON_PATH/IndexedPalette/IndexedPaletteProfile.h
+HEADERS += $$COMMON_PATH/utility/Vector2D.h
+HEADERS += $$COMMON_PATH/utility/Point2D.h
HEADERS += $$COMMON_PATH/utility/misc_funcs.h
HEADERS += $$COMMON_PATH/utility/ImportExportDialog.h
HEADERS += $$COMMON_PATH/utility/HelpDialog.h
=======================================
--- /src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp Sun Feb 7
22:05:58 2010 UTC
+++ /src/SpiralLenz/src/RectangularSpiralBackgroundProfile.cpp Sat Feb 20
16:25:28 2010 UTC
@@ -37,7 +37,7 @@
// begin tmp
// modified 02/06/10 to get back on track..
-//#include "spirals/NgonSpiralAlgorithm.h"
+#include "spirals/NgonSpiralAlgorithm.h"
#include "spirals/RectangularSpiralAlgorithm.h"
// end mod
#include "spirals/PolarSpiralAlgorithm.h"
@@ -263,16 +263,16 @@
new PolarSpiralAlgorithm(_colorWidth,_emptyWidth,_bConstantColor,
_bRandomColor, _bIncrementColor);
*/
- /*
+
NgonSpiralAlgorithm* alg =
- new NgonSpiralAlgorithm(0,_colorWidth,_emptyWidth,_bConstantColor,
+ new NgonSpiralAlgorithm(4,_colorWidth*3,_emptyWidth*2,_bConstantColor,
_bRandomColor, _bIncrementColor);
- */
+ /*
RectangularSpiralAlgorithm* alg =
new RectangularSpiralAlgorithm(_colorWidth,_emptyWidth,_bConstantColor,
_bRandomColor, _bIncrementColor);
-
+ */
if(alg == NULL)
return NULL;
=======================================
--- /src/common/spirals/NgonSpiralAlgorithm.cpp Sun Aug 2 18:49:07 2009 UTC
+++ /src/common/spirals/NgonSpiralAlgorithm.cpp Sat Feb 20 16:25:28 2010 UTC
@@ -19,32 +19,30 @@
_bConstantColor = true;
_bRandomColor = false;
_bIncrementColor = true;
-
- // internals
- _nextIdx = 0;
- _currX = 0.0;
- _currY = 0.0;
- _rCoeff = 0.0;
- _currR = 0.0;
- _currTheta = 0.0;
- _maxR = 0.0;
-
- // misc constants
_maxFieldIdx = 0;
- _screenXOffset = 0;
- _screenYOffset = 0;
+
+ _origin.setValue(0,0);
+ _axes = NULL;
+ _curAxis = -1;
+ _ringNum = -1;
+ _lineWidth = -1.0;
+ _bevelAngle = 0.0;
+ _bevelLength = 0.0;
+ _curColorIdx = 0;
+ _curColorCount = 0.0;
+ _growLength = 0.0;
}
- /**
- * Constructor takes initialization parameters.
- * @param N the number of sides the Ngon has. N=0 for a polar spiral.
- * @param colorWidth the width of the strip of color.
- * @param emptyWidth the width of the default color region.
- * @param bConstantColor whether or not to hold the color index constant.
- * @param bRandomColor whether or not the initial color is randomly
selected.
- * @param bIncrementColor whether to increment the color as it spirals
out.
- * @see calc()
- */
+/**
+ * Constructor takes initialization parameters.
+ * @param N the number of sides the Ngon has. N=0 for a polar spiral.
+ * @param colorWidth the width of the strip of color.
+ * @param emptyWidth the width of the default color region.
+ * @param bConstantColor whether or not to hold the color index constant.
+ * @param bRandomColor whether or not the initial color is randomly
selected.
+ * @param bIncrementColor whether to increment the color as it spirals out.
+ * @see calc()
+ */
NgonSpiralAlgorithm::NgonSpiralAlgorithm(const int N, const int colorWidth,
const int emptyWidth,
const bool bConstantColor,
@@ -53,18 +51,15 @@
// empty constants until initialize(...) is called
_maxFieldIdx = 0;
- _screenXOffset = 0;
- _screenYOffset = 0;
- _maxR = 0.0;
-
- // initial values for internals
- _nextIdx = 0;
- _currX = 0.0;
- _currY = 0.0;
+ /*
+ _screenXOffset = 0;
+ _screenYOffset = 0;
+ */
// set parameters
_n = N;
_colorWidth = colorWidth;
+ _colorWidthDbl = (double)colorWidth;
_emptyWidth = emptyWidth;
_bConstantColor = bConstantColor;
_bRandomColor = bRandomColor;
@@ -76,21 +71,60 @@
_emptyWidth = 0;
// calculate misc constants
- _segmentWidth = _colorWidth + (_emptyWidth<<1);
+ //_segmentWidth = _colorWidth + (_emptyWidth<<1);
+ _lineWidth = double(_colorWidth + (_emptyWidth<<1));
+ cout<<"Setting linewidth to "<<_lineWidth<<endl;
- // calculate spiral constants and initial values
- _rCoeff = double(_segmentWidth)/(2.0*NGONSPIRAL_PI);
- _rCoeff *= (jrand() % 2 == 0) ? 1.0 : -1.0; // whether clockwise or not.
- _currR = 0.0;
+ // allocate space for axes & their normals
+ if(!(3 <= _n && _n < 1024))
+ return;
+ _axes = new Vector2D[_n];
+ _normals = new Vector2D[_n];
+ if(_axes == NULL || _normals == NULL) {
+ _n = 0;
+ return;
+ }
- // for now, just start at 0.
- _currTheta = 0.0;
- _lastThetaStep = NGONSPIRAL_PI/16.0;
+ // create & calculate axes
+ double delta = 2.0 * M_PI / ((double)_n);
+ if(relativeCompare(delta, M_PI/2.0, 1e-6)) {
+ _growLength = ((double)_lineWidth);
+ } else if( M_PI/2.0 < delta) {
+ _growLength = ((double)_lineWidth) / sin(M_PI - delta);
+ } else {
+ //_growLength = ((double)_lineWidth) / sin(delta);
+ //_growLength = ((double)_lineWidth) / (2.0*sin(delta));
+ _growLength = ((double)_lineWidth);
+ //_growLength = ((double)_lineWidth) * sin(delta);
+ }
+ _bevelAngle = delta/2.0;
+ double angle = 0.0; //((double)(jrand()%360)) / 2.0*PI;
+ int i;
+ for(i=0; i<_n; i++) {
+ _axes[i].setValue(1.0,0.0);
+ _axes[i].rotate(angle);
+ _normals[i] = _axes[i].getNormal();
+ cout<<"i: "<<i<<", angle: "<<angle<<", axis: "<<_axes[i]<<", n: "
+ <<_normals[i]<<endl;
+ angle += delta;
+ }
+ _bevelLength = sin(_bevelAngle) * _lineWidth/2.0;
+ _curColorCount = 0.0;
+ _curAxis = 0;
+ _ringNum = 0.0;
}
NgonSpiralAlgorithm::~NgonSpiralAlgorithm() {
+ if(_axes != NULL) {
+ delete [] _axes;
+ _axes = NULL;
+ }
+ if(_normals != NULL) {
+ delete [] _normals;
+ _normals = NULL;
+ }
}
/**
@@ -112,31 +146,262 @@
if(_numColors <= 0)
return;
- // calculate remaining internal constants
- _maxFieldIdx = screenWidth * screenHeight - 1;
- _screenXOffset = screenWidth>>1;
- _screenYOffset = screenHeight>>1;
+ _maxFieldIdx = screenWidth*screenHeight-1;
- // calculate polar stopping condition.
- _maxR = sqrt( _screenXOffset*_screenXOffset +
- _screenYOffset*_screenYOffset);
- if(_rCoeff < 0.0) {
- _maxR *= -1.0;
- }
+ _origin.setValue((screenWidth>>1)+_lineWidth/2.0+0.5,
+ (screenHeight>>1)+_lineWidth/2.0+0.5 );
// pick initial color
if(_bRandomColor) {
- _nextIdx = jrand() % numColors;
+ _curColorIdx = jrand() % numColors;
} else {
- _nextIdx = 0;
+ _curColorIdx = 0;
}
+ _curColorCount = 0.0;
// begin debug
- _stepCount = 128; //16;
+ _stepCount = 16;
// end debug
+}
+/**
+ * Completes one iteration of the algorithm. Returns true if the algorithm
+ * has completed.
+ */
+bool NgonSpiralAlgorithm::calc() {
+ if(_field == NULL)
+ return true;
+
+ // begin debug
+ cout<<"Count: "<<_stepCount<<endl;
+ /*
+ if(_stepCount < 0)
+ return true;
+ _stepCount--;
+ */
+ // end debug
+
+ // draw a segment
+ Point2D beginPoint;
+ Point2D endPoint;
+
+ cout<<"Cur Axis: "<<_curAxis<<", ring: "<<_ringNum
+ <<", grow length: "<<_growLength<<endl;
+ // check to see if the first segment has been drawn, since it is
+ // the only "odd" one.
+ if(_ringNum < 1.0) {
+ // nope, so draw a segment from the origin to the first midpoint.
+ beginPoint = _origin;
+ //Vector2D tmpV = _axes[0];
+ //tmpV.rotate(0.5*_bevelAngle);
+ endPoint = _axes[0].getPoint(_origin, _growLength);
+ // set up for next round.
+ _lastPoint = endPoint;
+ _curAxis = 0;
+ _ringNum = _growLength;
+ _ringCounter = _n-2;
+ } else {
+ // start at last midpoint
+ beginPoint = _lastPoint;
+ // find the next midpoint on the next axis. If the current axis is the
+ // last axis in the set, then increment the ring number too.
+ int nextAxis = (_curAxis+1)%_n;
+ _ringCounter--;
+ if(_ringCounter <= 0) {
+ _ringNum+=_growLength;
+ _ringCounter = _n-2;
+ }
+ _lastPoint = _axes[nextAxis].getPoint(beginPoint, _ringNum);
+ // change axis state for next iteration
+ _curAxis = nextAxis;
+ }
+ // draw the line segment
+ return !drawSegment(beginPoint, _lastPoint);
}
+/**
+ * Draws a segment from pointA to pointB. Returns true if any indices were
+ * set within _field.
+ */
+bool NgonSpiralAlgorithm::drawSegment(const Point2D& pointA,
+ const Point2D& pointB) {
+ cout<<"Drawing Segment from "<<pointA<<" to "<<pointB<<endl;
+ bool bPixelDrawn = false;
+ Point2D pB = pointB;
+ Point2D pA = pointA;
+ Vector2D pathV = pB - pA;
+ pathV.normalize();
+ // calculate normal to the path
+ Vector2D nV = pathV.getNormal();
+ nV.normalize();
+ // calculate bevel vector
+ Vector2D bevV = nV;
+ bevV.normalize();
+ bevV.rotate(1.0*_bevelAngle);
+ // these points represent the actual drawing
+ Point2D pStart;
+ Point2D pEnd;
+ double posOuter;
+ double posInner;
+ double traverseLength;
+
+ cout<<"Path: "<<pathV<<", Normal: "<<nV<<", Bevel: "<<bevV<<endl;
+
+ Point2D bevA = pA;
+ Point2D bevB = pB;
+ if(_colorWidth > 1) {
+ // Calculate the first end of the bevel.
+ bevA = pA + _bevelLength*pathV;
+ // Calculate the end of the bevel on the other end.
+ bevB = pB - _bevelLength*pathV;
+
+ /* 1: draw bevel on starting endpoint */
+ // Traverse the width of the color part of the line, starting
+ // at the point on the normal that is (color width/2)-(current
increment)
+ // length away from the main path draw a line to the intersection of
the
+ // bevel vector along the vector that is parallel to path.
+ for(posOuter = 0.0; posOuter < _colorWidthDbl;
+ posOuter += NGONSPIRALALGORITHM_STEPSIZE) {
+ // calculate the point on the normal.
+ pStart = bevA + (_colorWidthDbl/2.0 - posOuter)*nV;
+
+ // calculate the point on the bevel vector.
+ if(!pathV.getIntersectionPt(pStart, bevV, pA, pEnd)) {
+ cout<<"pathV doesn't intersect bevV!"<<endl;
+ return false;
+ }
+
+ // calculate the traversal length
+ traverseLength = pathV.getDistanceToPoint(pStart, pEnd);
+ // traverse from start to finish setting pixels along the way -
remember,
+ // we're going backwards!
+ for(posInner = 0.0; posInner > traverseLength;
+ posInner -= NGONSPIRALALGORITHM_STEPSIZE) {
+ bPixelDrawn = setPixel(pathV.getPoint(pStart, posInner)) || bPixelDrawn;
+ }
+ }
+ updateColorCount(_bevelLength);
+ cout<<"first bevel done"<<endl;
+ }
+ /* 2: draw segment between beveled ends */
+ // Traverse the length of the segment between bevA and bevB filling in
the
+ // color portion of the segment.
+ traverseLength = pathV.getDistanceToPoint(bevA, bevB);
+ cout<<"TraverseLength: "<<traverseLength<<endl;
+ //for(posOuter = 0.0; posOuter < traverseLength;
+ for(posOuter = 0.0; posOuter < traverseLength;
+ posOuter += NGONSPIRALALGORITHM_STEPSIZE) {
+ //cout<<"posOuter: "<<posOuter<<endl;
+
+ // calculate the point on the path.
+ pStart = bevA + posOuter*pathV;
+ //cout<<">> "<<pStart<<" -> ";
+ // now go to the edge of the color region.
+ pStart = pStart + (_colorWidthDbl/2.0)*nV;
+ //cout<<pStart<<endl;
+
+ // traverse from start to finish setting pixels along the way
+ for(posInner = 0.0; posInner < _colorWidthDbl;
+ posInner += NGONSPIRALALGORITHM_STEPSIZE) {
+ //cout<<"posInner: "<<posInner<<", pStart: "<<pStart<<endl;
+ bPixelDrawn = setPixel(pStart) || bPixelDrawn;
+ updateColorCount(NGONSPIRALALGORITHM_STEPSIZE);
+ pStart = pStart - NGONSPIRALALGORITHM_STEPSIZE*nV;
+ }
+ }
+ cout<<"seg done"<<endl;
+
+ /* 3: draw bevel on tail endpoint */
+ if(_colorWidth > 1) {
+ // Adjust bevV for the new side.
+ bevV.rotate(-1.0*_bevelAngle);
+ // Traverse the width of the color part of the line, starting
+ // at the point on the normal that is (color width/2)-(current
increment)
+ // length away from the main path draw a line to the intersection of
the
+ // bevel vector along the vector that is parallel to path.
+ for(posOuter = 0.0; posOuter < _colorWidthDbl;
+ posOuter += NGONSPIRALALGORITHM_STEPSIZE) {
+ // calculate the point on the normal.
+ pStart = bevB + (_colorWidthDbl/2.0 - posOuter)*nV;
+
+ // calculate the point on the bevel vector.
+ if(!pathV.getIntersectionPt(pStart, bevV, pB, pEnd)) {
+ cout<<"pathV doesn't intersect bevV!"<<endl;
+ return false;
+ }
+
+ // calculate the traversal length
+ traverseLength = pathV.getDistanceToPoint(pStart, pEnd);
+ // traverse from start to finish setting pixels along the way - going
+ // forwards this time!
+ for(posInner = 0.0; posInner < traverseLength;
+ posInner += NGONSPIRALALGORITHM_STEPSIZE) {
+ bPixelDrawn = setPixel(pathV.getPoint(pStart, posInner)) || bPixelDrawn;
+ }
+ }
+ updateColorCount(_bevelLength);
+ }
+ return bPixelDrawn;
+}
+
+/**
+ * Updates the color count by the specified amount.
+ */
+void NgonSpiralAlgorithm::updateColorCount(const double amnt) {
+ if(!_bConstantColor) {
+ _curColorCount += amnt;
+ if(_colorWidthDbl <= _curColorCount) {
+ _curColorCount -= _colorWidthDbl;
+ // update the color index.
+ if(_bIncrementColor) {
+ _curColorIdx++;
+ if(_numColors <= _curColorIdx) {
+ _curColorIdx = 0;
+ }
+ } else {
+ _curColorIdx--;
+ if(_curColorIdx <= 0) {
+ _curColorIdx = _numColors-1;
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Sets the specified coordinates to the current color index.
+ */
+bool NgonSpiralAlgorithm::setPixel(const Point2D& p) {
+ if(_field == NULL)
+ return false;
+
+ Point2D lclP = p;
+
+ int x = (int)(lclP.getX() + 0.5);
+ int y = (int)(lclP.getY() + 0.5);
+ int pos = y*_width + x;
+
+ //cout<<"Setting pixel: ("<<x<<", "<<y<<")";
+
+ // validate that the pixel is on the screen.
+ if( (0 <= x && x < _width) &&
+ (0 <= y && y < _height) &&
+ pos < _maxFieldIdx) {
+
+ // it is! set the pixel to the current color index.
+ _field[pos] = _curColorIdx;
+
+ //cout<<" -> Success!"<<endl;
+
+ return true;
+ }
+
+ //cout<<" -> Failure!"<<endl;
+
+ return false;
+}
+
+#ifdef BLARGH
/**
* Completes one iteration of the algorithm. Returns true if the algorithm
* is completed.
@@ -145,7 +410,7 @@
if(_field == NULL)
return true;
- if(_stepCount < 0)
+ if(_stepCount < 0)
return true;
//_stepCount--;
// if N is valid, use the N-gon spiral calculations.
@@ -181,7 +446,6 @@
return retVal;
}
-
/**
* Calculates a new X,Y using a polar spiral. Utilizes an adaptive
* algorithm to adjust thetaStep such that the new (x,y) value will
@@ -223,10 +487,10 @@
iNewX = roundDtoI(newX);
iNewY = roundDtoI(newY);
/*
- cout<<"newX: "<<newX<<","<<iNewX<<endl;
- cout<<"newY: "<<newY<<","<<iNewY<<endl;
- cout<<"oldX: "<<*x<<","<<iOldX<<endl;
- cout<<"oldY: "<<*y<<","<<iOldY<<endl;
+ cout<<"newX: "<<newX<<","<<iNewX<<endl;
+ cout<<"newY: "<<newY<<","<<iNewY<<endl;
+ cout<<"oldX: "<<*x<<","<<iOldX<<endl;
+ cout<<"oldY: "<<*y<<","<<iOldY<<endl;
*/
bDone = true;
@@ -243,8 +507,8 @@
if(++escape_count >= 100) {
/*
- cout<<"NgonSpiralAlgorithm::calcSpiral() Escape count
reached!"<<endl;
- cout<<"maxR: "<<_maxR<<endl;
+ cout<<"NgonSpiralAlgorithm::calcSpiral() Escape count reached!"<<endl;
+ cout<<"maxR: "<<_maxR<<endl;
*/
//exit(1);
//*r = _maxR+1.0;
@@ -264,3 +528,5 @@
return (_rCoeff < 0.0) ? (newR <= _maxR) : (newR >= _maxR);
}
+
+#endif
=======================================
--- /src/common/spirals/NgonSpiralAlgorithm.h Sun Aug 2 18:49:07 2009 UTC
+++ /src/common/spirals/NgonSpiralAlgorithm.h Sat Feb 20 16:25:28 2010 UTC
@@ -23,17 +23,19 @@
*/
/**
- * This is a generic N-gon spiral algorithm. If N is invalid, a polar
- * spiral algorithm is used.
+ * This is a generic N-gon spiral algorithm.
*/
#include "utility/Vector2D.h"
+#include "utility/Point2D.h"
#include "utility/misc_funcs.h"
#include "SpiralAlgorithm.h"
#ifndef __NGONSPIRALALGORITHM_H__
#define __NGONSPIRALALGORITHM_H__
+#define NGONSPIRALALGORITHM_STEPSIZE 0.5
+
class NgonSpiralAlgorithm : public SpiralAlgorithm {
public:
@@ -71,55 +73,94 @@
/**
* Completes one iteration of the algorithm. Returns true if the
algorithm
- * is completed.
+ * has completed.
*/
bool calc();
private:
/**
- * Calculates a new X,Y using a polar spiral. Utilizes an adaptive
- * algorithm to adjust thetaStep such that the new (x,y) value will
- * be adjacent but not on the previous (x,y) value.
- * @param x the previous X value. On return, it is the new X value.
- * @param y the previous Y value. On return, it is the new Y value.
- * @param r the previous R value. On return, it is the new R value.
- * @param theta the previous Theta value. It is updated on return.
- * @param thetaStep the previous Theta step value. Updated on return.
- * @return True if the calculation is complete.
+ * Draws a segment from pointA to pointB. Returns true if any indices
were
+ * set within _field.
*/
- bool calcSpiral(double* x, double* y, double* r, double* theta,
- double* thetaStep);
+ bool drawSegment(const Point2D& pointA, const Point2D& pointB);
+ /**
+ * Updates the color count by the specified amount.
+ */
+ void updateColorCount(const double amnt);
+
+ /**
+ * Sets the specified coordinates to the current color index. Returns
+ * true if a pixel was actually set.
+ */
+ bool setPixel(const Point2D& p);
+
// begin parameters
int _n;
int _colorWidth;
+ double _colorWidthDbl;
int _emptyWidth;
bool _bConstantColor;
bool _bRandomColor;
bool _bIncrementColor;
+ int _maxFieldIdx; //> _sizeX * _sizeY - 1;
// end parameters
- // begin spiral specific
- double _rCoeff; // accounts for clockwise/counterclockwise!
- double _currR;
- double _currTheta;
- double _thetaStep;
- double _maxR; //!< polar stopping condition
- // end spiral specific
+ // begin state data
+ Point2D _origin;
+ Point2D _lastPoint;
+ Vector2D* _axes;
+ Vector2D* _normals;
+ int _curAxis;
+ double _ringNum;
+ int _ringCounter;
+ double _lineWidth;
+ double _growLength;
+ double _bevelAngle;
+ double _bevelLength;
+ double _curColorCount;
+ int _curColorIdx;
+ /*
+ // begin old...
double _currX;
double _currY;
int _nextIdx;
+ */
// begin constants to speed up calculations
int _screenXOffset;
int _screenYOffset;
int _segmentWidth;
- int _maxFieldIdx; //> _sizeX * _sizeY - 1;
// end constants
+ // end old...
+
// begin debug
int _stepCount;
+
+#ifdef BLARGH
+ // begin spiral specific
+ double _rCoeff; // accounts for clockwise/counterclockwise!
+ double _currR;
+ double _currTheta;
+ double _thetaStep;
+ double _maxR; //!< polar stopping condition
+ // end spiral specific
+
+ /**
+ * Calculates a new X,Y using a polar spiral. Utilizes an adaptive
+ * algorithm to adjust thetaStep such that the new (x,y) value will
+ * be adjacent but not on the previous (x,y) value.
+ * @param x the previous X value. On return, it is the new X value.
+ * @param y the previous Y value. On return, it is the new Y value.
+ * @param r the previous R value. On return, it is the new R value.
+ * @param theta the previous Theta value. It is updated on return.
+ * @param thetaStep the previous Theta step value. Updated on return.
+ * @return True if the calculation is complete.
+ */
+ bool calcSpiral(double* x, double* y, double* r, double* theta,
+ double* thetaStep);
/*
int* _cornerSeg;
@@ -137,6 +178,7 @@
// These are to speed up some calculations, since they only need done
once.
float _halfSegSize; //> _segmentSize / 2.0
*/
+#endif
};
#endif
=======================================
--- /src/common/utility/Vector2D.cpp Sat Feb 13 23:17:14 2010 UTC
+++ /src/common/utility/Vector2D.cpp Sat Feb 20 16:25:28 2010 UTC
@@ -283,7 +283,7 @@
return replica.isParallelTo(v2);
}
-double Vector2D::getIntersectingMul(const Point2D& pA, const Vector2D& vB,
+double Vector2D::getIntersectionMul(const Point2D& pA, const Vector2D& vB,
const Point2D& pB) {
Point2D rPA = pA;
@@ -324,10 +324,10 @@
* @param result The resulting point.
* @return True if the lines intersect, false if they do not.
*/
-bool Vector2D::getIntersectingPt(const Point2D& pA, const Vector2D& vB,
+bool Vector2D::getIntersectionPt(const Point2D& pA, const Vector2D& vB,
const Point2D& pB, Point2D& result) {
- double mul = getIntersectingMul(pA, vB, pB);
+ double mul = getIntersectionMul(pA, vB, pB);
if(!isnan(mul)) {
Vector2D rV = *this;
=======================================
--- /src/common/utility/Vector2D.h Sat Feb 13 23:17:14 2010 UTC
+++ /src/common/utility/Vector2D.h Sat Feb 20 16:25:28 2010 UTC
@@ -163,7 +163,7 @@
* @param result The resulting point.
* @return the multiplier, or NAN if lines don't intersect.
*/
- double getIntersectingMul(const Point2D& pA, const Vector2D& vB,
+ double getIntersectionMul(const Point2D& pA, const Vector2D& vB,
const Point2D& pB);
/**
@@ -178,7 +178,7 @@
* @param result The resulting point.
* @return True if the lines intersect, false if they do not.
*/
- bool getIntersectingPt(const Point2D& pA, const Vector2D& vB,
+ bool getIntersectionPt(const Point2D& pA, const Vector2D& vB,
const Point2D& pB, Point2D& result);
/**
=======================================
--- /src/common/utility/unit_tests/Test_Vector2D.cpp Sat Feb 13 23:17:14
2010 UTC
+++ /src/common/utility/unit_tests/Test_Vector2D.cpp Sat Feb 20 16:25:28
2010 UTC
@@ -625,15 +625,14 @@
vB.setValue(1.0,1.0);
vB.rotate(1.047198);
pB.setValue(-4.0,5.0);
- bResult=vA.getIntersectingPt(pA, vB, pB, pI);
- QVERIFY(relativeCompare(vA.getIntersectingMul(pA, vB, pB),-4.3093987,
1e-6));
+ QVERIFY(relativeCompare(vA.getIntersectionMul(pA, vB, pB),-4.3093987,
1e-6));
// Normal case
vA.setValue(1.0,1.0);
pA.setValue(2.0,3.0);
vB.setValue(-1.0,1.0);
pB.setValue(-4.0,1.0);
- bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ bResult=vA.getIntersectionPt(pA, vB, pB, pI);
QVERIFY(bResult);
QVERIFY(relativeCompare(pI.getX(),-2.0, 1e-6));
QVERIFY(relativeCompare(pI.getY(),-1.0, 1e-6));
@@ -643,7 +642,7 @@
pA.setValue(4.0,1.0);
vB.setValue(8.0,16.0);
pB.setValue(17.0,15.0);
- bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ bResult=vA.getIntersectionPt(pA, vB, pB, pI);
QVERIFY(!bResult);
QVERIFY(isnan(pI.getX()));
QVERIFY(isnan(pI.getY()));
@@ -653,7 +652,7 @@
pA.setValue(7.0,9.0);
vB.setValue(-4.0,1.0);
pB.setValue(7.0,9.0);
- bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ bResult=vA.getIntersectionPt(pA, vB, pB, pI);
QVERIFY(bResult);
QVERIFY(relativeCompare(pI.getX(),7.0, 1e-6));
QVERIFY(relativeCompare(pI.getY(),9.0, 1e-6));
@@ -663,7 +662,7 @@
pA.setValue(2.0,3.0);
vB.setValue(1.0,1.0);
pB.setValue(-4.0,5.0);
- bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ bResult=vA.getIntersectionPt(pA, vB, pB, pI);
QVERIFY(!bResult);
QVERIFY(isnan(pI.getX()));
QVERIFY(isnan(pI.getY()));
@@ -674,7 +673,7 @@
vB.setValue(1.0,1.0);
vB.rotate(1.047198);
pB.setValue(-4.0,5.0);
- bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ bResult=vA.getIntersectionPt(pA, vB, pB, pI);
QVERIFY(bResult);
QVERIFY(relativeCompare(pI.getX(),-2.3093987, 1e-6));
QVERIFY(relativeCompare(pI.getY(),-1.3093987, 1e-6));
@@ -685,7 +684,7 @@
vB.setValue(1.0,1.0);
vB.rotate(1.047198);
pB.setValue(2.0,3.0);
- bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ bResult=vA.getIntersectionPt(pA, vB, pB, pI);
QVERIFY(bResult);
QVERIFY(relativeCompare(pI.getX(),2.0, 1e-6));
QVERIFY(relativeCompare(pI.getY(),3.0, 1e-6));
@@ -695,7 +694,7 @@
pA.setValue(2.0,3.0);
vB.setValue(-1.0,1.0);
pB.setValue(-4.0,5.0);
- bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ bResult=vA.getIntersectionPt(pA, vB, pB, pI);
QVERIFY(!bResult);
QVERIFY(isnan(pI.getX()));
QVERIFY(isnan(pI.getY()));
@@ -705,7 +704,7 @@
pA.setValue(2.0,3.0);
vB.setValue();
pB.setValue(-4.0,5.0);
- bResult=vA.getIntersectingPt(pA, vB, pB, pI);
+ bResult=vA.getIntersectionPt(pA, vB, pB, pI);
QVERIFY(!bResult);
QVERIFY(isnan(pI.getX()));
QVERIFY(isnan(pI.getY()));