changeset 1409:21ba60008200 scale-ticks

More fixes, more tests, including some more that now fail
author Chris Cannam
date Wed, 03 May 2017 18:01:25 +0100
parents f89365917d02
children c4af57d59434
files base/ScaleTickIntervals.h base/test/TestScaleTickIntervals.h
diffstat 2 files changed, 113 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/base/ScaleTickIntervals.h	Wed May 03 17:02:01 2017 +0100
+++ b/base/ScaleTickIntervals.h	Wed May 03 18:01:25 2017 +0100
@@ -66,7 +66,10 @@
         double digMax = log10(fabs(r.max));
         double digMin = log10(fabs(r.min));
 
-        int precInc = int(trunc(digInc)) - 1;
+        int precInc = int(trunc(digInc));
+        if (double(precInc) != digInc) {
+            precInc -= 1;
+        }
 
         bool fixed = false;
         if (precInc > -4 && precInc < 4) {
@@ -96,28 +99,7 @@
         std::cerr << "fixed = " << fixed << ", inc = " << inc
                   << ", precInc = " << precInc << ", precRange = " << precRange
                   << ", prec = " << prec << std::endl;
-        
-//	int prec = int((ilg > 0.0) ? round(ilg) : trunc(ilg)) - 1;
-/*
-	int dp = 0, sf = 0;
-	bool fixed = false;
-	if (prec < 0) {
-	    dp = -prec;
-	    sf = 1; // was 2, but should probably vary
-	} else {
-	    sf = prec;
-	}
-	if (sf == 0) {
-	    sf = 1;
-	}
-	if (prec > -4 && prec < 4) {
-	    fixed = true;
-	}
-*/
-/*        bool fixed = true;
-        int dp = sig;
-        int sf = prec;
-*/      
+
 	double roundTo = pow(10.0, precInc);
 
         std::cerr << "roundTo = " << roundTo << std::endl;
--- a/base/test/TestScaleTickIntervals.h	Wed May 03 17:02:01 2017 +0100
+++ b/base/test/TestScaleTickIntervals.h	Wed May 03 18:01:25 2017 +0100
@@ -69,17 +69,45 @@
     {
 	auto ticks = ScaleTickIntervals::linear({ 0, 1, 10 });
 	vector<ScaleTickIntervals::Tick> expected {
-	    { 0.0, "0.00" },
-	    { 0.1, "0.10" },
-	    { 0.2, "0.20" },
-	    { 0.3, "0.30" },
-	    { 0.4, "0.40" },
-	    { 0.5, "0.50" },
-	    { 0.6, "0.60" },
-	    { 0.7, "0.70" },
-	    { 0.8, "0.80" },
-	    { 0.9, "0.90" },
-	    { 1.0, "1.00" }
+	    { 0.0, "0.0" },
+	    { 0.1, "0.1" },
+	    { 0.2, "0.2" },
+	    { 0.3, "0.3" },
+	    { 0.4, "0.4" },
+	    { 0.5, "0.5" },
+	    { 0.6, "0.6" },
+	    { 0.7, "0.7" },
+	    { 0.8, "0.8" },
+	    { 0.9, "0.9" },
+	    { 1.0, "1.0" }
+	};
+	compareTicks(ticks.ticks, expected);
+    }
+
+    void linear_0_5_5()
+    {
+	auto ticks = ScaleTickIntervals::linear({ 0, 5, 5 });
+	vector<ScaleTickIntervals::Tick> expected {
+	    { 0, "0" },
+	    { 1, "1" },
+	    { 2, "2" },
+	    { 3, "3" },
+	    { 4, "4" },
+	    { 5, "5" },
+	};
+	compareTicks(ticks.ticks, expected);
+    }
+
+    void linear_0_10_5()
+    {
+	auto ticks = ScaleTickIntervals::linear({ 0, 10, 5 });
+	vector<ScaleTickIntervals::Tick> expected {
+	    { 0, "0" },
+	    { 2, "2" },
+	    { 4, "4" },
+	    { 6, "6" },
+	    { 8, "8" },
+	    { 10, "10" }
 	};
 	compareTicks(ticks.ticks, expected);
     }
@@ -88,12 +116,12 @@
     {
 	auto ticks = ScaleTickIntervals::linear({ 0, 0.1, 5 });
 	vector<ScaleTickIntervals::Tick> expected {
-	    { 0.0, "0.00" },
+	    { 0.00, "0.00" },
 	    { 0.02, "0.02" },
 	    { 0.04, "0.04" },
 	    { 0.06, "0.06" },
 	    { 0.08, "0.08" },
-	    { 0.1, "0.10" }
+	    { 0.10, "0.10" }
 	};
 	compareTicks(ticks.ticks, expected);
     }
@@ -102,12 +130,26 @@
     {
 	auto ticks = ScaleTickIntervals::linear({ 0, 0.01, 5 });
 	vector<ScaleTickIntervals::Tick> expected {
-	    { 0.00, "0.000" },
+	    { 0.000, "0.000" },
 	    { 0.002, "0.002" },
 	    { 0.004, "0.004" },
 	    { 0.006, "0.006" },
 	    { 0.008, "0.008" },
-	    { 0.01, "0.010" }
+	    { 0.010, "0.010" }
+	};
+	compareTicks(ticks.ticks, expected);
+    }
+
+    void linear_0_0p005_5()
+    {
+	auto ticks = ScaleTickIntervals::linear({ 0, 0.005, 5 });
+	vector<ScaleTickIntervals::Tick> expected {
+	    { 0.000, "0.000" },
+	    { 0.001, "0.001" },
+	    { 0.002, "0.002" },
+	    { 0.003, "0.003" },
+	    { 0.004, "0.004" },
+	    { 0.005, "0.005" }
 	};
 	compareTicks(ticks.ticks, expected);
     }
@@ -116,12 +158,12 @@
     {
 	auto ticks = ScaleTickIntervals::linear({ 0, 0.001, 5 });
 	vector<ScaleTickIntervals::Tick> expected {
-	    { 0.000, "0.0e+00" },
+	    { 0.0000, "0.0e+00" },
 	    { 0.0002, "2.0e-04" },
 	    { 0.0004, "4.0e-04" },
 	    { 0.0006, "6.0e-04" },
 	    { 0.0008, "8.0e-04" },
-	    { 0.001, "1.0e-03" }
+	    { 0.0010, "1.0e-03" }
 	};
 	compareTicks(ticks.ticks, expected);
     }
@@ -130,12 +172,59 @@
     {
 	auto ticks = ScaleTickIntervals::linear({ 1, 1.001, 5 });
 	vector<ScaleTickIntervals::Tick> expected {
-	    { 1.000, "1.0000" },
+	    { 1.0000, "1.0000" },
 	    { 1.0002, "1.0002" },
 	    { 1.0004, "1.0004" },
 	    { 1.0006, "1.0006" },
 	    { 1.0008, "1.0008" },
-	    { 1.001, "1.0010" }
+	    { 1.0010, "1.0010" }
+	};
+	compareTicks(ticks.ticks, expected);
+    }
+    
+    void linear_10000_10010_5()
+    {
+	auto ticks = ScaleTickIntervals::linear({ 10000, 10010, 5 });
+	vector<ScaleTickIntervals::Tick> expected {
+	    { 10000, "10000" },
+	    { 10002, "10002" },
+	    { 10004, "10004" },
+	    { 10006, "10006" },
+	    { 10008, "10008" },
+	    { 10010, "10010" },
+	};
+	compareTicks(ticks.ticks, expected);
+    }
+    
+    void linear_10000_20000_5()
+    {
+	auto ticks = ScaleTickIntervals::linear({ 10000, 20000, 5 });
+	vector<ScaleTickIntervals::Tick> expected {
+	    { 10000, "10000" },
+	    { 12000, "12000" },
+	    { 14000, "14000" },
+	    { 16000, "16000" },
+	    { 18000, "18000" },
+	    { 20000, "20000" },
+	};
+	compareTicks(ticks.ticks, expected);
+    }
+    
+    void linear_m1_1_10()
+    {
+	auto ticks = ScaleTickIntervals::linear({ -1, 1, 10 });
+	vector<ScaleTickIntervals::Tick> expected {
+	    { -1.0, "-1.0" },
+	    { -0.8, "-0.8" },
+	    { -0.6, "-0.6" },
+	    { -0.4, "-0.4" },
+	    { -0.2, "-0.2" },
+	    { 0.0, "0.0" },
+	    { 0.2, "0.2" },
+	    { 0.4, "0.4" },
+	    { 0.6, "0.6" },
+	    { 0.8, "0.8" },
+	    { 1.0, "1.0" }
 	};
 	compareTicks(ticks.ticks, expected);
     }