[Kst] extragear/graphics/kst/kst
George Staikos
staikos at kde.org
Wed Oct 26 06:56:49 CEST 2005
SVN commit 474337 by staikos:
mostly cleanup, comments about inefficiencies, and factor away some extra sin,
cos, and fabs that get called frequently.
M +19 -23 kst2dplot.cpp
M +7 -9 kstplotlabel.cpp
M +1 -0 kstplotlabel.h
--- trunk/extragear/graphics/kst/kst/kst2dplot.cpp #474336:474337
@@ -1751,8 +1751,8 @@
tp.tick /= scale;
tp.org /= scale;
- tp.iLo = (int)((Min-tp.org)/tp.tick);
- tp.iHi = (int)((Max-tp.org)/tp.tick)+1;
+ tp.iLo = int((Min-tp.org)/tp.tick);
+ tp.iHi = int((Max-tp.org)/tp.tick)+1;
iShort = tp.iLo;
// determine the values, and determine if we need to use delta values
@@ -5629,23 +5629,11 @@
Y1 = y_px - ybot_bdr_px - (Y1 - ytop_bdr_px);
}
if (i % _yMinorTicks == 0) {
- p.drawLine(yMajorLeftTickLeft,
- d2i(Y1),
- yMajorLeftTickRight,
- d2i(Y1));
- p.drawLine(yMajorRightTickRight,
- d2i(Y1),
- yMajorRightTickLeft,
- d2i(Y1));
+ p.drawLine(yMajorLeftTickLeft, d2i(Y1), yMajorLeftTickRight, d2i(Y1));
+ p.drawLine(yMajorRightTickRight, d2i(Y1), yMajorRightTickLeft, d2i(Y1));
} else {
- p.drawLine(yMinorLeftTickLeft,
- d2i(Y1),
- yMinorLeftTickRight,
- d2i(Y1));
- p.drawLine(yMinorRightTickRight,
- d2i(Y1),
- yMinorRightTickLeft,
- d2i(Y1));
+ p.drawLine(yMinorLeftTickLeft, d2i(Y1), yMinorLeftTickRight, d2i(Y1));
+ p.drawLine(yMinorRightTickRight, d2i(Y1), yMinorRightTickLeft, d2i(Y1));
}
}
}
@@ -5668,6 +5656,7 @@
if (xTicksOutPlot()) {
yTickPos += d2i(2.0 * xtick_len_px);
}
+ // FIXME: inefficient. We keep reparsing and re-rendering tpx.labels[.]
for (i = tpx.iLo; i < tpx.iHi; i++) {
double xTickPos = x_orig_px + (double)i * xtick_px;
if (_xReversed) {
@@ -5695,6 +5684,7 @@
}
// if top axis is transformed, plot top axis numbers as well
+ // FIXME: inefficient. We keep reparsing and re-rendering tpx.oppLabels[.]
if (_xTransformed && !_suppressTop)
{
int yTopTickPos = d2i(ytop_bdr_px);
@@ -5732,6 +5722,7 @@
if (yTicksOutPlot()) {
xTickPos -= d2i(2.0 * ytick_len_px);
}
+ // FIXME: inefficient. We keep reparsing and re-rendering tpy.labels[.]
for (i = tpy.iLo; i < tpy.iHi; i++) {
double yTickPos = y_orig_px - (double)i * ytick_px;
if (_yReversed) {
@@ -5762,6 +5753,7 @@
if (yTicksOutPlot()) {
xTopTickPos += d2i(2.0 * ytick_len_px);
}
+ // FIXME: inefficient. We keep reparsing and re-rendering tpy.oppLabels[.]
for (i = tpy.iLo; i < tpy.iHi; i++) {
double yTickPos = y_orig_px - (double)i * ytick_px;
if (_yReversed) {
@@ -6428,15 +6420,15 @@
QPtrVector<KstNumberSequence> seqVect(3);
if (pointStylePriority > -1) {
seqVect.insert(pointStylePriority, &pointStyleSeq);
- maxSequences++;
+ ++maxSequences;
}
if (lineStylePriority > -1) {
seqVect.insert(lineStylePriority, &lineStyleSeq);
- maxSequences++;
+ ++maxSequences;
}
if (lineWidthPriority > -1) {
seqVect.insert(lineWidthPriority, &lineWidthSeq);
- maxSequences++;
+ ++maxSequences;
}
if (maxSequences < 0) {
return;
@@ -6444,7 +6436,7 @@
seqVect.resize(maxSequences + 1);
for (int i = 0; i < maxSequences; i++) {
- (seqVect[i])->hookToNextSequence(seqVect[i+1]);
+ seqVect[i]->hookToNextSequence(seqVect[i+1]);
}
KstVCurveList vcurves = kstObjectSubList<KstBaseCurve,KstVCurve>(Curves);
for (KstVCurveList::Iterator i = vcurves.begin(); i != vcurves.end(); ++i) {
@@ -6457,7 +6449,7 @@
if (lineWidthPriority > -1) {
(*i)->pushLineWidth(forPrint ? 5*lineWidthSeq.current() : lineWidthSeq.current());
}
- (seqVect[0])->next();
+ seqVect[0]->next();
}
}
@@ -6582,18 +6574,22 @@
return _topLabel;
}
+
KstPlotLabel *Kst2DPlot::xTickLabel() const {
return _xTickLabel;
}
+
KstPlotLabel *Kst2DPlot::yTickLabel() const {
return _yTickLabel;
}
+
KstPlotLabel *Kst2DPlot::fullTickLabel() const {
return _fullTickLabel;
}
+
#undef LABEL_PRECISION
#include "kst2dplot.moc"
--- trunk/extragear/graphics/kst/kst/kstplotlabel.cpp #474336:474337
@@ -51,6 +51,8 @@
_txt = txt;
_interpret = true;
_rotation = rotation;
+ _sinr = fabs(sin(_rotation * M_PI / 180.0));
+ _cosr = fabs(cos(_rotation * M_PI / 180.0));
_justify = justify;
_fontName = font;
_symbolFontName = "Symbol";
@@ -87,6 +89,8 @@
void KstPlotLabel::setRotation(float rotation) {
_rotation = rotation;
+ _sinr = fabs(sin(_rotation * M_PI / 180.0));
+ _cosr = fabs(cos(_rotation * M_PI / 180.0));
}
@@ -128,15 +132,12 @@
void KstPlotLabel::drawToPainter(Label::Parsed *lp, QPainter& p) {
RenderContext rc(_fontName, _symbolFontName, _absFontSize, &p);
- double rotationRadians = M_PI * (int(_rotation) % 360) / 180;
- double absin = fabs(sin(rotationRadians));
- double abcos = fabs(cos(rotationRadians));
int tx = 0, ty = 0; // translation
rc.x = -_textWidth / 2;
- tx = int(_textWidth * abcos + _textHeight * absin) / 2;
+ tx = int(_textWidth * _cosr + _textHeight * _sinr) / 2;
rc.y = _ascent - _textHeight / 2;
- ty = int(_textHeight * abcos + _textWidth * absin) / 2;
+ ty = int(_textHeight * _cosr + _textWidth * _sinr) / 2;
p.translate(tx, ty);
p.rotate(_rotation);
@@ -181,10 +182,7 @@
QSize KstPlotLabel::size() const {
- double sinr = fabs(sin(_rotation*M_PI/180.0));
- double cosr = fabs(cos(_rotation*M_PI/180.0));
-
- return QSize(d2i(_textWidth*cosr + _textHeight*sinr), d2i(_textHeight*cosr + _textWidth*sinr));
+ return QSize(d2i(_textWidth*_cosr + _textHeight*_sinr), d2i(_textHeight*_cosr + _textWidth*_sinr));
}
--- trunk/extragear/graphics/kst/kst/kstplotlabel.h #474336:474337
@@ -69,6 +69,7 @@
void reparse();
float _rotation;
+ double _cosr, _sinr; // absolute cos and sin of the rotation angle
QString _txt;
QString _symbolFontName;
QString _fontName;
More information about the Kst
mailing list