Commit 1c94c79a authored by JasonPries's avatar JasonPries
Browse files

Change Sketch Pattern vector from raw pointers to shared pointers

parent fab91099
...@@ -21,9 +21,6 @@ void Sketch::delete_me() { ...@@ -21,9 +21,6 @@ void Sketch::delete_me() {
} }
Constraints.clear(); Constraints.clear();
for (auto x : Patterns) {
delete x;
}
Patterns.clear(); Patterns.clear();
Contours.clear(); Contours.clear();
...@@ -93,9 +90,9 @@ void Sketch::add_element(Constraint &c) { ...@@ -93,9 +90,9 @@ void Sketch::add_element(Constraint &c) {
add_element(Constraints, c); add_element(Constraints, c);
} }
void Sketch::add_element(Pattern &p) { void Sketch::add_element(std::shared_ptr<Pattern> p) {
add_element(Patterns, p); add_element(Patterns, p);
p.register_elements(this); p->register_elements(this);
} }
template<> template<>
......
...@@ -184,7 +184,7 @@ public: ...@@ -184,7 +184,7 @@ public:
void add_element(Constraint &c); void add_element(Constraint &c);
void add_element(Pattern &p); void add_element(std::shared_ptr<Pattern> p);
void solve(); void solve();
...@@ -214,7 +214,7 @@ private: ...@@ -214,7 +214,7 @@ private:
std::vector<std::shared_ptr<Vertex>> Verticies; std::vector<std::shared_ptr<Vertex>> Verticies;
std::vector<Curve *> Curves; std::vector<Curve *> Curves;
std::vector<Constraint *> Constraints; std::vector<Constraint *> Constraints;
std::vector<Pattern *> Patterns; std::vector<std::shared_ptr<Pattern>> Patterns;
std::vector<std::shared_ptr<Contour>> Contours; std::vector<std::shared_ptr<Contour>> Contours;
......
...@@ -74,7 +74,7 @@ TEST(MirrorCopy, nonoverlapping) { ...@@ -74,7 +74,7 @@ TEST(MirrorCopy, nonoverlapping) {
std::vector<const Curve *> vec{&l0, &l1, &l2, &l3}; std::vector<const Curve *> vec{&l0, &l1, &l2, &l3};
MirrorCopy &mc0 = s.new_element<MirrorCopy>(vec, &l4); auto mc0 = s.new_element_SHARED_PTR<MirrorCopy>(vec, &l4);
s.save_as<SaveMethod::Rasterize>(SAVE_DIR, "Pattern__Mirror_nonoverlapping_square"); s.save_as<SaveMethod::Rasterize>(SAVE_DIR, "Pattern__Mirror_nonoverlapping_square");
...@@ -127,7 +127,7 @@ TEST(MirrorCopy, overlapping) { ...@@ -127,7 +127,7 @@ TEST(MirrorCopy, overlapping) {
// std::vector<const Curve *> vec{&l0, &l1, &l2, &l3}; // std::vector<const Curve *> vec{&l0, &l1, &l2, &l3};
auto mvec = s.curves(); auto mvec = s.curves();
MirrorCopy &mc0 = s.new_element<MirrorCopy>(mvec, &l3, remove_internal); auto mc0 = s.new_element_SHARED_PTR<MirrorCopy>(mvec, &l3, remove_internal);
s.save_as<SaveMethod::Rasterize>(SAVE_DIR, std::string("Mirror__overlapping_parallelogram")+std::to_string(remove_internal)); s.save_as<SaveMethod::Rasterize>(SAVE_DIR, std::string("Mirror__overlapping_parallelogram")+std::to_string(remove_internal));
...@@ -185,7 +185,7 @@ TEST(MirrorCopy, multiple_overlapping) { ...@@ -185,7 +185,7 @@ TEST(MirrorCopy, multiple_overlapping) {
//std::vector<const Curve *> vec{&l0, &l1, &l2, &l3, &l4, &l5, &l6}; //std::vector<const Curve *> vec{&l0, &l1, &l2, &l3, &l4, &l5, &l6};
auto mvec = s.curves(); auto mvec = s.curves();
s.new_element<MirrorCopy>(mvec, &l3, remove_internal); s.new_element_SHARED_PTR<MirrorCopy>(mvec, &l3, remove_internal);
s.solve(); s.solve();
s.build(); s.build();
......
...@@ -95,7 +95,7 @@ TEST(RotateCopy, nonoverlapping) { ...@@ -95,7 +95,7 @@ TEST(RotateCopy, nonoverlapping) {
Angle &a0 = s.new_element<Angle>(l0, l1, a_deg); Angle &a0 = s.new_element<Angle>(l0, l1, a_deg);
std::vector<const Curve *> vec{&l0, &l1, &c0, &c1}; std::vector<const Curve *> vec{&l0, &l1, &c0, &c1};
RotateCopy &r0 = s.new_element<RotateCopy>(vec, v0, 360.0 / (N - 1), N - 2); auto r0 = s.new_element_SHARED_PTR<RotateCopy>(vec, v0, 360.0 / (N - 1), N - 2);
s.save_as<SaveMethod::Rasterize>(SAVE_DIR, "Rotate__non_overlapping_0"); s.save_as<SaveMethod::Rasterize>(SAVE_DIR, "Rotate__non_overlapping_0");
...@@ -172,7 +172,7 @@ TEST(RotateCopy, overlapping) { ...@@ -172,7 +172,7 @@ TEST(RotateCopy, overlapping) {
s.save_as<SaveMethod::Rasterize>(SAVE_DIR, std::string("Rotate__overlapping_base_0_") + std::to_string(remove_internal)); s.save_as<SaveMethod::Rasterize>(SAVE_DIR, std::string("Rotate__overlapping_base_0_") + std::to_string(remove_internal));
std::vector<const Curve *> rvec = {&l0, &l1, &c0, &c1}; std::vector<const Curve *> rvec = {&l0, &l1, &c0, &c1};
RotateCopy &r0 = s.new_element<RotateCopy>(rvec, v0, 360.0 / N, N - 2, remove_internal); auto r0 = s.new_element_SHARED_PTR<RotateCopy>(rvec, v0, 360.0 / N, N - 2, remove_internal);
s.solve(); s.solve();
s.build(); s.build();
......
...@@ -32,10 +32,10 @@ TEST(Stator, 0) { ...@@ -32,10 +32,10 @@ TEST(Stator, 0) {
CircularArc &c3 = sketch.new_element<CircularArc>(v6, v3, origin, rb); CircularArc &c3 = sketch.new_element<CircularArc>(v6, v3, origin, rb);
auto mvec = sketch.curves(); auto mvec = sketch.curves();
MirrorCopy &m0 = sketch.new_element<MirrorCopy>(mvec, &l1, true); auto m0 = sketch.new_element_SHARED_PTR<MirrorCopy>(mvec, &l1, true);
auto rvec = sketch.curves(); auto rvec = sketch.curves();
RotateCopy &rcopy = sketch.new_element<RotateCopy>(rvec, origin, 360.0 / Nt, 1, true); auto rcopy = sketch.new_element_SHARED_PTR<RotateCopy>(rvec, origin, 360.0 / Nt, 1, true);
sketch.solve(); sketch.solve();
......
Supports Markdown
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