[Kst] extragear/graphics/kst/kst
George Staikos
staikos at kde.org
Wed Oct 26 20:26:21 CEST 2005
SVN commit 474562 by staikos:
a bunch of smaller optimizations and cleanups
M +6 -8 kstpoint.cpp
M +1 -1 kstpoint.h
M +31 -40 kstvcurve.cpp
--- trunk/extragear/graphics/kst/kst/kstpoint.cpp #474561:474562
@@ -18,6 +18,7 @@
#include "kstpoint.h"
+#include <kglobal.h>
KstPoint::KstPoint() {
Type = 0;
@@ -40,7 +41,8 @@
int s;
if (size == -1) {
- s = (p->window().width()+p->window().height())/400;
+ QRect r = p->window();
+ s = (r.width() + r.height())/400;
} else {
s = size/200;
}
@@ -147,14 +149,10 @@
p->setBrush(QBrush::NoBrush);
}
-int KstPoint::dim(QPainter *p) const {
- int s = (p->window().width()+p->window().height())/400;
- if (s < 1) {
- s = 1;
- }
-
- return s;
+int KstPoint::dim(QPainter *p) const {
+ QRect r = p->window();
+ return kMax(1, (r.width() + r.height() / 400));
}
// vim: ts=2 sw=2 et
--- trunk/extragear/graphics/kst/kst/kstpoint.h #474561:474562
@@ -38,7 +38,7 @@
void setType(int type);
/** get the type of the point for storage */
int type() const;
- /** Get the dimention of the current point type */
+ /** Get the dimension of the current point type */
int dim(QPainter *p) const;
private:
int Type;
--- trunk/extragear/graphics/kst/kst/kstvcurve.cpp #474561:474562
@@ -563,7 +563,7 @@
// monotonically rising: we can do a binary search
// should be reasonably fast
- if (xIsRising()) {
+ if (xv->isRising()) {
int i_top = sampleCount() - 1;
int i_bot = 0;
@@ -620,7 +620,7 @@
int i,i0, iN, index;
int sc = sampleCount();
- if (xIsRising()) {
+ if (xv->isRising()) {
iN = i0 = getIndexNearX(x);
xi = xv->interpolate(i0, NS);
@@ -760,7 +760,6 @@
QPainter *p = context.p;
QColor _foregroundColor = context._foregroundColor;
- QRegion clipRegion;
double Lx = context.Lx, Hx = context.Hx, Ly = context.Ly, Hy = context.Hy;
double m_X = context.m_X, m_Y = context.m_Y;
double b_X = context.b_X, b_Y = context.b_Y;
@@ -772,24 +771,17 @@
double X1 = 0.0, Y1 = 0.0;
double X2 = 0.0, Y2 = 0.0;
double last_x1, last_y1;
- bool overlap;
- bool clipping;
+ bool overlap = false;
int i_pt;
- clipRegion = p->clipRegion();
- clipping = p->hasClipping();
- p->setClipRect(int(Lx), int(Ly), int(Hx-Lx), int(Hy-Ly), QPainter::CoordPainter);
+ QRegion clipRegion = p->clipRegion();
+ bool clipping = p->hasClipping();
+ p->setClipRect(int(Lx), int(Ly), int(Hx - Lx), int(Hy - Ly), QPainter::CoordPainter);
#ifdef BENCHMARK
QTime bench_time, benchtmp;
int b_1 = 0, b_2 = 0, b_3 = 0, b_4 = 0;
-#endif
-
-#ifdef BENCHMARK
bench_time.start();
-#endif
- overlap = false;
-#ifdef BENCHMARK
benchtmp.start();
#endif
@@ -798,7 +790,7 @@
int i0, iN;
int width = kMax(lineWidth(), penWidth);
- if (xIsRising()) {
+ if (xv->isRising()) {
i0 = getIndexNearX(XMin);
if (i0 > 0) {
--i0;
@@ -822,7 +814,6 @@
int index = 0;
int i0Start = i0;
- double lineWidth = (double)width;
p->setPen(QPen(color(), width, style));
// optimize - isnan seems expensive, at least in gcc debug mode
@@ -1195,19 +1186,25 @@
if (visible) {
if (barStyle() == 1) { // filled
- p->fillRect(d2i(X1), d2i(Y1), d2i(X2)-d2i(X1), d2i(Y2)-d2i(Y1), color());
+ int X1i = d2i(X1);
+ int Y1i = d2i(Y1);
+ p->fillRect(X1i, Y1i, d2i(X2) - X1i, d2i(Y2) - Y1i, color());
}
if (has_top) {
- p->drawLine(d2i(X1-(width/2)), d2i(Y1), d2i(X2+(width/2)), d2i(Y1));
+ int Y1i = d2i(Y1);
+ p->drawLine(d2i(X1-(width/2)), Y1i, d2i(X2+(width/2)), Y1i);
}
if (has_bot) {
- p->drawLine(d2i(X1-(width/2)), d2i(Y2), d2i(X2-(width/2)), d2i(Y2));
+ int Y2i = d2i(Y2);
+ p->drawLine(d2i(X1-(width/2)), Y2i, d2i(X2-(width/2)), Y2i);
}
if (has_left) {
- p->drawLine(d2i(X1), d2i(Y1-(width/2)), d2i(X1), d2i(Y2+(width/2)));
+ int X1i = d2i(X1);
+ p->drawLine(X1i, d2i(Y1-(width/2)), X1i, d2i(Y2+(width/2)));
}
if (has_right) {
- p->drawLine(d2i(X2), d2i(Y1-(width/2)), d2i(X2), d2i(Y2+(width/2)));
+ int X2i = d2i(X2);
+ p->drawLine(X2i, d2i(Y1-(width/2)), X2i, d2i(Y2+(width/2)));
}
}
}
@@ -1222,17 +1219,13 @@
// draw the points, if any...
if (hasPoints()) {
if (hasLines() && pointDensity() != 0) {
- QRegion rgn((int)Lx, (int)Ly, (int)(Hx-Lx), (int)(Hy-Ly), QRegion::Rectangle);
- QPoint pt;
- int size;
-
- size = (int)pow(3.0, KSTPOINTDENSITY_MAXTYPE - pointDensity());
- if (Hx-Lx > Hy-Ly) {
- size = (int)(Hx-Lx) / size;
- } else {
- size = (int)(Hy-Ly) / size;
- }
- for (i_pt = i0; i_pt <= iN; i_pt++) {
+ const double w = Hx - Lx;
+ const double h = Hy - Ly;
+ QRegion rgn((int)Lx, (int)Ly, (int)w, (int)h);
+ const int size = int(kMax(w, h)) / int(pow(3.0, KSTPOINTDENSITY_MAXTYPE - pointDensity()));
+ QPoint pt;
+ const int lineWidth = this->lineWidth();
+ for (i_pt = i0; i_pt <= iN; ++i_pt) {
rX = xv->interpolate(i_pt, NS);
rY = yv->interpolate(i_pt, NS);
if (_xLog) {
@@ -1245,12 +1238,13 @@
pt.setX( d2i(m_X * rX + b_X) );
pt.setY( d2i(m_Y * rY + b_Y) );
if (rgn.contains(pt)) {
- Point.draw(p, pt.x(), pt.y(), lineWidth());
+ Point.draw(p, pt.x(), pt.y(), lineWidth);
rgn -= QRegion(pt.x()-(size/2), pt.y()-(size/2), size, size, QRegion::Ellipse);
}
}
} else {
- for (i_pt = i0; i_pt <= iN; i_pt++) {
+ const int lineWidth = this->lineWidth();
+ for (i_pt = i0; i_pt <= iN; ++i_pt) {
rX = xv->interpolate(i_pt, NS);
rY = yv->interpolate(i_pt, NS);
if (_xLog) {
@@ -1263,7 +1257,7 @@
X1 = m_X * rX + b_X;
Y1 = m_Y * rY + b_Y;
if (X1 >= Lx && X1 <= Hx && Y1 >= Ly && Y1 <= Hy) {
- Point.draw(p, d2i(X1), d2i(Y1), lineWidth());
+ Point.draw(p, d2i(X1), d2i(Y1), lineWidth);
}
}
}
@@ -1353,7 +1347,6 @@
int X1i = d2i(X1);
int X2i = d2i(X2);
int Y1i = d2i(Y1);
- int Y2i = d2i(Y2);
p->drawLine(X1i, Y1i, X2i, Y1i);
if (do_low_flag) {
p->drawLine(X1i, Y1i + Point.dim(p), X1i, Y1i - Point.dim(p));
@@ -1443,7 +1436,6 @@
if (X1 >= Lx && X1 <= Hx && Y1 >= Ly && Y2 <= Hy) {
int X1i = d2i(X1);
- int X2i = d2i(X2);
int Y1i = d2i(Y1);
int Y2i = d2i(Y2);
p->drawLine(X1i, Y1i, X1i, Y2i);
@@ -1490,7 +1482,7 @@
// get range of the curve to search for min/max
int i0, iN;
- if (xIsRising()) {
+ if (xv->isRising()) {
i0 = getIndexNearX(xFrom);
iN = getIndexNearX(xTo);
} else {
@@ -1554,8 +1546,7 @@
p->setPen(QPen(color(), lineWidth()));
KstPoint tmppoint;
tmppoint.setType(Point.type());
- tmppoint.draw(p, bound.left() + bound.width()/2, bound.top() + bound.height()/2,
- lineWidth(), 600);
+ tmppoint.draw(p, bound.left() + bound.width()/2, bound.top() + bound.height()/2, lineWidth(), 600);
}
}
More information about the Kst
mailing list