[dasher] Refactored computation of polar co-ordinates for auto speed control.
- From: Patrick Welche <pwelche src gnome org>
- To: svn-commits-list gnome org
- Subject: [dasher] Refactored computation of polar co-ordinates for auto speed control.
- Date: Fri, 15 May 2009 12:50:36 -0400 (EDT)
commit 1b88d825b7f894ce98c40a2af78ba6ea762d3028
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Fri May 15 17:49:54 2009 +0100
Refactored computation of polar co-ordinates for auto speed control.
---
ChangeLog | 4 ++++
Src/DasherCore/AutoSpeedControl.cpp | 14 +++-----------
Src/DasherCore/DasherView.h | 14 ++++----------
Src/DasherCore/DasherViewSquare.cpp | 13 +++++++++++++
Src/DasherCore/DasherViewSquare.h | 13 +++++++------
5 files changed, 31 insertions(+), 27 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 67fa3ed..bd3382d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@
* Backport to OS X 10.4 universal binary for PPC.
* DasherModel.{h,cpp}: Remove unused Recursive_Push_Node method.
+ * AutoSpeedControl.cpp, DasherView.h, DasherViewSquare.{h,cpp}:
+ Refactored computation of polar co-ordinates for auto speed
+ control.
+
2009-05-14 Patrick Welche <prlw1 cam ac uk>
diff --git a/Src/DasherCore/AutoSpeedControl.cpp b/Src/DasherCore/AutoSpeedControl.cpp
index e0cefe4..b8813e9 100644
--- a/Src/DasherCore/AutoSpeedControl.cpp
+++ b/Src/DasherCore/AutoSpeedControl.cpp
@@ -181,17 +181,9 @@ inline void CAutoSpeedControl::UpdateSigmas(double r, double dFrameRate)
void CAutoSpeedControl::SpeedControl(myint iDasherX, myint iDasherY, double dFrameRate, CDasherView *pView) {
if(GetBoolParameter(BP_AUTO_SPEEDCONTROL) && !GetBoolParameter(BP_DASHER_PAUSED)) {
-// Coordinate transforms:
- iDasherX = myint(pView->xmap(iDasherX / static_cast < double >(GetLongParameter(LP_MAX_Y))) * GetLongParameter(LP_MAX_Y));
- iDasherY = myint(pView->ymap(iDasherY));
-
- myint iDasherOX = myint(pView->xmap(GetLongParameter(LP_OX) / static_cast < double >(GetLongParameter(LP_MAX_Y))) * GetLongParameter(LP_MAX_Y));
- myint iDasherOY = myint(pView->ymap(GetLongParameter(LP_OY)));
-
- double x = -(iDasherX - iDasherOX) / double(iDasherOX); //Use normalised coords so min r works
- double y = -(iDasherY - iDasherOY) / double(iDasherOY);
- double theta = atan2(y, x);
- double r = sqrt(x * x + y * y);
+// Coordinate transforms:
+ double r,theta;
+ pView->Dasher2Polar(iDasherX, iDasherY, r, theta);
m_dBitrate = GetLongParameter(LP_MAX_BITRATE) / 100.0; // stored as long(round(true bitrate * 100))
diff --git a/Src/DasherCore/DasherView.h b/Src/DasherCore/DasherView.h
index fca7bd2..041666d 100644
--- a/Src/DasherCore/DasherView.h
+++ b/Src/DasherCore/DasherView.h
@@ -104,21 +104,15 @@ public:
virtual void Dasher2Screen(myint iDasherX, myint iDasherY, screenint & iScreenX, screenint & iScreenY) = 0;
+ ///
+ /// Convert Dasher co-ordinates to polar co-ordinates (r,theta), with 0<r<1, 0<theta<2*pi
+ ///
+ virtual void Dasher2Polar(myint iDasherX, myint iDasherY, double &r, double &theta) = 0;
virtual bool IsNodeVisible(myint y1, myint y2) { return true; };
virtual void VisibleRegion( myint &iDasherMinX, myint &iDasherMinY, myint &iDasherMaxX, myint &iDasherMaxY ) = 0;
- /// \todo This function is only public (and in the parent class)
- /// because of the slightly hacky conversion needed for auto speed
- /// control. At some point find a way to make this more sensible.
- virtual double xmap(double x) const = 0;
-
- /// \todo This function is only public (and in the parent class)
- /// because of the slightly hacky conversion needed for auto speed
- /// control. At some point find a way to make this more sensible.
- virtual double ymap(double x) const = 0;
-
/// @}
/// Change the screen - must be called if the Screen is replaced or resized
diff --git a/Src/DasherCore/DasherViewSquare.cpp b/Src/DasherCore/DasherViewSquare.cpp
index fd79fd8..a204503 100644
--- a/Src/DasherCore/DasherViewSquare.cpp
+++ b/Src/DasherCore/DasherViewSquare.cpp
@@ -894,6 +894,19 @@ void CDasherViewSquare::Dasher2Screen(myint iDasherX, myint iDasherY, screenint
}
}
+void CDasherViewSquare::Dasher2Polar(myint iDasherX, myint iDasherY, double &r, double &theta) {
+ iDasherX = myint(xmap(iDasherX / static_cast < double >(GetLongParameter(LP_MAX_Y))) * GetLongParameter(LP_MAX_Y));
+ iDasherY = myint(m_ymap.map(iDasherY));
+
+ myint iDasherOX = myint(xmap(GetLongParameter(LP_OX) / static_cast < double >(GetLongParameter(LP_MAX_Y))) * GetLongParameter(LP_MAX_Y));
+ myint iDasherOY = myint(m_ymap.map(GetLongParameter(LP_OY)));
+
+ double x = -(iDasherX - iDasherOX) / double(iDasherOX); //Use normalised coords so min r works
+ double y = -(iDasherY - iDasherOY) / double(iDasherOY);
+ theta = atan2(y, x);
+ r = sqrt(x * x + y * y);
+}
+
void CDasherViewSquare::VisibleRegion( myint &iDasherMinX, myint &iDasherMinY, myint &iDasherMaxX, myint &iDasherMaxY ) {
// TODO: Change output parameters to pointers and allow NULL to mean
// 'I don't care'. Need to be slightly careful about this as it will
diff --git a/Src/DasherCore/DasherViewSquare.h b/Src/DasherCore/DasherViewSquare.h
index 60bb9e6..a8a8ad9 100644
--- a/Src/DasherCore/DasherViewSquare.h
+++ b/Src/DasherCore/DasherViewSquare.h
@@ -78,6 +78,11 @@ public:
///
void Dasher2Screen(myint iDasherX, myint iDasherY, screenint & iScreenX, screenint & iScreenY);
+ ///
+ /// Convert Dasher co-ordinates to polar co-ordinates (r,theta), with 0<r<1, 0<theta<2*pi
+ ///
+ virtual void Dasher2Polar(myint iDasherX, myint iDasherY, double &r, double &theta);
+
///
/// Return true if a node spanning y1 to y2 is entirely enclosed by
/// the screen boundary
@@ -89,11 +94,6 @@ public:
///
void VisibleRegion( myint &iDasherMinX, myint &iDasherMinY, myint &iDasherMaxX, myint &iDasherMaxY );
- double xmap(double x) const;
- double ymap(double x) const {
- return m_ymap.map( (myint)x );
- };
-
/// @}
@@ -151,7 +151,7 @@ private:
#endif
// Class definitions
-
+ ///Implements the non-linearity near the extremes of the Y axis
class Cymap {
public:
Cymap(myint iScale);
@@ -162,6 +162,7 @@ private:
myint m_Y1, m_Y2, m_Y3;
};
+ double xmap(double x) const;
double xmax(double x, double y) const;
double ixmap(double x) const;
inline void Crosshair(myint sx);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]