Commit 8e5011bb authored by JasonPries's avatar JasonPries
Browse files

Change Sketch Constraint and Curve vectors from raw pointers to shared pointers

parent 1c94c79a
......@@ -542,7 +542,7 @@ void Mesh::create_boundary_polygon() {
Edges.reserve(Boundary->size());
Points.reserve(Boundary->size());
for (size_t i = 0; i != Boundary->size(); ++i) {
Curve const *cc = Boundary->curve(i); //clone() to prevent alteration of input Contour when Edge is split
std::shared_ptr<Curve> cc = Boundary->curve(i);
bool dir = Boundary->orientation(i);
Edge &e = new_edge(Points.size(), Constraints.size(), dir); // TODO: change to new_edge(Edge)
e.Twin = e.Self;
......@@ -629,7 +629,7 @@ void Mesh::insert_internal_boundaries() {
*/
// Find interior curves
std::vector<Curve const *> interior;
std::vector<std::shared_ptr<Curve>> interior;
for (auto c : Curves) {
bool on_exterior = false;
for (size_t i = 0; i != Boundary->size(); ++i) {
......@@ -691,7 +691,7 @@ void Mesh::insert_internal_boundaries() {
} else {
double s0 = dc.S0;
double s1 = dc.S1;
Curve const *cc = dc.ConstraintCurve;
std::shared_ptr<Curve> cc = dc.ConstraintCurve;
double sn = (s0 + s1) / 2.0;
Point const p = cc->point(sn);
......@@ -778,7 +778,7 @@ void Mesh::split_edge(size_t ei) {
DartConstraint &dc = Constraints[Edges[ei].Constraint];
double s0 = dc.S0;
double s1 = dc.S1;
Curve const *cc = dc.ConstraintCurve;
std::shared_ptr<Curve> cc = dc.ConstraintCurve;
double sn = (s0 + s1) / 2.0;
dc.S1 = sn;
......@@ -1069,7 +1069,7 @@ InsertPointResult Mesh::insert_midpoint(size_t ei) {
DartConstraint &dc = Constraints[Edges[ei].Constraint];
double s0 = dc.S0;
double s1 = dc.S1;
Curve const *cc = dc.ConstraintCurve;
std::shared_ptr<Curve> cc = dc.ConstraintCurve;
double sn = (s0 + s1) / 2.0;
dc.S1 = sn;
......
......@@ -21,11 +21,11 @@ class DartConstraint {
public:
DartConstraint() : S0(DBL_MAX), S1(DBL_MAX), ConstraintCurve(nullptr) {};
DartConstraint(double s0, double s1, Curve const *cc) : S0(s0), S1(s1), ConstraintCurve(cc) {};
DartConstraint(double s0, double s1, std::shared_ptr<Curve> cc) : S0(s0), S1(s1), ConstraintCurve(cc) {};
double S0;
double S1;
Curve const *ConstraintCurve;
std::shared_ptr<Curve> ConstraintCurve;
};
class Mesh {
......@@ -92,7 +92,7 @@ public:
DartConstraint const constraint(size_t ei) const { return Constraints[Edges[ei].Constraint]; };
Curve const *constraint_curve(size_t ei) const { return Constraints[Edges[ei].Constraint].ConstraintCurve; };
std::shared_ptr<Curve> constraint_curve(size_t ei) const { return Constraints[Edges[ei].Constraint].ConstraintCurve; };
Point circumcenter(size_t ei) const;
......@@ -129,7 +129,7 @@ public:
protected:
std::shared_ptr<Contour> Boundary;
std::vector<Curve const *> Curves;
std::vector<std::shared_ptr<Curve>> Curves;
std::vector<std::shared_ptr<Contour>> Contours;
std::vector<Point> Points;
......
......@@ -3,14 +3,13 @@
class Angle : public Constraint {
public:
LineSegment *Line0, *Line1;
std::shared_ptr<LineSegment> Line0;
std::shared_ptr<LineSegment> Line1;
double Dim;
// Constructors
Angle(LineSegment &l0, LineSegment &l1, double angle) : Line0(&l0), Line1(&l1), Dim(angle) {};
Angle(std::shared_ptr<LineSegment> l0, std::shared_ptr<LineSegment> l1, double angle) : Line0(l0), Line1(l1), Dim(angle) {};
// Public Member Functions
size_t set_equation_index(size_t i) override {
EquationIndex = i;
return 1;
......
......@@ -2,7 +2,7 @@
#define OERSTED_BRANCH_H
struct Branch {
const Curve *Path;
std::shared_ptr<Curve> Path;
bool Orientation;
double Angle;
};
......
......@@ -199,10 +199,12 @@ bool CircularArc::on_manifold(const double x, const double y) const {
}
}
bool CircularArc::is_identical(const Curve *c) const {
const CircularArc *cc = dynamic_cast<const CircularArc *>(c);
bool CircularArc::is_identical(std::shared_ptr<Curve> c) const {
//const CircularArc *cc = dynamic_cast<const CircularArc *>(c);
if (cc == nullptr) {
auto cc = std::dynamic_pointer_cast<CircularArc>(c);
if (cc.get() == nullptr) {
return false;
} else {
return is_identical(
......@@ -216,10 +218,12 @@ bool CircularArc::is_identical(const Curve *c) const {
}
}
bool CircularArc::is_identical(const Curve *c, std::shared_ptr<Vertex> origin, const double angle) const {
const CircularArc *cc = dynamic_cast<const CircularArc *>(c);
bool CircularArc::is_identical(std::shared_ptr<Curve> c, std::shared_ptr<Vertex> origin, const double angle) const {
//const CircularArc *cc = dynamic_cast<const CircularArc *>(c);
auto cc = std::dynamic_pointer_cast<CircularArc>(c);
if (cc == nullptr) {
if (cc.get() == nullptr) {
return false;
} else {
double xc, yc, xs, ys, xe, ye;
......@@ -245,10 +249,12 @@ bool CircularArc::is_identical(const double r, const double xc, const double yc,
&& abs(end()->y() - ye) < tol;
}
bool CircularArc::is_coincident(const Curve *c) const {
const CircularArc *cc = dynamic_cast<const CircularArc *>(c);
bool CircularArc::is_coincident(std::shared_ptr<Curve> c) const {
//const CircularArc *cc = dynamic_cast<const CircularArc *>(c);
auto cc = std::dynamic_pointer_cast<CircularArc>(c);
if (cc == nullptr) {
if (cc.get() == nullptr) {
return false;
} else {
// #TODO: Extract input curve center, put the rest of the method in subroutine
......
......@@ -13,10 +13,9 @@ public:
friend class Tangency;
// Constructors
CircularArc() : Curve(), Radius(std::make_shared<Variable>(0.0)) {};
CircularArc(const CircularArc *c) : Curve(c->Start, c->End, c->ForConstruction), Center(c->Center), Radius(c->Radius) {};
CircularArc(CircularArc const *c) : Curve(c->Start, c->End, c->ForConstruction), Center(c->Center), Radius(c->Radius) {};
CircularArc(std::shared_ptr<Vertex> v0, std::shared_ptr<Vertex> v1, std::shared_ptr<Vertex> c, bool fc = false) : Curve(v0, v1, fc), Center(c) {};
......@@ -24,12 +23,10 @@ public:
CircularArc(std::shared_ptr<Vertex> v0, std::shared_ptr<Vertex> v1, std::shared_ptr<Vertex> c, std::shared_ptr<Variable> r, Sketch &s, bool fc = false) : Curve(v0, v1, fc), Center(c), Radius(r) {};
// Accessors
std::shared_ptr<Vertex> center() const { return Center; };
double radius() const { return Radius->value(); };
// Virtual Function Implementation
void get_verticies(std::list<std::shared_ptr<Vertex>> &v) const override {
v.push_back(Start);
v.push_back(End);
......@@ -45,7 +42,6 @@ public:
void update(Eigen::MatrixXd &J, Eigen::VectorXd &r) override;
// Calculation
sPoint point(double s) const override;
Vertex tangent(double s, bool orientation) const override;
......@@ -60,20 +56,17 @@ public:
std::pair<double, double> supremum() const override;
// Curve-Vertex Comparison
using Curve::on_manifold;
using Curve::on_segment;
// Curve-Curve Comparison
bool is_identical(const Curve *c) const override;
bool is_identical(std::shared_ptr<Curve> c) const override;
bool is_identical(const Curve *c, std::shared_ptr<Vertex> origin, const double angle) const override;
bool is_identical(std::shared_ptr<Curve> c, std::shared_ptr<Vertex> origin, const double angle) const override;
bool is_coincident(const Curve *c) const override;
bool is_coincident(std::shared_ptr<Curve> c) const override;
// Modification
Curve *clone() const override { return new CircularArc(this); };
std::shared_ptr<Curve> clone() const override { return std::make_shared<CircularArc>(this); };
void replace_verticies(std::vector<std::shared_ptr<Vertex>> oldv, std::vector<std::shared_ptr<Vertex>> newv) override;
......
......@@ -5,10 +5,10 @@ template<class T>
class Coincident : public Constraint {
public:
std::shared_ptr<Vertex> Point;
T *Element;
std::shared_ptr<T> Element;
// Constructors
Coincident(std::shared_ptr<Vertex> p, T &e) : Point(p), Element(&e) {};
Coincident(std::shared_ptr<Vertex> p, std::shared_ptr<T> e) : Point(p), Element(e) {};
// Public Member Functions
size_t set_equation_index(size_t i) override {
......
......@@ -8,7 +8,7 @@ Constellation::Constellation(const Sketch *s) {
}
bool Constellation::twin(std::list<Star>::iterator &s_out, std::list<Branch>::iterator &b_out) {
const Curve *c = b_out->Path; // #TODO: Local variable 'c' is only assigned but never accessed
std::shared_ptr<Curve> c = b_out->Path; // #TODO: Local variable 'c' is only assigned but never accessed
for (auto s = Stars.begin(); s != Stars.end(); ++s) {
if (s != s_out) {
......@@ -44,7 +44,7 @@ void Constellation::supremum(std::list<Star>::iterator &s_out, std::list<Branch>
}
}
void Constellation::pop(const Curve *c) {
void Constellation::pop(std::shared_ptr<Curve> c) {
bool iterate = true;
while (iterate) {
......@@ -76,7 +76,7 @@ void Constellation::pop(const Curve *c) {
}
bool Constellation::boundary(std::shared_ptr<Contour> c) {
std::vector<const Curve *> curves;
std::vector<std::shared_ptr<Curve>> curves;
std::vector<bool> orientation;
// Base of induction
......@@ -122,7 +122,7 @@ bool Constellation::boundary(std::shared_ptr<Contour> c) {
}
bool Constellation::contours(std::vector<std::shared_ptr<Contour>> &contours) {
std::vector<const Curve *> contour_curves;
std::vector<std::shared_ptr<Curve>> contour_curves;
std::vector<bool> orientation;
while (size() > 0) {
......@@ -137,7 +137,7 @@ bool Constellation::contours(std::vector<std::shared_ptr<Contour>> &contours) {
return true;
}
bool Constellation::find_closed_contour(std::vector<const Curve *> &curves, std::vector<bool> &orientation) {
bool Constellation::find_closed_contour(std::vector<std::shared_ptr<Curve>> &curves, std::vector<bool> &orientation) {
curves.resize(0);
orientation.resize(0);
......
......@@ -19,13 +19,13 @@ public:
private:
std::list<Star> Stars;
void pop(const Curve *c = nullptr);
void pop(std::shared_ptr<Curve> c = nullptr);
bool twin(std::list<Star>::iterator &s_out, std::list<Branch>::iterator &b_out);
void supremum(std::list<Star>::iterator &s_out, std::list<Branch>::iterator &b_out);
bool find_closed_contour(std::vector<const Curve *> &curves, std::vector<bool> &orientation);
bool find_closed_contour(std::vector<std::shared_ptr<Curve>> &curves, std::vector<bool> &orientation);
};
#endif //OERSTED_CONSTELLATION_H
\ No newline at end of file
#include "Sketch.hpp"
Contour::Contour(const std::vector<const Curve *> &c) {
Contour::Contour(std::vector<std::shared_ptr<Curve>> const &c) {
// #TODO: Check for intersecting curves
// #TODO: Check for ccw orientation of entire contour
Curves = std::vector<const Curve *>();
Curves = std::vector<std::shared_ptr<Curve>>();
Curves.reserve(c.size());
std::vector<std::shared_ptr<Vertex>> start;
......@@ -56,7 +56,7 @@ Contour::Contour(const std::vector<const Curve *> &c) {
}
}
Contour::Contour(const std::vector<const Curve *> &c, const std::vector<bool> &dir) {
Contour::Contour(std::vector<std::shared_ptr<Curve>> const &c, std::vector<bool> const &dir) {
bool success = initialize(c, dir);
if (!success) {
......@@ -64,7 +64,7 @@ Contour::Contour(const std::vector<const Curve *> &c, const std::vector<bool> &d
}
}
bool Contour::initialize(const std::vector<const Curve *> &c, const std::vector<bool> &dir) {
bool Contour::initialize(std::vector<std::shared_ptr<Curve>> const &c, std::vector<bool> const &dir) {
Curves.resize(0);
Orientation.resize(0);
......
......@@ -6,22 +6,22 @@
class Contour {
public:
// Constructors
Contour() : Curves(std::vector<const Curve *>()), Orientation(std::vector<bool>()) {};
Contour() : Curves(std::vector<std::shared_ptr<Curve>>()), Orientation(std::vector<bool>()) {};
Contour(const std::vector<const Curve *> &c);
Contour(std::vector<std::shared_ptr<Curve>> const &c);
Contour(const std::vector<const Curve *> &c, const std::vector<bool> &dir);
Contour(std::vector<std::shared_ptr<Curve>> const &c, std::vector<bool> const &dir);
//Public Member Functions
std::shared_ptr<Vertex> vertex(size_t i) const { return (Orientation[i] ? Curves[i]->start() : Curves[i]->end()); };
const Curve *curve(size_t i) const { return Curves[i]; };
std::shared_ptr<Curve> curve(size_t i) const { return Curves[i]; };
const bool orientation(size_t i) const { return Orientation[i]; };
const size_t size() const { return Curves.size(); };
bool initialize(const std::vector<const Curve *> &c, const std::vector<bool> &dir);
bool initialize(std::vector<std::shared_ptr<Curve>> const &c, std::vector<bool> const &dir);
auto begin() { return Curves.begin(); };
......@@ -36,7 +36,7 @@ public:
double area() const;
private:
std::vector<const Curve *> Curves;
std::vector<std::shared_ptr<Curve>> Curves;
std::vector<bool> Orientation;
};
......
......@@ -46,19 +46,19 @@ public:
virtual bool on_segment(std::shared_ptr<Vertex> v, std::shared_ptr<Vertex> 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, std::shared_ptr<Vertex> origin, const double angle) const = 0;
virtual bool is_identical(std::shared_ptr<Curve> c) const = 0; // true if (input curve) XOR (object curve) is a set with measure < tol
virtual bool is_identical(std::shared_ptr<Curve> c, std::shared_ptr<Vertex> 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;
virtual bool is_coincident(const Curve *c) const = 0; // true if (input curve) AND (object curve + parametric extension) is a set with measure > tol
virtual bool is_coincident(std::shared_ptr<Curve> c) const = 0; // true if (input curve) AND (object curve + parametric extension) is a set with measure > tol
// #TODO: virtual bool is_coincident(const Curve* c, const Vertex* origin, const double_t angle) const = 0;
// Modification
void reverse() { std::swap(Start, End); };
virtual Curve *clone() const = 0;
virtual std::shared_ptr<Curve> clone() const = 0;
virtual void replace_verticies(std::vector<std::shared_ptr<Vertex>> oldv, std::vector<std::shared_ptr<Vertex>> newv) = 0;
......
......@@ -204,17 +204,17 @@ template
class Distance<LineSegment>;
template<>
size_t Distance<std::shared_ptr<Vertex>>::set_equation_index(size_t i) {
size_t Distance<Vertex>::set_equation_index(size_t i) {
EquationIndex = i;
return 1;
}
template<>
void Distance<std::shared_ptr<Vertex>>::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<Vertex>::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<std::shared_ptr<Vertex>>::update(Eigen::MatrixXd &J, Eigen::Vector
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<std::shared_ptr<Vertex>>;
\ No newline at end of file
class Distance<Vertex>;
\ No newline at end of file
......@@ -4,15 +4,13 @@
template<class T>
class Distance : public Constraint {
public:
T *Element0;
T *Element1;
std::shared_ptr<T> Element0;
std::shared_ptr<T> Element1;
double Dim;
// Constructors
Distance(T &e0, T &e1, double d) : Element0(&e0), Element1(&e1), Dim(d) {};
Distance(std::shared_ptr<T> e0, std::shared_ptr<T> e1, double d) : Element0(e0), Element1(e1), Dim(d) {};
// Public Member Functions
size_t set_equation_index(size_t i) override;
void update(Eigen::MatrixXd &J, Eigen::VectorXd &r) override;
......
......@@ -6,10 +6,8 @@ public:
std::shared_ptr<Vertex> Point;
sPoint Dim;
// Constructors
Fixation(std::shared_ptr<Vertex> v);
// Public Member Functions
size_t set_equation_index(size_t i) override {
EquationIndex = i;
return 2;
......
......@@ -3,12 +3,10 @@
class Horizontal : public Constraint {
public:
LineSegment *Line;
std::shared_ptr<LineSegment> Line;
// Constructors
Horizontal(LineSegment &l) : Line(&l) {};
Horizontal(std::shared_ptr<LineSegment> l) : Line(l) {};
// Public Member Functions
size_t set_equation_index(size_t i) override {
EquationIndex = i;
return 1;
......
#ifndef OERSTED_LENGTH_H
#define OERSTED_LENGTH_H
class Length : public Constraint {
class Length : public Constraint { // TODO: Public member variables?
public:
LineSegment *Line;
std::shared_ptr<LineSegment> Line;
double Dim;
// Constructors
Length(LineSegment &c, double length) : Line(&c), Dim(length) {};
Length(std::shared_ptr<LineSegment> c, double length) : Line(c), Dim(length) {};
// Public Member Functions
size_t set_equation_index(size_t i) override {
EquationIndex = i;
return 1;
......
......@@ -105,20 +105,20 @@ bool LineSegment::on_segment(const double x, const double y) const {
}
}
bool LineSegment::is_identical(const Curve *c) const {
const LineSegment *l = dynamic_cast<const LineSegment *>(c);
bool LineSegment::is_identical(std::shared_ptr<Curve> c) const {
auto l = std::dynamic_pointer_cast<LineSegment>(c);
if (l == nullptr) {
if (l.get() == nullptr) {
return false;
} else {
return is_identical(l->start()->x(), l->start()->y(), l->end()->x(), l->end()->y());
}
}
bool LineSegment::is_identical(const Curve *c, std::shared_ptr<Vertex> origin, const double angle) const {
const LineSegment *l = dynamic_cast<const LineSegment *>(c);
bool LineSegment::is_identical(std::shared_ptr<Curve> c, std::shared_ptr<Vertex> origin, const double angle) const {
auto l = std::dynamic_pointer_cast<LineSegment>(c);
if (l == nullptr) {
if (l.get() == nullptr) {
return false;
} else {
double xs, ys, xe, ye;
......@@ -137,17 +137,16 @@ bool LineSegment::is_identical(const double x0, const double y0, const double x1
double xe = end()->x();
double ye = end()->y();
double tol =
FLT_EPSILON * std::fmax(abs(xs - xe), abs(ys - ye)); // #TODO: L1 norm is more efficient tolerance strategy
double tol = FLT_EPSILON * std::fmax(abs(xs - xe), abs(ys - ye)); // #TODO: L1 norm is more efficient tolerance strategy
return (abs(xs - x0) < tol && abs(ys - y0) < tol && abs(xe - x1) < tol && abs(ye - y1) < tol)
|| (abs(xs - x1) < tol && abs(ys - y1) < tol && abs(xe - x0) < tol && abs(ye - y0) < tol);
}
bool LineSegment::is_coincident(const Curve *c) const {
const LineSegment *l = dynamic_cast<const LineSegment *>(c);
bool LineSegment::is_coincident(std::shared_ptr<Curve> c) const {
auto l = std::dynamic_pointer_cast<LineSegment>(c);
if (l == nullptr) {
if (l.get() == nullptr) {
return false;
} else {
if (on_manifold(c->start()) && on_manifold(c->end())) {
......
......@@ -62,14 +62,14 @@ public:
using Curve::on_segment;
// Curve-Curve Comparison
bool is_identical(const Curve *c) const override;
bool is_identical(std::shared_ptr<Curve> c) const override;
bool is_identical(const Curve *c, std::shared_ptr<Vertex> origin, const double angle) const override;
bool is_identical(std::shared_ptr<Curve> c, std::shared_ptr<Vertex> origin, const double angle) const override;
bool is_coincident(const Curve *c) const override;
bool is_coincident(std::shared_ptr<Curve> c) const override;
// Modification
Curve *clone() const override { return new LineSegment(this); };
std::shared_ptr<Curve> clone() const override { return std::make_shared<LineSegment>(this); };
void replace_verticies(std::vector<std::shared_ptr<Vertex>> oldv, std::vector<std::shared_ptr<Vertex>> newv) override;
......
#include "Sketch.hpp"
MirrorCopy::MirrorCopy(std::vector<const Curve *> &input, LineSegment *l, bool remove_internal) {
MirrorCopy::MirrorCopy(std::vector<std::shared_ptr<Curve>> &input, std::shared_ptr<LineSegment> l, bool remove_internal) {
// Creates mirror copies of the input curves about a line
// Assign Properties
......@@ -14,7 +14,8 @@ MirrorCopy::MirrorCopy(std::vector<const Curve *> &input, LineSegment *l, bool r
std::list<std::shared_ptr<Vertex>> input_vlist;
for (auto c : Input) {
if (l->is_coincident(c)) {
const_cast<Curve *>(c)->ForConstruction = RemoveInternalBoundaries; // TODO: const_cast is ugly
//const_cast<Curve *>(c)->ForConstruction = RemoveInternalBoundaries; // TODO: const_cast is ugly
c->ForConstruction = RemoveInternalBoundaries;
} else {
Curves.push_back(c->clone());
c->get_verticies(input_vlist);
......@@ -68,6 +69,6 @@ MirrorCopy::MirrorCopy(std::vector<const Curve *> &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(std::make_shared<Symmetry>(input_vvector[i], Verticies[i], SymmetryLine));