From: Matthew Fernandez Date: Sat, 22 May 2021 04:14:33 +0000 (-0700) Subject: take const references in Rectangle::overlap{X|Y} instead of mutable pointers X-Git-Tag: 2.47.3~25^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d4efe1879df76bdd4e41dc63787ff94da41599d0;p=graphviz take const references in Rectangle::overlap{X|Y} instead of mutable pointers These functions do not handle nullptr and do not modify their parameter, so a const reference is more appropriate. This change will ease some future work towards removing manual memory management. --- diff --git a/lib/vpsc/generate-constraints.cpp b/lib/vpsc/generate-constraints.cpp index 5c83fc76c..34ffa8098 100644 --- a/lib/vpsc/generate-constraints.cpp +++ b/lib/vpsc/generate-constraints.cpp @@ -84,11 +84,11 @@ static NodeSet getLeftNeighbours(NodeSet &scanline,Node *v) { NodeSet::iterator i=scanline.find(v); while(i!=scanline.begin()) { Node *u=*(--i); - if(u->r->overlapX(v->r)<=0) { + if(u->r->overlapX(*v->r)<=0) { leftv.insert(u); return leftv; } - if(u->r->overlapX(v->r)<=u->r->overlapY(v->r)) { + if(u->r->overlapX(*v->r)<=u->r->overlapY(*v->r)) { leftv.insert(u); } } @@ -99,11 +99,11 @@ static NodeSet getRightNeighbours(NodeSet &scanline,Node *v) { NodeSet::iterator i=scanline.find(v); for(i++;i!=scanline.end(); i++) { Node *u=*(i); - if(u->r->overlapX(v->r)<=0) { + if(u->r->overlapX(*v->r)<=0) { rightv.insert(u); return rightv; } - if(u->r->overlapX(v->r)<=u->r->overlapY(v->r)) { + if(u->r->overlapX(*v->r)<=u->r->overlapY(*v->r)) { rightv.insert(u); } } diff --git a/lib/vpsc/generate-constraints.h b/lib/vpsc/generate-constraints.h index abd228e46..1b22d4a36 100644 --- a/lib/vpsc/generate-constraints.h +++ b/lib/vpsc/generate-constraints.h @@ -54,18 +54,18 @@ public: maxY=y+height()-yBorder; minY=y; } - inline double overlapX(Rectangle *r) const { - if (getCentreX() <= r->getCentreX() && r->minX < getMaxX()) - return getMaxX() - r->minX; - if (r->getCentreX() <= getCentreX() && minX < r->getMaxX()) - return r->getMaxX() - minX; + inline double overlapX(const Rectangle &r) const { + if (getCentreX() <= r.getCentreX() && r.minX < getMaxX()) + return getMaxX() - r.minX; + if (r.getCentreX() <= getCentreX() && minX < r.getMaxX()) + return r.getMaxX() - minX; return 0; } - inline double overlapY(Rectangle *r) const { - if (getCentreY() <= r->getCentreY() && r->minY < getMaxY()) - return getMaxY() - r->minY; - if (r->getCentreY() <= getCentreY() && minY < r->getMaxY()) - return r->getMaxY() - minY; + inline double overlapY(const Rectangle &r) const { + if (getCentreY() <= r.getCentreY() && r.minY < getMaxY()) + return getMaxY() - r.minY; + if (r.getCentreY() <= getCentreY() && minY < r.getMaxY()) + return r.getMaxY() - minY; return 0; } private: