Commit 000b41f0 by JasonPries

Change Sketch Variable and Vertex vectors from raw pointers to shared pointers

parent 305f7d04
 ... ... @@ -70,14 +70,15 @@ ... ...
 ... ... @@ -10,9 +10,11 @@ public: Point(double x, double y) : X{x}, Y{y} {}; Point(Vertex const &v) : X{v.x()}, Y{v.y()} {}; //Point(Vertex const &v) : X{v.x()}, Y{v.y()} {}; Point(Vertex const *v) : X{v->x()}, Y{v->y()} {}; Point(std::shared_ptrv) : X{v->x()}, Y{v->y()} {}; Point(sPoint const pp) : X{pp.x()}, Y{pp.y()} {}; //double W; // Nurbs weight? double X; ... ...
 ... ... @@ -94,10 +94,10 @@ double CircularArc::arc_angle() const { return (a1 - a0); } Vertex CircularArc::point(double s) const { sPoint CircularArc::point(double s) const { double a = s_to_a(s); return Vertex{center()->x() + radius() * cos(a), center()->y() + radius() * sin(a)}; return sPoint{center()->x() + radius() * cos(a), center()->y() + radius() * sin(a)}; } Vertex CircularArc::tangent(double s, bool orientation) const { ... ... @@ -167,7 +167,7 @@ std::pair CircularArc::supremum() const { double s = a_to_s(center()->atan()); if (s > 0.0 && s < 1.0) { Vertex v = point(s); sPoint v = point(s); xx = v.x(); yy = v.y(); val = sqrt(xx * xx + yy * yy); ... ... @@ -216,7 +216,7 @@ bool CircularArc::is_identical(const Curve *c) const { } } bool CircularArc::is_identical(const Curve *c, const Vertex *origin, const double angle) const { bool CircularArc::is_identical(const Curve *c, std::shared_ptr origin, const double angle) const { const CircularArc *cc = dynamic_cast(c); if (cc == nullptr) { ... ... @@ -302,7 +302,7 @@ bool CircularArc::on_segment(const double x, const double y) const { } } void CircularArc::replace_verticies(std::vector oldv, std::vector newv) { void CircularArc::replace_verticies(std::vector> oldv, std::vector> newv) { auto i = std::find(oldv.begin(), oldv.end(), Start); if (i != oldv.end()) { size_t j = i - oldv.begin(); ... ...
 ... ... @@ -4,11 +4,11 @@ template class Coincident : public Constraint { public: Vertex *Point; std::shared_ptr Point; T *Element; // Constructors Coincident(Vertex &p, T &e) : Point(&p), Element(&e) {}; Coincident(std::shared_ptr p, T &e) : Point(p), Element(&e) {}; // Public Member Functions size_t set_equation_index(size_t i) override { ... ...
 ... ... @@ -7,10 +7,10 @@ Contour::Contour(const std::vector &c) { Curves = std::vector(); Curves.reserve(c.size()); std::vector start; std::vector> start; start.reserve(c.size()); std::vector end; std::vector> end; end.reserve(c.size()); for (size_t i = 0; i < c.size(); i++) { ... ... @@ -73,8 +73,8 @@ bool Contour::initialize(const std::vector &c, const std::vector< Orientation.push_back(dir[i]); size_t j = (i + 1) % c.size(); const Vertex *vi = (dir[i] ? c[i]->end() : c[i]->start()); const Vertex *vj = (dir[j] ? c[j]->start() : c[j]->end()); std::shared_ptr vi = (dir[i] ? c[i]->end() : c[i]->start()); std::shared_ptr vj = (dir[j] ? c[j]->start() : c[j]->end()); if (vi != vj) { return false; } ... ... @@ -119,8 +119,8 @@ double Contour::area() const { double area{0.0}; for (size_t i = 0; i != Curves.size(); ++i) { const Vertex *v0 = Curves[i]->start(); const Vertex *v1 = Curves[i]->end(); std::shared_ptr v0 = Curves[i]->start(); std::shared_ptr v1 = Curves[i]->end(); const double da = Curves[i]->area() + v0->x() * v1->y() - v0->y() * v1->x(); if (Orientation[i]) { ... ...
 ... ... @@ -13,7 +13,7 @@ public: Contour(const std::vector &c, const std::vector &dir); //Public Member Functions const Vertex *vertex(size_t i) const { return (Orientation[i] ? Curves[i]->start() : Curves[i]->end()); }; std::shared_ptr vertex(size_t i) const { return (Orientation[i] ? Curves[i]->start() : Curves[i]->end()); }; const Curve *curve(size_t i) const { return Curves[i]; }; ... ...
 #include "Sketch.hpp" Curve *Curve::split(Vertex *vnew, double s) { Curve *cnew = clone(); *(vnew) = point(s); End = vnew; cnew->Start = vnew; return cnew; } bool Curve::on_segment(const Vertex *v) const { bool Curve::on_segment(std::shared_ptr v) const { return on_segment(v->x(), v->y()); } bool Curve::on_segment(const Vertex *v, const Vertex *origin, const double angle) const { bool Curve::on_segment(std::shared_ptr v, std::shared_ptr origin, const double angle) const { double x, y; std::tie(x, y) = v->rotate(origin, angle); return on_segment(x, y); } bool Curve::on_manifold(const Vertex *v) const { bool Curve::on_manifold(std::shared_ptr v) const { return on_manifold(v->x(), v->y()); } bool Curve::on_manifold(const Vertex *v, const Vertex *origin, const double angle) const { bool Curve::on_manifold(std::shared_ptr v, std::shared_ptr origin, const double angle) const { double x, y; std::tie(x, y) = v->rotate(origin, angle); ... ...
 ... ... @@ -10,23 +10,23 @@ public: // Constructors Curve() : Start(nullptr), End(nullptr) {}; Curve(Vertex &v0, Vertex &v1, bool fc = false) : Start(&v0), End(&v1), ForConstruction(fc) {}; Curve(std::shared_ptr v0, std::shared_ptrv1, bool fc = false) : Start(v0), End(v1), ForConstruction(fc) {}; Curve(Vertex *v0, Vertex *v1, bool fc = false) : Start(v0), End(v1), ForConstruction(fc) {}; //Curve(Vertex *v0, Vertex *v1, bool fc = false) : Start(v0), End(v1), ForConstruction(fc) {}; // Properties bool ForConstruction = false; // Accessors const Vertex *start() const { return Start; }; std::shared_ptr start() const { return Start; }; const Vertex *end() const { return End; }; std::shared_ptr end() const { return End; }; virtual void get_verticies(std::list &v) const = 0; virtual void get_verticies(std::list> &v) const = 0; // Calculation // #TODO: Add const to double_t and bool arguments where appropriate virtual Vertex point(double s) const = 0; virtual sPoint point(double s) const = 0; virtual Vertex tangent(double s, bool orientation) const = 0; ... ... @@ -39,15 +39,15 @@ public: virtual std::pair supremum() const = 0; // maximum length of vector between origin and point on curve // Curve-Vertex Comparison virtual bool on_manifold(const Vertex *v) const final; // true if vertex is on manifold defined by curve virtual bool on_manifold(const Vertex *v, const Vertex *origin, const double angle) const final; virtual bool on_manifold(std::shared_ptr v) const final; // true if vertex is on manifold defined by curve virtual bool on_manifold(std::shared_ptr v, std::shared_ptr origin, const double angle) const final; virtual bool on_segment(const Vertex *v) const final; // true if vertex is on curve segment virtual bool on_segment(const Vertex *v, const Vertex *origin, const double angle) const final; virtual bool on_segment(std::shared_ptr v) const final; // true if vertex is on curve segment virtual bool on_segment(std::shared_ptr v, std::shared_ptr origin, const double angle) const final; // Curve-Curve Comparison virtual bool is_identical(const Curve *c) const = 0; // true if (input curve) XOR (object curve) is a set with measure < tol virtual bool is_identical(const Curve *c, const Vertex *origin, const double angle) const = 0; virtual bool is_identical(const Curve *c, std::shared_ptr origin, const double angle) const = 0; // #TODO: virtual bool is_overlapping(const Curve* c) const = 0; // true if (input curve) AND (object curve) is a set with measure > tol // #TODO: virtual bool is_overlapping(const Curve* c, const Vertex* origin, const double_t angle) const = 0; ... ... @@ -56,16 +56,15 @@ public: // #TODO: virtual bool is_coincident(const Curve* c, const Vertex* origin, const double_t angle) const = 0; // Modification Curve *split(Vertex *v, double s); void reverse() { std::swap(Start, End); }; virtual Curve *clone() const = 0; virtual void replace_verticies(std::vector oldv, std::vector newv) = 0; virtual void replace_verticies(std::vector> oldv, std::vector> newv) = 0; protected: Vertex *Start, *End; std::shared_ptr Start; std::shared_ptr End; virtual bool on_manifold(const double x, const double y) const = 0; ... ...
 ... ... @@ -204,17 +204,17 @@ template class Distance; template<> size_t Distance::set_equation_index(size_t i) { size_t Distance>::set_equation_index(size_t i) { EquationIndex = i; return 1; } template<> void Distance::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) { const double x0 = Element0->x(); const double y0 = Element0->y(); const double x1 = Element1->x(); const double y1 = Element1->y(); void Distance>::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) { const double x0 = (*Element0)->x(); const double y0 = (*Element0)->y(); const double x1 = (*Element1)->x(); const double y1 = (*Element1)->y(); double dx = x1 - x0; double dy = y1 - y0; ... ... @@ -224,11 +224,11 @@ void Distance::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) { r(EquationIndex) = dr - Dim; J(EquationIndex, Element0->X->get_index()) -= dx; J(EquationIndex, Element0->Y->get_index()) -= dy; J(EquationIndex, Element1->X->get_index()) += dx; J(EquationIndex, Element1->Y->get_index()) += dy; J(EquationIndex, (*Element0)->X->get_index()) -= dx; J(EquationIndex, (*Element0)->Y->get_index()) -= dy; J(EquationIndex, (*Element1)->X->get_index()) += dx; J(EquationIndex, (*Element1)->Y->get_index()) += dy; } template class Distance; \ No newline at end of file class Distance>; \ No newline at end of file
 #include "Sketch.hpp" Fixation::Fixation(Vertex &v) { Point = &v; Dim = new Vertex(v); Fixation::Fixation(std::shared_ptr v) { Point = v; Dim = sPoint(v->x(), v->y()); } void Fixation::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) { r(EquationIndex) = Point->x() - Dim->x(); r(EquationIndex) = Point->x() - Dim.X; J(EquationIndex, Point->X->get_index()) += 1.0; r(EquationIndex + 1) = Point->y() - Dim->y(); r(EquationIndex + 1) = Point->y() - Dim.Y; J(EquationIndex + 1, Point->Y->get_index()) += 1.0; } \ No newline at end of file
 ... ... @@ -3,11 +3,11 @@ class Fixation : public Constraint { public: Vertex *Point; Vertex *Dim; std::shared_ptr Point; sPoint Dim; // Constructors Fixation(Vertex &v); Fixation(std::shared_ptr v); // Public Member Functions size_t set_equation_index(size_t i) override { ... ...
 #include "Sketch.hpp" Vertex LineSegment::point(double s) const { sPoint LineSegment::point(double s) const { const double x0 = start()->x(); const double y0 = start()->y(); const double x1 = end()->x(); const double y1 = end()->y(); return Vertex{x0 * (1.0 - s) + x1 * s, y0 * (1.0 - s) + y1 * s}; return sPoint{x0 * (1.0 - s) + x1 * s, y0 * (1.0 - s) + y1 * s}; } Vertex LineSegment::tangent(double s, bool orientation) const { ... ... @@ -115,7 +115,7 @@ bool LineSegment::is_identical(const Curve *c) const { } } bool LineSegment::is_identical(const Curve *c, const Vertex *origin, const double angle) const { bool LineSegment::is_identical(const Curve *c, std::shared_ptr origin, const double angle) const { const LineSegment *l = dynamic_cast(c); if (l == nullptr) { ... ... @@ -162,7 +162,7 @@ bool LineSegment::is_coincident(const Curve *c) const { double LineSegment::length() const { return hypot(end()->x() - start()->x(), end()->y() - start()->y()); }; void LineSegment::replace_verticies(std::vector oldv, std::vector newv) { void LineSegment::replace_verticies(std::vector> oldv, std::vector> newv) { auto i = std::find(oldv.begin(), oldv.end(), Start); if (i != oldv.end()) { size_t j = i - oldv.begin(); ... ...
 ... ... @@ -24,10 +24,10 @@ public: LineSegment(const LineSegment *l) : Curve(l->Start, l->End, l->ForConstruction) {}; LineSegment(Vertex &v0, Vertex &v1, bool fc = false) : Curve(v0, v1, fc) {}; LineSegment(std::shared_ptr v0, std::shared_ptr v1, bool fc = false) : Curve(v0, v1, fc) {}; // Virtual Function Implementation void get_verticies(std::list &v) const override { void get_verticies(std::list> &v) const override { v.push_back(Start); v.push_back(End); }; ... ... @@ -42,7 +42,7 @@ public: void update(Eigen::MatrixXd &J, Eigen::VectorXd &r) override {}; // Calculation Vertex point(double s) const override; sPoint point(double s) const override; Vertex tangent(double s, bool orientation) const override; ... ... @@ -64,14 +64,14 @@ public: // Curve-Curve Comparison bool is_identical(const Curve *c) const override; bool is_identical(const Curve *c, const Vertex *origin, const double angle) const override; bool is_identical(const Curve *c, std::shared_ptr origin, const double angle) const override; bool is_coincident(const Curve *c) const override; // Modification Curve *clone() const override { return new LineSegment(this); }; void replace_verticies(std::vector oldv, std::vector newv) override; void replace_verticies(std::vector> oldv, std::vector> newv) override; protected: bool on_manifold(const double x, const double y) const override; ... ...
 ... ... @@ -11,7 +11,7 @@ MirrorCopy::MirrorCopy(std::vector &input, LineSegment *l, bool r // Clone input curves and create a list of unique input verticies Curves.reserve(Input.size()); std::list input_vlist; std::list> input_vlist; for (auto c : Input) { if (l->is_coincident(c)) { const_cast(c)->ForConstruction = RemoveInternalBoundaries; // TODO: const_cast is ugly ... ... @@ -48,7 +48,9 @@ MirrorCopy::MirrorCopy(std::vector &input, LineSegment *l, bool r px = x - 2.0 * px; py = y - 2.0 * py; Verticies.push_back(new Vertex(px, py)); //Verticies.push_back(new Vertex(px, py)); Verticies.push_back(std::make_shared(px, py)); ++v; } else { ... ... @@ -57,7 +59,7 @@ MirrorCopy::MirrorCopy(std::vector &input, LineSegment *l, bool r } // Replace verticies in mirror curves std::vector input_vvector{input_vlist.begin(), input_vlist.end()}; std::vector> input_vvector{input_vlist.begin(), input_vlist.end()}; for (auto c : Curves) { c->replace_verticies(input_vvector, Verticies); c->reverse(); ... ... @@ -66,6 +68,6 @@ MirrorCopy::MirrorCopy(std::vector &input, LineSegment *l, bool r // Constrain mirrored verticies to be symmetric about the SymmetryLine Constraints.reserve(Verticies.size()); for (size_t i = 0; i != Verticies.size(); ++i) { Constraints.push_back(new Symmetry(*input_vvector[i], *Verticies[i], *SymmetryLine)); Constraints.push_back(new Symmetry(input_vvector[i], Verticies[i], *SymmetryLine)); } } \ No newline at end of file
 ... ... @@ -2,7 +2,7 @@ void Pattern::register_elements(Sketch *s) { for (auto v : Verticies) { s->add_element(*v); s->add_element(v); } for (auto c : Curves) { ... ...
 ... ... @@ -20,7 +20,7 @@ protected: std::vector Input; bool RemoveInternalBoundaries; std::vector Verticies; std::vector> Verticies; std::vector Curves; std::vector Constraints; }; ... ...