]> granicus.if.org Git - graphviz/commitdiff
take a vector in generateXConstraints instead of size and C pointer
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 22 May 2021 04:00:29 +0000 (21:00 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 29 May 2021 00:02:43 +0000 (17:02 -0700)
This is a stepping stone to removing some manual memory management of the
Rectangles collection.

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

index 36872cbd2363456a666bb9cafba7755aa508c2e7..83d0fffdd12fe7d5010862c09cc03cda436b9b9a 100644 (file)
@@ -43,7 +43,7 @@ int genXConstraints(int n, boxf* bb, Variable** vs, Constraint*** cs,int transit
        for(int i=0;i<n;i++) {
                rs[i]=new Rectangle(bb[i].LL.x,bb[i].UR.x,bb[i].LL.y,bb[i].UR.y);
        }
-       int m = generateXConstraints(n,rs.data(),vs,*cs,transitiveClosure?true:false);
+       int m = generateXConstraints(rs,vs,*cs,transitiveClosure?true:false);
        for(int i=0;i<n;i++) {
                delete rs[i];
        }
index 4c598fbc264b2258a9ab6be185331f7b6c6730e3..5f276e78d9f1fb7bccd1e00f0775f2de95eb056c 100644 (file)
@@ -137,10 +137,12 @@ static bool compare_events(const Event &ea, const Event &eb) {
  * useNeighbourLists determines whether or not a heuristic is used to deciding whether to resolve
  * all overlap in the x pass, or leave some overlaps for the y pass.
  */
-int generateXConstraints(const int n, Rectangle** rs, Variable** vars, Constraint** &cs, const bool useNeighbourLists) {
+int generateXConstraints(vector<Rectangle*> &rs, Variable** vars,
+         Constraint** &cs, const bool useNeighbourLists) {
+
        vector<Event> events;
-       events.reserve(2 * n);
-       for(int i=0;i<n;i++) {
+       events.reserve(2 * rs.size());
+       for(size_t i=0;i<rs.size();i++) {
                vars[i]->desiredPosition=rs[i]->getCentreX();
                Node *v = new Node(vars[i],rs[i],rs[i]->getCentreX());
                events.emplace_back(Open,v,rs[i]->getMinY());
index a209d7dcc9f6cf0b5cf9a4ec84bc7b317e8af683..68f15a09b9d9b41f53f46f86f3510702104a56f5 100644 (file)
@@ -17,6 +17,7 @@
  */
 #pragma once
 #include <iostream>
+#include <vector>
 
 class Rectangle {      
        friend std::ostream& operator <<(std::ostream &os, const Rectangle &r);
@@ -76,5 +77,6 @@ struct Variable;
 struct Constraint;
 
 // returns number of constraints generated
-int generateXConstraints(const int n, Rectangle** rs, Variable** vars, Constraint** &cs, const bool useNeighbourLists);
+int generateXConstraints(std::vector<Rectangle*> &rs, Variable** vars,
+       Constraint** &cs, const bool useNeighbourLists);
 int generateYConstraints(const int n, Rectangle** rs, Variable** vars, Constraint** &cs);