[dasher] Remove m_dXmpc, multiplicative factor can be combined into iScaleFactorX.
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher] Remove m_dXmpc, multiplicative factor can be combined into iScaleFactorX.
- Date: Tue, 18 Jan 2011 17:18:36 +0000 (UTC)
commit 36ce3f7c75db14ce45000bf7b55735dd099538e0
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date: Fri Dec 17 17:22:37 2010 +0000
Remove m_dXmpc, multiplicative factor can be combined into iScaleFactorX.
This makes the arbitrariness (and pointlessness!) of what we were doing before,
even more apparent...
Rename x nonlinearity coeffs, tidy SetScaleFactor.
Src/DasherCore/DasherViewSquare.cpp | 68 ++++++++++++-----------------------
Src/DasherCore/DasherViewSquare.h | 3 +-
Src/DasherCore/DasherViewSquare.inl | 23 +++++++-----
3 files changed, 38 insertions(+), 56 deletions(-)
---
diff --git a/Src/DasherCore/DasherViewSquare.cpp b/Src/DasherCore/DasherViewSquare.cpp
index 008c5a2..0ac50fc 100644
--- a/Src/DasherCore/DasherViewSquare.cpp
+++ b/Src/DasherCore/DasherViewSquare.cpp
@@ -842,63 +842,42 @@ void CDasherViewSquare::SetScaleFactor( void )
{
//Parameters for X non-linearity.
// Set some defaults here, in case we change(d) them later...
- m_dXmpb = 0.5; //threshold: DasherX's less than (m_dXmpb * MAX_Y) are linear...
- m_dXmpc = 0.9; //...but multiplied by m_dXmpc; DasherX's above that, are logarithmic...
-
- //set log scaling coefficient (unused if LP_NONLINEAR_X==0)
- // note previous value of m_dXmpa = 0.2, i.e. a value of LP_NONLINEAR_X =~= 4.8
- m_dXmpa = exp(GetLongParameter(LP_NONLINEAR_X)/-3.0);
+ m_iXlogThres=GetLongParameter(LP_MAX_Y)/2; //threshold: DasherX's less than this are linear; those greater are logarithmic
- myint iDasherWidth = (myint)GetLongParameter(LP_MAX_Y);
- myint iDasherHeight = iDasherWidth;
-
- screenint iScreenWidth = Screen()->GetWidth();
- screenint iScreenHeight = Screen()->GetHeight();
-
- // Try doing this a different way:
-
- iMarginWidth = GetLongParameter(LP_MARGIN_WIDTH);
-
- myint iMinX( 0-iMarginWidth );
- myint iMaxX( iDasherWidth );
- myint iMinY( 0 );
- myint iMaxY( iDasherHeight );
- myint iCenterX((iMinX+iMaxX)/2);
- Dasher::Opts::ScreenOrientations eOrientation(Dasher::Opts::ScreenOrientations(GetLongParameter(LP_REAL_ORIENTATION)));
+ //set log scaling coefficient (unused if LP_NONLINEAR_X==0)
+ // note previous value = 1/0.2, i.e. a value of LP_NONLINEAR_X =~= 4.8
+ m_dXlogCoeff = exp(GetLongParameter(LP_NONLINEAR_X)/3.0);
- double dScaleFactorX, dScaleFactorY;
+ const Dasher::Opts::ScreenOrientations eOrientation(Dasher::Opts::ScreenOrientations(GetLongParameter(LP_REAL_ORIENTATION)));
+ const bool bHoriz(eOrientation == Dasher::Opts::LeftToRight || eOrientation == Dasher::Opts::RightToLeft);
+ const screenint iScreenWidth(Screen()->GetWidth()), iScreenHeight(Screen()->GetHeight());
+ const double dPixelsX(bHoriz ? iScreenWidth : iScreenHeight), dPixelsY(bHoriz ? iScreenHeight : iScreenWidth);
- if (eOrientation == Dasher::Opts::LeftToRight || eOrientation == Dasher::Opts::RightToLeft) {
- dScaleFactorX = iScreenWidth / static_cast<double>( iMaxX - iMinX );
- dScaleFactorY = iScreenHeight / static_cast<double>( iMaxY - iMinY );
- } else {
- dScaleFactorX = iScreenHeight / static_cast<double>( iMaxX - iMinX );
- dScaleFactorY = iScreenWidth / static_cast<double>( iMaxY - iMinY );
- }
+ const myint lpMaxY(GetLongParameter(LP_MAX_Y));
+ iMarginWidth = GetLongParameter(LP_MARGIN_WIDTH); //different schemes will alter this later...
+ double dScaleFactorY(dPixelsY / lpMaxY );
+ double dScaleFactorX(dPixelsX / static_cast<double>(lpMaxY + iMarginWidth) );
+
if (dScaleFactorX < dScaleFactorY) {
//fewer (pixels per dasher coord) in X direction - i.e., X is more compressed.
//So, use X scale for Y too...except first, we'll _try_ to reduce the difference
// by changing the relative scaling of X and Y (by at most 20%):
double dMul = max(0.8, dScaleFactorX / dScaleFactorY);
- m_dXmpc *= dMul; // => m_dXmpc = dMul*0.9
- dScaleFactorX /= dMul;
-
- iScaleFactorX = myint(dScaleFactorX * m_iScalingFactor);
- iScaleFactorY = myint(std::max(dScaleFactorX, dScaleFactorY / 4.0) * m_iScalingFactor);
- iMarginWidth = (iMaxX/20.0 + iMarginWidth*0.95)*dMul;
+ dScaleFactorY = std::max(dScaleFactorX/dMul, dScaleFactorY / 4.0);
+ dScaleFactorX *= 0.9;
+ iMarginWidth = (lpMaxY/20.0 + iMarginWidth*0.95)/0.9;
} else {
//X has more room; use Y scale for both -> will get lots history
- iScaleFactorX = myint(std::max(dScaleFactorY, dScaleFactorX / 4.0) * m_iScalingFactor);
- iScaleFactorY = myint(dScaleFactorY * m_iScalingFactor);
// however, "compensate" by relaxing the default "relative scaling" of X
// (normally only 90% of Y) towards 1...
- m_dXmpc = std::min(1.0,0.9 * dScaleFactorX / dScaleFactorY);
- iMarginWidth = (iScreenWidth*m_iScalingFactor/iScaleFactorX - (4096-iMarginWidth)*m_dXmpc)/2;
+ double dXmpc = std::min(1.0,0.9 * dScaleFactorX / dScaleFactorY);
+ dScaleFactorX = max(dScaleFactorY, dScaleFactorX / 4.0)*dXmpc;
+ iMarginWidth = (iMarginWidth + dPixelsX/dScaleFactorX - lpMaxY)/2;
}
- iCenterX *= m_dXmpc;
-
- //iMarginWidth = (iMarginWidth + iScreenWidth*m_iScalingFactor/iScaleFactorX)*m_dXmpc/2.0;
+ iScaleFactorX = myint(dScaleFactorX * m_iScalingFactor);
+ iScaleFactorY = myint(dScaleFactorY * m_iScalingFactor);
+
#ifdef DEBUG
//now test Dasher2Screen & Screen2Dasher are inverses...
for (screenint x=0; x<iScreenWidth; x++) {
@@ -1032,8 +1011,7 @@ void CDasherViewSquare::DasherLine2Screen(myint x1, myint y1, myint x2, myint y2
x1=x_mid; y1=m_Y2;
}
}
- double dMax(static_cast<double>(GetLongParameter(LP_MAX_Y)));
- if (GetLongParameter(LP_NONLINEAR_X) && (x1 / dMax > m_dXmpb || x2 / dMax > m_dXmpb)) {
+ if (GetLongParameter(LP_NONLINEAR_X) && (x1 > m_iXlogThres || x2 > m_iXlogThres)) {
//into logarithmic section
CDasherScreen::point pStart, pScreenMid, pEnd;
Dasher2Screen(x2, y2, pEnd.x, pEnd.y);
diff --git a/Src/DasherCore/DasherViewSquare.h b/Src/DasherCore/DasherViewSquare.h
index 920f4aa..8a3a485 100644
--- a/Src/DasherCore/DasherViewSquare.h
+++ b/Src/DasherCore/DasherViewSquare.h
@@ -196,7 +196,8 @@ private:
void SetScaleFactor();
// Parameters for x non-linearity
- double m_dXmpa, m_dXmpb, m_dXmpc;
+ double m_dXlogCoeff;
+ myint m_iXlogThres;
//width of margin, in abstract screen coords
myint iMarginWidth;
diff --git a/Src/DasherCore/DasherViewSquare.inl b/Src/DasherCore/DasherViewSquare.inl
index 22ff835..8754cf6 100644
--- a/Src/DasherCore/DasherViewSquare.inl
+++ b/Src/DasherCore/DasherViewSquare.inl
@@ -45,20 +45,23 @@ namespace Dasher {
inline myint CDasherViewSquare::ixmap(myint x) const
{
- double dx = (x - iMarginWidth) / static_cast<double>(GetLongParameter(LP_MAX_Y));
- dx /= m_dXmpc;
- if(GetLongParameter(LP_NONLINEAR_X)>0 && dx >= m_dXmpb)
- dx = m_dXmpb - m_dXmpa + m_dXmpa * exp((dx - m_dXmpb) / m_dXmpa);
- return myint(dx * GetLongParameter(LP_MAX_Y));
+ x -= iMarginWidth;
+ if (GetLongParameter(LP_NONLINEAR_X)>0 && x >= m_iXlogThres) {
+ double dx = (x - m_iXlogThres) / static_cast<double>(GetLongParameter(LP_MAX_Y));
+ dx = (exp(dx * m_dXlogCoeff) - 1) / m_dXlogCoeff;
+ x = myint( dx * GetLongParameter(LP_MAX_Y)) + m_iXlogThres;
+ }
+ return x;
}
inline myint CDasherViewSquare::xmap(myint x) const
{
- double dx = x / static_cast<double>(GetLongParameter(LP_MAX_Y));
- if(GetLongParameter(LP_NONLINEAR_X) && dx >= m_dXmpb)
- dx = (m_dXmpa * log((dx + m_dXmpa - m_dXmpb) / m_dXmpa) + m_dXmpb);
- dx *= m_dXmpc * GetLongParameter(LP_MAX_Y);
- return myint(dx>0 ? ceil(dx) : floor(dx)) + iMarginWidth;
+ if(GetLongParameter(LP_NONLINEAR_X) && x >= m_iXlogThres) {
+ double dx = log(1+ (x-m_iXlogThres)*m_dXlogCoeff/GetLongParameter(LP_MAX_Y))/m_dXlogCoeff;
+ dx = (dx*GetLongParameter(LP_MAX_Y)) + m_iXlogThres;
+ x= myint(dx>0 ? ceil(dx) : floor(dx));
+ }
+ return x + iMarginWidth;
}
inline myint CDasherViewSquare::ymap(myint y) const {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]