]> granicus.if.org Git - graphviz/commitdiff
take const references in Rectangle::overlap{X|Y} instead of mutable pointers
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 22 May 2021 04:14:33 +0000 (21:14 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 29 May 2021 00:02:43 +0000 (17:02 -0700)
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.

lib/vpsc/generate-constraints.cpp
lib/vpsc/generate-constraints.h

index 5c83fc76c38009913936b785341963b12959f057..34ffa809858c5807ac5e7fa58aa89372393f1221 100644 (file)
@@ -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);
                }
        }
index abd228e4674317ace08c7b5b0dd8a83bfeef7fc2..1b22d4a363b75238dcb2bdc793781d0c85a9bf71 100644 (file)
@@ -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: