ScrPoints

- a typed Graph point container
- make Graph iterable
- (partly) translate to C++
- move graph functions to Graph
This commit is contained in:
Felix Salfelder 2015-06-16 09:20:21 +02:00
parent 1dfee83441
commit 27064475cc
11 changed files with 227 additions and 186 deletions

View File

@ -241,7 +241,7 @@ bool CurveDiagram::insideDiagram(float x, float y) const
}
// ------------------------------------------------------------
void CurveDiagram::clip(float* &p)
void CurveDiagram::clip(Graph::iterator &p) const
{
rectClip(p);
}

View File

@ -36,7 +36,7 @@ public:
bool insideDiagram(float, float) const;
protected:
void clip(float* &);
void clip(Graph::iterator&) const;
};
#endif

View File

@ -336,28 +336,28 @@ Marker* Diagram::setMarker(int x, int y)
/*!
Cohen-Sutherland clipping algorithm
*/
void Diagram::rectClip(float* &p)
void Diagram::rectClip(Graph::iterator &p) const
{
int code, z=0;
float x=0, y=0, dx, dy;
float x_1 = *(p-4), y_1 = *(p-3);
float x_2 = *(p-2), y_2 = *(p-1);
float x_1 = (p-4)->Scr, y_1 = (p-3)->Scr;
float x_2 = (p-2)->Scr, y_2 = (p-1)->Scr;
int code1 = regionCode(x_1, y_1);
int code2 = regionCode(x_2, y_2);
if((code1 | code2) == 0) return; // line completly inside ?
if(code1 != 0) if(*(p-5) >= 0) { // is there already a line end flag ?
if(code1 != 0) if((p-5)->Scr >= 0) { // is there already a line end flag ?
p++;
*(p-5) = STROKEEND;
(p-5)->Scr = STROKEEND;
}
if(code1 & code2) // line not visible at all ?
goto endWithHidden;
if(code2 != 0) {
*p = STROKEEND;
*(p+1) = x_2;
*(p+2) = y_2;
p->Scr = STROKEEND;
(p+1)->Scr = x_2;
(p+2)->Scr = y_2;
z += 3;
}
@ -401,27 +401,27 @@ void Diagram::rectClip(float* &p)
goto endWithHidden; // line not visible at all ?
}
*(p-4) = x_1;
*(p-3) = y_1;
*(p-2) = x_2;
*(p-1) = y_2;
(p-4)->Scr = x_1;
(p-3)->Scr = y_1;
(p-2)->Scr = x_2;
(p-1)->Scr = y_2;
p += z;
return;
endWithHidden:
*(p-4) = x_2;
*(p-3) = y_2;
(p-4)->Scr = x_2;
(p-3)->Scr = y_2;
p -= 2;
}
/*!
Clipping for round diagrams (smith, polar, ...)
*/
void Diagram::clip(float* &p)
void Diagram::clip(Graph::iterator &p) const
{
float R = float(x2) / 2.0;
float x_1 = *(p-4) - R, y_1 = *(p-3) - R;
float x_2 = *(p-2) - R, y_2 = *(p-1) - R;
float x_1 = (p-4)->Scr - R, y_1 = (p-3)->Scr - R;
float x_2 = (p-2)->Scr - R, y_2 = (p-1)->Scr - R;
float dt1 = R*R; // square of radius
float dt2 = dt1 - x_2*x_2 - y_2*y_2;
@ -429,9 +429,9 @@ void Diagram::clip(float* &p)
if(dt1 >= 0.0) if(dt2 >= 0.0) return; // line completly inside ?
if(dt1 < 0.0) if(*(p-5) >= 0.0) { // is there already a line end flag ?
if(dt1 < 0.0) if((p-5)->Scr >= 0.0) { // is there already a line end flag ?
p++;
*(p-5) = STROKEEND;
(p-5)->Scr = STROKEEND;
}
float x = x_1-x_2;
@ -445,8 +445,8 @@ void Diagram::clip(float* &p)
x_2 += R;
y_2 += R;
if(F <= 0.0) { // line not visible at all ?
*(p-4) = x_2;
*(p-3) = y_2;
(p-4)->Scr = x_2;
(p-3)->Scr = y_2;
p -= 2;
return;
}
@ -455,29 +455,29 @@ void Diagram::clip(float* &p)
R = sqrt(F);
dt1 = C - R;
if((dt1 > 0.0) && (dt1 < D)) { // intersection outside start/end point ?
*(p-4) = x_1 - x*dt1 / D;
*(p-3) = y_1 - y*dt1 / D;
(p-4)->Scr = x_1 - x*dt1 / D;
(p-3)->Scr = y_1 - y*dt1 / D;
code |= 1;
}
else {
*(p-4) = x_1;
*(p-3) = y_1;
(p-4)->Scr = x_1;
(p-3)->Scr = y_1;
}
dt2 = C + R;
if((dt2 > 0.0) && (dt2 < D)) { // intersection outside start/end point ?
*(p-2) = x_1 - x*dt2 / D;
*(p-1) = y_1 - y*dt2 / D;
*p = STROKEEND;
(p-2)->Scr = x_1 - x*dt2 / D;
(p-1)->Scr = y_1 - y*dt2 / D;
p->Scr = STROKEEND;
p += 3;
code |= 2;
}
*(p-2) = x_2;
*(p-1) = y_2;
(p-2)->Scr = x_2;
(p-1)->Scr = y_2;
if(code == 0) { // intersections both lie outside ?
*(p-4) = x_2;
*(p-3) = y_2;
(p-4)->Scr = x_2;
(p-3)->Scr = y_2;
p -= 2;
}
@ -486,6 +486,7 @@ void Diagram::clip(float* &p)
// ------------------------------------------------------------
// g->Points must already be empty!!!
// is this a Graph Member?
void Diagram::calcData(Graph *g)
{
double *px;
@ -493,7 +494,7 @@ void Diagram::calcData(Graph *g)
if(!pz) return;
if(g->cPointsX.count() < 1) return;
int i, z, tmp, Counter=2;
int i, z, Counter=2;
float dx, dy, xtmp, ytmp;
int Size = ((2*(g->cPointsX.getFirst()->count) + 1) * g->countY) + 10;
@ -503,11 +504,13 @@ void Diagram::calcData(Graph *g)
double Dummy = 0.0; // not used
double *py = &Dummy;
float *p = (float*)malloc( Size*sizeof(float) ); // create memory for points
float *p_end;
g->ScrPoints = p_end = p;
g->resizeScrPoints(Size);
auto p = g->begin();
auto p_end = g->begin();
p_end += Size - 9; // limit of buffer
*(p++) = STROKEEND;
p->Scr = STROKEEND;
++p;
assert(p!=g->end());
Axis *pa;
if(g->yAxisNo == 0) pa = &yAxis;
@ -518,26 +521,26 @@ void Diagram::calcData(Graph *g)
case GRAPHSTYLE_SOLID: // ***** solid line ****************************
for(i=g->countY; i>0; i--) { // every branch of curves
px = g->cPointsX.getFirst()->Points;
calcCoordinate(px, pz, py, p, p+1, pa);
calcCoordinate(px, pz, py, &p->Scr, &(p+1)->Scr, pa);
p += 2;
for(z=g->cPointsX.getFirst()->count-1; z>0; z--) { // every point
FIT_MEMORY_SIZE; // need to enlarge memory block ?
calcCoordinate(px, pz, py, p, p+1, pa);
calcCoordinate(px, pz, py, &p->Scr, &(p+1)->Scr, pa);
p += 2;
if(Counter >= 2) // clipping only if an axis is manual
clip(p);
}
if(*(p-3) == STROKEEND)
if((p-3)->Scr == STROKEEND)
p -= 3; // no single point after "no stroke"
else if(*(p-3) == BRANCHEND) {
if((*(p-2) < 0) || (*(p-1) < 0))
else if((p-3)->Scr == BRANCHEND) {
if(((p-2)->Scr < 0) || ((p-1)->Scr < 0))
p -= 2; // erase last hidden point
}
*(p++) = BRANCHEND;
(p++)->Scr = BRANCHEND;
}
*p = GRAPHEND;
p->Scr = GRAPHEND;
/*z = p-g->Points+1;
p = g->Points;
qDebug("\n****** p=%p", p);
@ -559,13 +562,14 @@ for(int zz=0; zz<z; zz+=2)
for(i=g->countY; i>0; i--) { // every branch of curves
px = g->cPointsX.getFirst()->Points;
for(z=g->cPointsX.getFirst()->count; z>0; z--) { // every point
calcCoordinate(px, pz, py, p, p+1, pa);
if(insideDiagram(*p, *(p+1))) // within diagram ?
calcCoordinate(px, pz, py, &p->Scr, &(p+1)->Scr, pa);
if(insideDiagram(p->Scr, (p+1)->Scr)) // within diagram ?
p += 2;
}
*(p++) = BRANCHEND;
(p++)->Scr = BRANCHEND;
assert(p!=g->end());
}
*p = GRAPHEND;
p->Scr = GRAPHEND;
/*qDebug("\n******");
for(int zz=0; zz<60; zz+=2)
qDebug("c: %d/%d", *(g->Points+zz), *(g->Points+zz+1));*/
@ -579,8 +583,10 @@ for(int zz=0; zz<60; zz+=2)
dist = -Stroke;
px = g->cPointsX.getFirst()->Points;
calcCoordinate(px, pz, py, &xtmp, &ytmp, pa);
*(p++) = xtmp;
*(p++) = ytmp;
(p++)->Scr = xtmp;
assert(p!=g->end());
(p++)->Scr = ytmp;
assert(p!=g->end());
Counter = 1;
for(z=g->cPointsX.getFirst()->count-1; z>0; z--) {
dx = xtmp;
@ -592,8 +598,10 @@ for(int zz=0; zz<60; zz+=2)
if(Flag == 1) if(dist <= 0.0) {
FIT_MEMORY_SIZE; // need to enlarge memory block ?
*(p++) = xtmp; // if stroke then save points
*(p++) = ytmp;
(p++)->Scr = xtmp; // if stroke then save points
assert(p!=g->end());
(p++)->Scr = ytmp;
assert(p!=g->end());
if((++Counter) >= 2) clip(p);
continue;
}
@ -601,22 +609,27 @@ for(int zz=0; zz<60; zz+=2)
while(dist > 0) { // stroke or space finished ?
FIT_MEMORY_SIZE; // need to enlarge memory block ?
*(p++) = xtmp - float(dist*cos(alpha)); // linearly interpolate
*(p++) = ytmp - float(dist*sin(alpha));
(p++)->Scr = xtmp - float(dist*cos(alpha)); // linearly interpolate
assert(p!=g->end());
(p++)->Scr = ytmp - float(dist*sin(alpha));
assert(p!=g->end());
if((++Counter) >= 2) clip(p);
if(Flag == 0) {
dist -= Stroke;
if(dist <= 0) {
*(p++) = xtmp; // don't forget point after ...
*(p++) = ytmp; // ... interpolated point
(p++)->Scr = xtmp; // don't forget point after ...
assert(p!=g->end());
(p++)->Scr = ytmp; // ... interpolated point
assert(p!=g->end());
if((++Counter) >= 2) clip(p);
assert(p<g->end());
}
}
else {
dist -= Space;
if(*(p-3) < 0) p -= 2;
else *(p++) = STROKEEND;
if((p-3)->Scr < 0) p -= 2;
else (p++)->Scr = STROKEEND;
if(Counter < 0) Counter = -50000; // if auto-scale
else Counter = 0;
}
@ -625,17 +638,17 @@ for(int zz=0; zz<60; zz+=2)
} // of x loop
if(*(p-3) == STROKEEND)
if((p-3)->Scr == STROKEEND)
p -= 3; // no single point after "no stroke"
else if(*(p-3) == BRANCHEND) {
if((*(p-2) < 0) || (*(p-1) < 0))
else if((p-3)->Scr == BRANCHEND) {
if(((p-2)->Scr < 0) || ((p-1)->Scr < 0))
p -= 2; // erase last hidden point
}
*(p++) = BRANCHEND;
(p++)->Scr = BRANCHEND;
} // of y loop
*p = GRAPHEND;
p->Scr = GRAPHEND;
/*z = p-g->Points+1;
p = g->Points;
qDebug("\n****** p=%p", p);
@ -829,10 +842,7 @@ void Diagram::updateGraphData()
int valid = calcDiagram(); // do not calculate graph data if invalid
foreach(Graph *pg, Graphs) {
if(pg->ScrPoints != 0) {
free(pg->ScrPoints);
pg->ScrPoints = 0;
}
pg->clear();
if((valid & (pg->yAxisNo+1)) != 0)
calcData(pg); // calculate screen coordinates
else if(pg->cPointsY) {

View File

@ -35,13 +35,13 @@
// Enlarge memory block if neccessary.
#define FIT_MEMORY_SIZE \
if(p >= p_end) { \
int pos = p - g->begin(); \
assert(pos<Size); \
Size += 256; \
tmp = p - g->ScrPoints; \
p = p_end = g->ScrPoints = (float*)realloc(g->ScrPoints, Size*sizeof(float)); \
p += tmp; \
p_end += Size - 9; \
} \
g->resizeScrPoints(Size); \
p = g->begin() + pos; \
p_end = g->begin() + (Size - 9); \
}
struct Axis {
double min, max; // least and greatest values of all graph data
@ -117,8 +117,8 @@ protected:
virtual void createAxisLabels();
int regionCode(float, float) const;
virtual void clip(float* &);
void rectClip(float* &);
virtual void clip(Graph::iterator &) const;
void rectClip(Graph::iterator &) const;
virtual void calcData(Graph*);

View File

@ -20,7 +20,7 @@
#include <QPainter>
Graph::Graph(const QString& _Line)
Graph::Graph(const QString& _Line) : Element()
{
Type = isGraph;
@ -33,7 +33,6 @@ Graph::Graph(const QString& _Line)
isSelected = false;
yAxisNo = 0; // left y axis
ScrPoints = 0;
cPointsY = 0;
cPointsX.setAutoDelete(true);
@ -41,8 +40,6 @@ Graph::Graph(const QString& _Line)
Graph::~Graph()
{
if(ScrPoints != 0)
free(ScrPoints);
if(cPointsY != 0)
delete[] cPointsY;
}
@ -50,7 +47,7 @@ Graph::~Graph()
// ---------------------------------------------------------------------
void Graph::paint(ViewPainter *p, int x0, int y0)
{
if(ScrPoints == 0)
if(!ScrPoints.size())
return;
if(isSelected) {
@ -72,16 +69,16 @@ void Graph::paintLines(ViewPainter *p, int x0, int y0)
{
switch(Style) {
case GRAPHSTYLE_STAR:
p->drawStarSymbols(x0, y0, ScrPoints);
drawStarSymbols(x0, y0, p);
break;
case GRAPHSTYLE_CIRCLE:
p->drawCircleSymbols(x0, y0, ScrPoints);
drawCircleSymbols(x0, y0, p);
break;
case GRAPHSTYLE_ARROW:
p->drawArrowSymbols(x0, y0, ScrPoints);
drawArrowSymbols(x0, y0, p);
break;
default:
p->drawLines(x0, y0, ScrPoints);
drawLines(x0, y0, p);
}
}
@ -145,31 +142,31 @@ bool Graph::load(const QString& _s)
// diagram cx/cy. 5 is the precision the user must point onto the graph.
int Graph::getSelected(int x, int y)
{
float *pp = ScrPoints;
if(pp == 0) return -1;
auto pp = ScrPoints.begin();
if(pp == ScrPoints.end()) return -1;
int A, z=0;
int dx, dx2, x1;
int dy, dy2, y1;
int countX = cPointsX.getFirst()->count;
if(*pp <= STROKEEND) {
if(*pp <= BRANCHEND) z++;
if(pp->Scr <= STROKEEND) {
if(pp->Scr <= BRANCHEND) z++;
pp++;
if(*pp <= BRANCHEND) {
if(*pp <= GRAPHEND) return -1; // not even one point ?
if(pp->Scr <= BRANCHEND) {
if(pp->Scr <= GRAPHEND) return -1; // not even one point ?
z++;
pp++;
if(*pp < BRANCHEND) return -1; // not even one point ?
if(pp->Scr < BRANCHEND) return -1; // not even one point ?
}
}
if(Style >= GRAPHSTYLE_STAR) {
// for graph symbols
while(*pp > GRAPHEND) {
if(*pp > STROKEEND) {
dx = x - int(*(pp++));
dy = y - int(*(pp++));
while(pp->Scr > GRAPHEND) {
if(pp->Scr > STROKEEND) {
dx = x - int((++pp)->Scr);
dy = y - int((++pp)->Scr);
if(dx < -5) continue;
if(dx > 5) continue;
@ -186,24 +183,24 @@ int Graph::getSelected(int x, int y)
}
// for graph lines
while(*pp > GRAPHEND) {
while(*pp >= STROKEEND) {
x1 = int(*(pp++));
y1 = int(*(pp++));
while(pp->Scr > GRAPHEND) {
while(pp->Scr >= STROKEEND) {
x1 = int((++pp)->Scr);
y1 = int((++pp)->Scr);
dx = x - x1;
dy = y - y1;
dx2 = int(*pp);
dx2 = int(pp->Scr);
if(dx2 <= STROKEEND) { // end of stroke ?
if(dx2 <= BRANCHEND) break;
pp++;
dx2 = int(*pp); // go on as graph can also be selected between strokes
dx2 = int(pp->Scr); // go on as graph can also be selected between strokes
if(dx2 <= BRANCHEND) break;
}
if(dx < -5) { if(x < dx2-5) continue; } // point between x coordinates ?
else { if(x > 5) if(x > dx2+5) continue; }
dy2 = int(*(pp+1));
dy2 = int((pp+1)->Scr);
if(dy < -5) { if(y < dy2-5) continue; } // point between y coordinates ?
else { if(y > 5) if(y > dy2+5) continue; }
@ -242,3 +239,5 @@ Graph* Graph::sameNewOne()
return pg;
}
// vim:ts=8:sw=2:et

View File

@ -26,6 +26,7 @@
#include <Q3PtrList>
#include <QDateTime>
#include <assert.h>
// meaning of the values in a graph "Points" list
#define STROKEEND -2
@ -59,18 +60,31 @@ public:
Graph(const QString& _Line="");
~Graph();
struct ScrPt{
float Scr;
//double Data; not yet
};
typedef std::vector<ScrPt> container;
typedef container::iterator iterator;
typedef container::const_iterator const_iterator;
void paint(ViewPainter*, int, int);
void paintLines(ViewPainter*, int, int);
QString save();
bool load(const QString&);
int getSelected(int, int);
Graph* sameNewOne();
void clear(){ScrPoints.resize(0);}
void resizeScrPoints(size_t s){assert(s>=ScrPoints.size()); ScrPoints.resize(s);}
iterator begin(){return ScrPoints.begin();}
iterator end(){return ScrPoints.end();}
const_iterator begin() const{return ScrPoints.begin();}
const_iterator end() const{return ScrPoints.end();}
QDateTime lastLoaded; // when it was loaded into memory
int yAxisNo; // which y axis is used
Q3PtrList<DataX> cPointsX;
double *cPointsY;
float *ScrPoints; // data in screen coordinates
int countY; // number of curves
QString Var;
QColor Color;
@ -81,6 +95,15 @@ public:
// for tabular diagram
int Precision; // number of digits to show
int numMode; // real/imag or polar (deg/rad)
private: // painting
void drawLines(int, int, ViewPainter*) const;
void drawStarSymbols(int, int, ViewPainter*) const;
void drawCircleSymbols(int, int, ViewPainter*) const;
void drawArrowSymbols(int, int, ViewPainter*) const;
private:
std::vector<ScrPt> ScrPoints; // data in screen coordinates
};
#endif

View File

@ -952,20 +952,20 @@ void Rect3DDiagram::calcData(Graph *g)
if(!pMem) return;
if(!g->cPointsY) return;
int tmp;
int Size = ((2*(g->cPointsX.getFirst()->count) + 1) * g->countY) + 10;
Size *= 2; // memory for cross grid lines
double *py;
if(g->countY > 1) py = g->cPointsX.at(1)->Points;
float *p = (float*)malloc( Size*sizeof(float) ); // create memory for points
float *p_end;
g->ScrPoints = p_end = p;
g->resizeScrPoints(Size);
auto p = g->begin();
auto p_end = g->begin();
p_end += Size - 9; // limit of buffer
*(p++) = STROKEEND;
p->Scr = STROKEEND;
++p;
float dx=0.0, dy=0.0, xtmp=0.0, ytmp=0.0;
double Stroke=10.0, Space=10.0; // length of strokes and spaces in pixel
switch(g->Style) {
@ -981,22 +981,21 @@ void Rect3DDiagram::calcData(Graph *g)
}
else break;
}
FIT_MEMORY_SIZE; // need to enlarge memory block ?
*(p++) = pMem->x;
*(p++) = pMem->y;
(p++)->Scr = pMem->x;
(p++)->Scr = pMem->y;
break;
}
FIT_MEMORY_SIZE; // need to enlarge memory block ?
if(pMem->done & 8) *(p++) = BRANCHEND; // new branch
if(pMem->done & 8) (p++)->Scr = BRANCHEND; // new branch
if(pMem->done & 4) // point invisible ?
if( *(p-1) >= 0 ) // line already interrupted ?
*(p++) = STROKEEND;
if( (p-1)->Scr >= 0 ) // line already interrupted ?
(p++)->Scr = STROKEEND;
} while(((pMem++)->done & 256) == 0);
*p = GRAPHEND;
p->Scr = GRAPHEND;
return;
case GRAPHSTYLE_DASH:
@ -1021,15 +1020,15 @@ void Rect3DDiagram::calcData(Graph *g)
else break;
}
*(p++) = pMem->x;
*(p++) = pMem->y;
(p++)->Scr = pMem->x;
(p++)->Scr = pMem->y;
break;
}
if(pMem->done & 8)
*(p++) = BRANCHEND; // new branch
(p++)->Scr = BRANCHEND; // new branch
} while(((pMem++)->done & 512) == 0);
*p = GRAPHEND;
p->Scr = GRAPHEND;
return;
}
@ -1058,36 +1057,36 @@ void Rect3DDiagram::calcData(Graph *g)
if(Counter > 1) {
if(Counter == 2) {
*(p++) = dx; // if first points of branch -> paint first one
*(p++) = dy;
(p++)->Scr = dx; // if first points of branch -> paint first one
(p++)->Scr = dy;
}
dx = xtmp - dx;
dy = ytmp - dy;
dist += sqrt(double(dx*dx + dy*dy)); // distance between points
if((Flag == 1) && (dist <= 0.0)) {
FIT_MEMORY_SIZE; // need to enlarge memory block ?
*(p++) = xtmp; // if stroke then save points
*(p++) = ytmp;
(p++)->Scr = xtmp; // if stroke then save points
(p++)->Scr = ytmp;
}
else {
alpha = atan2(double(dy), double(dx)); // slope for interpolation
while(dist > 0) { // stroke or space finished ?
FIT_MEMORY_SIZE; // need to enlarge memory block ?
*(p++) = xtmp - float(dist*cos(alpha)); // linearly interpolate
*(p++) = ytmp - float(dist*sin(alpha));
(p++)->Scr = xtmp - float(dist*cos(alpha)); // linearly interpolate
(p++)->Scr = ytmp - float(dist*sin(alpha));
if(Flag == 0) {
dist -= Stroke;
if(dist <= 0) {
*(p++) = xtmp; // don't forget point after ...
*(p++) = ytmp; // ... interpolated point
(p++)->Scr = xtmp; // don't forget point after ...
(p++)->Scr = ytmp; // ... interpolated point
}
}
else {
dist -= Space;
if(*(p-3) < 0) p -= 2;
else *(p++) = STROKEEND;
if((p-3)->Scr < 0) p -= 2;
else (p++)->Scr = STROKEEND;
}
Flag ^= 1; // toggle between stroke and space
}
@ -1100,25 +1099,25 @@ void Rect3DDiagram::calcData(Graph *g)
dy = ytmp;
if(pMem->done & 8) {
if(*(p-3) == STROKEEND)
if((p-3)->Scr == STROKEEND)
p -= 3; // no single point after "no stroke"
else if(*(p-3) == BRANCHEND) {
if((*(p-2) < 0) || (*(p-1) < 0))
else if((p-3)->Scr == BRANCHEND) {
if(((p-2)->Scr < 0) || ((p-1)->Scr < 0))
p -= 2; // erase last hidden point
}
*(p++) = BRANCHEND; // new branch
(p++)->Scr = BRANCHEND; // new branch
Counter = 0;
Flag = 1;
dist = -Stroke;
}
if(pMem->done & 4) // point invisible ?
if( *(p-1) >= 0 ) // line already interrupted ?
*(p++) = STROKEEND;
if( (p-1)->Scr >= 0 ) // line already interrupted ?
(p++)->Scr = STROKEEND;
} while(((pMem++)->done & 256) == 0);
*p = GRAPHEND;
p->Scr = GRAPHEND;
/*
@ -1161,3 +1160,5 @@ Element* Rect3DDiagram::info(QString& Name, char* &BitmapFile, bool getNewOne)
if(getNewOne) return new Rect3DDiagram();
return 0;
}
// vim:ts=8:sw=2:noet

View File

@ -239,7 +239,7 @@ bool RectDiagram::insideDiagram(float x, float y) const
}
// ------------------------------------------------------------
void RectDiagram::clip(float* &p)
void RectDiagram::clip(Graph::iterator &p) const
{
rectClip(p);
}

View File

@ -36,7 +36,7 @@ public:
bool insideDiagram(float, float) const;
protected:
void clip(float* &);
void clip(Graph::iterator &) const;
};
#endif

View File

@ -98,39 +98,42 @@ void ViewPainter::drawLine(int x1i, int y1i, int x2i, int y2i)
}
// -------------------------------------------------------------
void ViewPainter::drawLines(int x0, int y0, float *pp)
void Graph::drawLines(int x0, int y0, ViewPainter *p) const
{
float DX_, DY_;
float x1, x2, y1, y2;
if(*pp < 0)
auto Scale = p->Scale;
auto Painter = p->Painter;
auto pp = begin();
if(pp->Scr < 0)
pp++;
DX_ = DX + float(x0)*Scale;
DY_ = DY + float(y0)*Scale;
DX_ = p->DX + float(x0)*Scale;
DY_ = p->DY + float(y0)*Scale;
while(*pp > GRAPHEND) {
if(*pp >= 0) {
x1 = DX_ + (*pp)*Scale;
y1 = DY_ - (*(pp+1))*Scale;
while(pp->Scr > GRAPHEND) {
if(pp->Scr >= 0) {
x1 = DX_ + (pp)->Scr*Scale;
y1 = DY_ - (pp+1)->Scr*Scale;
Painter->drawPoint(QPointF(x1, y1));
}
while(*pp > BRANCHEND) { // until end of branch
x1 = DX_ + (*pp)*Scale;
y1 = DY_ - (*(pp+1))*Scale;
while(pp->Scr > BRANCHEND) { // until end of branch
x1 = DX_ + (pp)->Scr*Scale;
y1 = DY_ - (pp+1)->Scr*Scale;
pp += 2;
while(*pp > STROKEEND) { // until end of stroke
x2 = DX_ + (*pp)*Scale;
y2 = DY_ - (*(pp+1))*Scale;
while(pp->Scr > STROKEEND) { // until end of stroke
x2 = DX_ + (pp)->Scr*Scale;
y2 = DY_ - (pp+1)->Scr*Scale;
Painter->drawLine(QLineF(x1, y1, x2, y2));
pp += 2;
if(*pp <= STROKEEND) break;
if(pp->Scr <= STROKEEND) break;
x1 = DX_ + (*pp)*Scale;
y1 = DY_ - (*(pp+1))*Scale;
x1 = DX_ + pp->Scr*Scale;
y1 = DY_ - (pp+1)->Scr*Scale;
Painter->drawLine(QLineF(x2, y2, x1, y1));
pp += 2;
}
if(*pp <= BRANCHEND) break; // end of line ?
if(pp->Scr <= BRANCHEND) break; // end of line ?
pp++;
}
pp++;
@ -138,24 +141,27 @@ void ViewPainter::drawLines(int x0, int y0, float *pp)
}
// -------------------------------------------------------------
void ViewPainter::drawStarSymbols(int x0i, int y0i, float *pp)
void Graph::drawStarSymbols(int x0i, int y0i, ViewPainter *p) const
{
float x3, x0, y0, x1, x2, y1, y2;
float z, DX_, DY_;
if(*pp < 0)
auto Scale = p->Scale;
auto Painter = p->Painter;
auto pp = begin();
if(pp->Scr < 0)
pp++;
DX_ = DX + float(x0i)*Scale;
DY_ = DY + float(y0i)*Scale;
DX_ = p->DX + float(x0i)*Scale;
DY_ = p->DY + float(y0i)*Scale;
while(*pp > GRAPHEND) {
if(*pp >= 0) {
z = DX_ + (*(pp++))*Scale;
while(pp->Scr > GRAPHEND) {
if(pp->Scr >= 0) {
z = DX_ + (pp++)->Scr*Scale;
x0 = z-5.0*Scale;
x3 = z+5.0*Scale;
x1 = z-4.0*Scale;
x2 = z+4.0*Scale;
z = DY_ - (*(pp++))*Scale;
z = DY_ - (pp++)->Scr*Scale;
y0 = z;
y1 = z-4.0*Scale;
y2 = z+4.0*Scale;
@ -168,21 +174,24 @@ void ViewPainter::drawStarSymbols(int x0i, int y0i, float *pp)
}
// -------------------------------------------------------------
void ViewPainter::drawCircleSymbols(int x0i, int y0i, float *pp)
void Graph::drawCircleSymbols(int x0i, int y0i, ViewPainter *p) const
{
float x0, y0;
float z, DX_, DY_;
if(*pp < 0)
auto Scale = p->Scale;
auto Painter = p->Painter;
auto pp = begin();
if(pp->Scr < 0)
pp++;
z = 8.0*Scale;
DX_ = DX + float(x0i)*Scale;
DY_ = DY + float(y0i)*Scale;
DX_ = p->DX + float(x0i)*Scale;
DY_ = p->DY + float(y0i)*Scale;
while(*pp > GRAPHEND) {
if(*pp >= 0) {
x0 = DX_ + (*(pp++)-4.0)*Scale;
y0 = DY_ - (*(pp++)+4.0)*Scale;
while(pp->Scr > GRAPHEND) {
if(pp->Scr >= 0) {
x0 = DX_ + ((pp++)->Scr-4.0)*Scale;
y0 = DY_ - ((pp++)->Scr+4.0)*Scale;
Painter->drawEllipse(QRectF(x0, y0, z, z));
}
else pp++;
@ -190,23 +199,26 @@ void ViewPainter::drawCircleSymbols(int x0i, int y0i, float *pp)
}
// -------------------------------------------------------------
void ViewPainter::drawArrowSymbols(int x0i, int y0i, float *pp)
void Graph::drawArrowSymbols(int x0i, int y0i, ViewPainter *p) const
{
int x0, y0, x1, x2, y1, y2;
float DX_, DY_;
if(*pp < 0)
auto Scale = p->Scale;
auto Painter = p->Painter;
auto pp = begin();
if(pp->Scr < 0)
pp++;
DX_ = DX + float(x0i)*Scale;
DY_ = DY + float(y0i)*Scale;
DX_ = p->DX + float(x0i)*Scale;
DY_ = p->DY + float(y0i)*Scale;
y2 = DY_;
while(*pp > GRAPHEND) {
if(*pp >= 0) {
x0 = DX_ + (*(pp++))*Scale;
while(pp->Scr > GRAPHEND) {
if(pp->Scr >= 0) {
x0 = DX_ + (pp++)->Scr*Scale;
x1 = x0-4.0*Scale;
x2 = x0+4.0*Scale;
y0 = DY_ - (*(pp++))*Scale;
y0 = DY_ - (pp++)->Scr*Scale;
y1 = y0+7.0*Scale;
Painter->drawLine(QLineF(x0, y0, x0, y2));
Painter->drawLine(QLineF(x1, y1, x0, y0));

View File

@ -42,7 +42,6 @@ public:
void map(int, int, int&, int&);
void drawPoint(int, int);
void drawLine (int, int, int, int);
void drawLines(int, int, float*);
void drawRect (int, int, int, int);
void drawRectD(int, int, int, int);
void drawRoundRect(int, int, int, int);
@ -53,9 +52,6 @@ public:
void fillRect(int, int, int, int, const QColor&);
void eraseRect(int, int, int, int);
void drawResizeRect(int, int);
void drawStarSymbols(int, int, float*);
void drawCircleSymbols(int, int, float*);
void drawArrowSymbols(int, int, float*);
QPainter *Painter;
float Scale, FontScale, PrintScale, DX , DY;