[Kst] kdeextragear-2/kst
George Staikos
staikos at kde.org
Mon Dec 6 00:51:14 CET 2004
CVS commit by staikos:
fix a big pile of histogram bugs (memory errors, inconsistent internal state,
etc) pointed out by the regression tests. Actually the same number of tests
still fail...
M +33 -4 kst/ksthistogram.cpp 1.39
M +1 -0 kst/ksthistogram.h 1.26
M +6 -5 tests/testhistogram.cpp 1.5
--- kdeextragear-2/kst/kst/ksthistogram.cpp #1.38:1.39
@@ -121,5 +121,6 @@ void KstHistogram::commonConstructor(con
NBins = 2;
}
- Bins = new unsigned long[in_n_bins];
+ Bins = new unsigned long[NBins];
+ NS = 3*NBins+1;
KstVectorPtr v = new KstVector(in_tag+"-bins", NBins);
@@ -167,5 +170,5 @@ KstObject::UpdateType KstHistogram::upda
double temp_xMin, temp_xMax;
KstHistogram::AutoBin(V, &temp_NBins, &temp_xMax, &temp_xMin);
- setNBins(temp_NBins);
+ internalSetNBins(temp_NBins);
setXRange(temp_xMin, temp_xMax);
}
@@ -266,5 +272,6 @@ void KstHistogram::setXRange(double xmin
}
-void KstHistogram::setNBins(int in_n_bins) {
+
+void KstHistogram::internalSetNBins(int in_n_bins) {
delete[] Bins;
@@ -274,10 +281,17 @@ void KstHistogram::setNBins(int in_n_bin
NBins = 2;
}
- Bins = new unsigned long[in_n_bins];
+ Bins = new unsigned long[NBins];
W = (MaxX - MinX)/(double)NBins;
+ NS = 3*NBins+1;
(*_bVector)->resize(NBins);
(*_hVector)->resize(NBins);
+}
+
+void KstHistogram::setNBins(int in_n_bins) {
+ _realTimeAutoBin = false;
+ internalSetNBins(in_n_bins);
+ update(); // Have to update here otherwise Bins[] is invalid!
}
--- kdeextragear-2/kst/kst/ksthistogram.h #1.25:1.26
@@ -109,4 +109,5 @@ private:
KstVectorMap::Iterator _bVector, _hVector;
+ void internalSetNBins(int in_n_bins);
};
--- kdeextragear-2/kst/tests/testhistogram.cpp #1.4:1.5
@@ -41,6 +41,4 @@ void doTests() {
doTest(h1->propertyString() == "Histogram: V1");
doTest(!h1->realTimeAutoBin()); // should be false by default
- h1->setRealTimeAutoBin(true);
- doTest(h1->realTimeAutoBin());
doTest(h1->type() == KST_HISTOGRAM);
doTest(h1->nBins() == 10);
@@ -49,17 +47,20 @@ void doTests() {
doTest(h1->vNumSamples() == 100);
int count = 0;
- for (int i = 1; i < 10*4; i += 3) {
+ for (int i = 1; i < 10*3+1; i += 3) {
double x, y;
h1->point(i, x, y);
count += int(y);
}
+ h1->setRealTimeAutoBin(true);
+ doTest(h1->realTimeAutoBin());
//dumpPoints(h1, 10);
doTest(count == 100); // should account for the whole vector
h1->setNBins(11);
+ doTest(!h1->realTimeAutoBin());
doTest(h1->nBins() == 11);
doTest(h1->vMin() == 0.0);
doTest(h1->vMax() == 10.0);
doTest(h1->vNumSamples() == 100);
- for (int i = 1; i < 11*4; i += 3) {
+ for (int i = 1; i < 11*3+1; i += 3) {
double x, y;
h1->point(i, x, y);
@@ -73,5 +74,5 @@ void doTests() {
doTest(h1->vMax() == 10.0);
doTest(h1->vNumSamples() == 100);
- for (int i = 1; i < 9*4; i += 3) {
+ for (int i = 1; i < 9*3+1; i += 3) {
double x, y;
h1->point(i, x, y);
More information about the Kst
mailing list