Commit fab91099 authored by JasonPries's avatar JasonPries
Browse files

Change Sketch Boundary and Contour vector from raw pointers to shared pointers

parent 000b41f0
......@@ -128,9 +128,9 @@ public:
InsertPointResult insert_point(Point const p) { return insert_point(p, Edges.size() - 1); };
protected:
Contour const *Boundary;
std::shared_ptr<Contour> Boundary;
std::vector<Curve const *> Curves;
std::vector<Contour const *> Contours;
std::vector<std::shared_ptr<Contour>> Contours;
std::vector<Point> Points;
std::vector<Edge> Edges;
......
......@@ -75,7 +75,7 @@ void Constellation::pop(const Curve *c) {
}
}
bool Constellation::boundary(Contour *c) {
bool Constellation::boundary(std::shared_ptr<Contour> c) {
std::vector<const Curve *> curves;
std::vector<bool> orientation;
......@@ -121,14 +121,14 @@ bool Constellation::boundary(Contour *c) {
}
}
bool Constellation::contours(std::vector<Contour *> &contours) {
bool Constellation::contours(std::vector<std::shared_ptr<Contour>> &contours) {
std::vector<const Curve *> contour_curves;
std::vector<bool> orientation;
while (size() > 0) {
bool success = find_closed_contour(contour_curves, orientation);
if (success) {
contours.push_back(new Contour(contour_curves, orientation));
contours.push_back(std::make_shared<Contour>(contour_curves, orientation));
} else {
return false;
}
......
......@@ -12,9 +12,9 @@ public:
size_t size() { return Stars.size(); };
bool contours(std::vector<Contour *> &contours);
bool contours(std::vector<std::shared_ptr<Contour>> &contours);
bool boundary(Contour *c);
bool boundary(std::shared_ptr<Contour>);
private:
std::list<Star> Stars;
......
......@@ -3,12 +3,10 @@
Sketch::Sketch() {
NumEquations = 0;
NumVariables = 0;
Boundary = new Contour();
Boundary = std::make_shared<Contour>();
}
void Sketch::delete_me() {
delete Boundary;
Variables.clear();
Verticies.clear();
......@@ -28,9 +26,6 @@ void Sketch::delete_me() {
}
Patterns.clear();
for (auto x : Contours) {
delete x;
}
Contours.clear();
};
......@@ -78,7 +73,6 @@ void Sketch::solve() {
bool Sketch::build() {
Constellation c = Constellation(this);
bool success = c.boundary(Boundary);
Contours.resize(0);
......
......@@ -155,9 +155,9 @@ public:
const Constraint *constraint(size_t i) const { return Constraints[i]; };
const Contour *contour(size_t i) const { return Contours[i]; };
std::shared_ptr<Contour> contour(size_t i) const { return Contours[i]; };
const Contour *boundary() const { return Boundary; };
std::shared_ptr<Contour> boundary() const { return Boundary; };
size_t size() const { return (Verticies.size() + Curves.size() + Constraints.size()); };
......@@ -178,7 +178,6 @@ public:
template<class T, class...ArgT>
std::shared_ptr<T> new_element_SHARED_PTR(ArgT &&... args);
//#TODO: Add elements by pointer
void add_element(std::shared_ptr<Vertex> v);
void add_element(Curve &c);
......@@ -217,9 +216,9 @@ private:
std::vector<Constraint *> Constraints;
std::vector<Pattern *> Patterns;
std::vector<Contour *> Contours;
std::vector<std::shared_ptr<Contour>> Contours;
Contour *Boundary;
std::shared_ptr<Contour> Boundary;
size_t NumVariables;
size_t NumEquations;
......
......@@ -131,7 +131,7 @@ TEST(RotateCopy, nonoverlapping) {
TEST(RotateCopy, overlapping) {
for (bool remove_internal : {true, false}) {
Sketch s;
Sketch s = Sketch();
size_t N = 4;
double a_deg = 360.0 / N;
......
......@@ -214,7 +214,7 @@ TEST(Star, find_closed_contour_0) {
EXPECT_EQ(sketch.size_contours(), 1);
EXPECT_TRUE(*sketch.contour(0) == *sketch.boundary());
const Contour *contour = sketch.contour(0);
auto contour = sketch.contour(0);
EXPECT_TRUE(contour->size() == 3);
EXPECT_TRUE(&l0 == contour->curve(0) || &l0 == contour->curve(1) || &l0 == contour->curve(2));
EXPECT_TRUE(&l5 == contour->curve(0) || &l5 == contour->curve(1) || &l5 == contour->curve(2));
......@@ -255,7 +255,7 @@ TEST(Star, find_closed_contour_1) {
EXPECT_TRUE(sketch.size_contours() == 1);
EXPECT_TRUE(*sketch.contour(0) == *sketch.boundary());
const Contour *contour = sketch.contour(0);
auto contour = sketch.contour(0);
EXPECT_TRUE(contour->size() == 3);
EXPECT_TRUE(&l0 == contour->curve(0) || &l0 == contour->curve(1) || &l0 == contour->curve(2));
EXPECT_TRUE(&l1 == contour->curve(0) || &l1 == contour->curve(1) || &l1 == contour->curve(2));
......@@ -302,7 +302,7 @@ TEST(Star, find_closed_contour_2) {
EXPECT_FALSE(sketch.contour(0) == sketch.boundary());
EXPECT_FALSE(sketch.contour(1) == sketch.boundary());
const Contour *contour = sketch.contour(1);
auto contour = sketch.contour(1);
EXPECT_EQ(contour->size(), 3);
EXPECT_TRUE(&l0 == contour->curve(0) || &l0 == contour->curve(1) || &l0 == contour->curve(2));
......@@ -316,8 +316,8 @@ TEST(Star, find_closed_contour_2) {
EXPECT_TRUE(&l4 == contour->curve(0) || &l4 == contour->curve(1) || &l4 == contour->curve(2));
EXPECT_TRUE(&c0 == contour->curve(0) || &c0 == contour->curve(1) || &c0 == contour->curve(2));
const Contour *c0 = sketch.contour(0);
const Contour *c1 = sketch.contour(1);
auto c0 = sketch.contour(0);
auto c1 = sketch.contour(1);
for (size_t i = 0; i < 3; ++i) {
for (size_t j = 0; j < 3; ++j) {
if (c0->curve(i) == c1->curve(j)) {
......@@ -329,7 +329,7 @@ TEST(Star, find_closed_contour_2) {
// Test Boundary
{
const Contour *boundary = sketch.boundary();
auto boundary = sketch.boundary();
EXPECT_EQ(boundary->size(), 4);
EXPECT_TRUE(&l0 == boundary->curve(0) || &l0 == boundary->curve(1) || &l0 == boundary->curve(2) || &l0 == boundary->curve(3));
......@@ -369,7 +369,7 @@ TEST(Star, find_closed_contour_3) {
EXPECT_TRUE(sketch.size_contours() == 1);
EXPECT_TRUE(*sketch.contour(0) == *sketch.boundary());
const Contour *contour = sketch.contour(0);
auto contour = sketch.contour(0);
EXPECT_TRUE(contour->size() == 2);
EXPECT_TRUE(&arc == contour->curve(0) || &arc == contour->curve(1));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment