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

Cleanup of Sketch and reorganization of dependencies

parent 2312e40b
......@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.2)
project(Oersted)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 --coverage")
find_package(Boost REQUIRED COMPONENTS system filesystem)
......
#ifndef OERSTED_MESH_HPP
#define OERSTED_MESH_HPP
#include <boost/filesystem.hpp>
#include "../src/Mesh.h"
#include "../src/Edge.h"
#include "../src/Point.h"
......
......@@ -5,6 +5,10 @@ set(SOURCE_FILES
./src/Sketch.h ./src/Sketch.cpp
./src/Variable.h ./src/Variable.cpp
./src/SketchElement.h ./src/SketchElement.cpp
./src/Vertex.h ./src/Vertex.cpp
./src/Curve.h ./src/Curve.cpp
......@@ -13,26 +17,26 @@ set(SOURCE_FILES
./src/Constraint.h ./src/Constraint.cpp
./src/Angle.h ./src/Angle.cpp
./src/Coincident.cpp ./src/Coincident.h
./src/Distance.cpp ./src/Distance.h
./src/Fixation.cpp ./src/Fixation.h
./src/Horizontal.cpp ./src/Horizontal.h
./src/Length.cpp ./src/Length.h
./src/Radius.cpp ./src/Radius.h
./src/Rotation.cpp ./src/Rotation.h
./src/Symmetry.cpp ./src/Symmetry.h
./src/Tangency.cpp ./src/Tangency.h
./src/Vertical.cpp ./src/Vertical.h
./src/Coincident.h ./src/Coincident.cpp
./src/Distance.h ./src/Distance.cpp
./src/Fixation.h ./src/Fixation.cpp
./src/Horizontal.h ./src/Horizontal.cpp
./src/Length.h ./src/Length.cpp
./src/Radius.h ./src/Radius.cpp
./src/Rotation.h ./src/Rotation.cpp
./src/Symmetry.h ./src/Symmetry.cpp
./src/Tangency.h ./src/Tangency.cpp
./src/Vertical.h ./src/Vertical.cpp
./src/Pattern.h ./src/Pattern.cpp
./src/MirrorCopy.cpp ./src/MirrorCopy.h
./src/RotateCopy.cpp ./src/RotateCopy.h
./src/MirrorCopy.h ./src/MirrorCopy.cpp
./src/RotateCopy.h ./src/RotateCopy.cpp
./src/Branch.h ./src/Branch.cpp
./src/Star.h ./src/Star.cpp
./src/Constellation.h ./src/Constellation.cpp
./src/Contour.h ./src/Contour.cpp)
./src/Contour.h ./src/Contour.cpp src/sPoint.cpp src/sPoint.h)
add_library(sketch STATIC ${SOURCE_FILES})
......
......@@ -3,16 +3,38 @@
#include "../src/Sketch.h"
#include "../src/Variable.h"
#include "../src/SketchElement.h"
#include "../src/Vertex.h"
#include "../src/Curve.h"
#include "../src/LineSegment.h"
#include "../src/CircularArc.h"
#include "../src/Constraint.h"
#include "../src/Angle.h"
#include "../src/Coincident.h"
#include "../src/Distance.h"
#include "../src/Constraint.h"
#include "../src/Fixation.h"
#include "../src/Horizontal.h"
#include "../src/Length.h"
#include "../src/Radius.h"
#include "../src/Rotation.h"
#include "../src/Symmetry.h"
#include "../src/Tangency.h"
#include "../src/Vertical.h"
#include "../src/Pattern.h"
#include "../src/MirrorCopy.h"
#include "../src/RotateCopy.h"
#include "../src/Branch.h"
#include "../src/Star.h"
#include "../src/Constellation.h"
#include "../src/Contour.h"
......
#include "Sketch.hpp"
#include "Angle.h"
#include "LineSegment.h"
void Angle::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) {
/*
......@@ -9,15 +10,15 @@ void Angle::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) {
parameters is zero when the cosine (resp. sine) is equal to one.
*/
const double x00 = Line0->Start->x();
const double x01 = Line0->End->x();
const double x10 = Line1->Start->x();
const double x11 = Line1->End->x();
const double x00 = Line0->start()->x();
const double x01 = Line0->end()->x();
const double x10 = Line1->start()->x();
const double x11 = Line1->end()->x();
const double y00 = Line0->Start->y();
const double y01 = Line0->End->y();
const double y10 = Line1->Start->y();
const double y11 = Line1->End->y();
const double y00 = Line0->start()->y();
const double y01 = Line0->end()->y();
const double y10 = Line1->start()->y();
const double y11 = Line1->end()->y();
double vx0 = x01 - x00;
double vy0 = y01 - y00;
......@@ -42,38 +43,38 @@ void Angle::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) {
r(EquationIndex) = scale * (dot - cos(M_PI * Dim / 180.0));
f = scale * (vx1 - dot * vx0) / d0;
J(EquationIndex, Line0->Start->X->get_index()) -= f;
J(EquationIndex, Line0->End->X->get_index()) += f;
J(EquationIndex, Line0->start()->x_index()) -= f; //TODO: Change get_index() and set_index() to size_t index() and size_t index(size_t) (overloaded)
J(EquationIndex, Line0->end()->x_index()) += f;
f = scale * (vx0 - dot * vx1) / d1;
J(EquationIndex, Line1->Start->X->get_index()) -= f;
J(EquationIndex, Line1->End->X->get_index()) += f;
J(EquationIndex, Line1->start()->x_index()) -= f;
J(EquationIndex, Line1->end()->x_index()) += f;
f = scale * (vy1 - dot * vy0) / d0;
J(EquationIndex, Line0->Start->Y->get_index()) -= f;
J(EquationIndex, Line0->End->Y->get_index()) += f;
J(EquationIndex, Line0->start()->y_index()) -= f;
J(EquationIndex, Line0->end()->y_index()) += f;
f = scale * (vy0 - dot * vy1) / d1;
J(EquationIndex, Line1->Start->Y->get_index()) -= f;
J(EquationIndex, Line1->End->Y->get_index()) += f;
J(EquationIndex, Line1->start()->y_index()) -= f;
J(EquationIndex, Line1->end()->y_index()) += f;
} else {
// Solve (cross product) = sin(Dim)
r(EquationIndex) = scale * (cross - sin(M_PI * Dim / 180.0));
f = scale * (vy1 - cross * vx0) / d0;
J(EquationIndex, Line0->Start->X->get_index()) -= f;
J(EquationIndex, Line0->End->X->get_index()) += f;
J(EquationIndex, Line0->start()->x_index()) -= f;
J(EquationIndex, Line0->end()->x_index()) += f;
f = scale * (vy0 + cross * vx1) / d1;
J(EquationIndex, Line1->Start->X->get_index()) += f;
J(EquationIndex, Line1->End->X->get_index()) -= f;
J(EquationIndex, Line1->start()->x_index()) += f;
J(EquationIndex, Line1->end()->x_index()) -= f;
f = scale * (vx1 + cross * vy0) / d0;
J(EquationIndex, Line0->Start->Y->get_index()) += f;
J(EquationIndex, Line0->End->Y->get_index()) -= f;
J(EquationIndex, Line0->start()->y_index()) += f;
J(EquationIndex, Line0->end()->y_index()) -= f;
f = scale * (vx0 - cross * vy1) / d1;
J(EquationIndex, Line1->Start->Y->get_index()) -= f;
J(EquationIndex, Line1->End->Y->get_index()) += f;
J(EquationIndex, Line1->start()->y_index()) -= f;
J(EquationIndex, Line1->end()->y_index()) += f;
}
}
\ No newline at end of file
#ifndef OERSTED_ANGLE_H
#define OERSTED_ANGLE_H
class Angle : public Constraint {
public:
std::shared_ptr<LineSegment> Line0;
std::shared_ptr<LineSegment> Line1;
#include "Constraint.h"
double Dim;
class LineSegment;
class Angle : public Constraint {
public:
Angle(std::shared_ptr<LineSegment> l0, std::shared_ptr<LineSegment> l1, double angle) : Line0(l0), Line1(l1), Dim(angle) {};
size_t set_equation_index(size_t i) override {
......@@ -15,7 +14,17 @@ public:
return 1;
};
double dim() const { return Dim; };
void dim(double d) { Dim = d;};
void update(Eigen::MatrixXd &J, Eigen::VectorXd &r) override;
protected:
std::shared_ptr<LineSegment> Line0;
std::shared_ptr<LineSegment> Line1;
double Dim;
};
#endif //OERSTED_ANGLE_H
\ No newline at end of file
#include "Sketch.hpp"
\ No newline at end of file
#include "Branch.h"
#include "LineSegment.h"
\ No newline at end of file
#ifndef OERSTED_BRANCH_H
#define OERSTED_BRANCH_H
#include <memory>
class Curve;
struct Branch {
std::shared_ptr<Curve> Path;
bool Orientation;
double Angle;
bool Orientation;
};
#endif //OERSTED_BRANCH_H
#include "Sketch.hpp"
#include "CircularArc.h"
#include "sPoint.h"
void CircularArc::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) {
/*
......@@ -16,13 +17,13 @@ void CircularArc::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) {
r(EquationIndex) = radius() - rad;
J(EquationIndex, Radius->get_index()) += rad / radius();
J(EquationIndex, radius_index()) += rad / radius();
J(EquationIndex, Start->X->get_index()) -= dx / rad;
J(EquationIndex, Start->Y->get_index()) -= dy / rad;
J(EquationIndex, Start->x_index()) -= dx / rad;
J(EquationIndex, Start->y_index()) -= dy / rad;
J(EquationIndex, Center->X->get_index()) += dx / rad;
J(EquationIndex, Center->Y->get_index()) += dy / rad;
J(EquationIndex, Center->x_index()) += dx / rad;
J(EquationIndex, Center->y_index()) += dy / rad;
dx = End->x() - Center->x();
dy = End->y() - Center->y();
......@@ -30,13 +31,13 @@ void CircularArc::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) {
r(EquationIndex + 1) = radius() - rad;
J(EquationIndex + 1, Radius->get_index()) += rad / radius();
J(EquationIndex + 1, radius_index()) += rad / radius();
J(EquationIndex + 1, End->X->get_index()) -= dx / rad;
J(EquationIndex + 1, End->Y->get_index()) -= dy / rad;
J(EquationIndex + 1, End->x_index()) -= dx / rad;
J(EquationIndex + 1, End->y_index()) -= dy / rad;
J(EquationIndex + 1, Center->X->get_index()) += dx / rad;
J(EquationIndex + 1, Center->Y->get_index()) += dy / rad;
J(EquationIndex + 1, Center->x_index()) += dx / rad;
J(EquationIndex + 1, Center->y_index()) += dy / rad;
}
double CircularArc::s_to_a(double s) const {
......@@ -205,8 +206,7 @@ Direction CircularArc::is_identical(std::shared_ptr<Curve> const &c) const {
if (cc.get() == nullptr) {
return Direction::None;
} else {
return is_identical(cc->radius(), cc->center()->x(), cc->center()->y(), cc->start()->x(), cc->start()->y(),
cc->end()->x(), cc->end()->y());
return is_identical(cc->radius(), cc->center()->x(), cc->center()->y(), cc->start()->x(), cc->start()->y(), cc->end()->x(), cc->end()->y());
}
}
......@@ -226,8 +226,7 @@ Direction CircularArc::is_identical(std::shared_ptr<Curve> const &c, std::shared
}
}
Direction CircularArc::is_identical(const double r, const double xc, const double yc, const double xs, const double ys,
const double xe, const double ye) const {
Direction CircularArc::is_identical(const double r, const double xc, const double yc, const double xs, const double ys, const double xe, const double ye) const {
double tol = FLT_EPSILON * radius();
if (abs(radius() - r) < tol && abs(center()->x() - xc) < tol && abs(center()->y() - yc) < tol &&
......
......@@ -2,17 +2,10 @@
#define OERSTED_CIRCULARARC_H
#include "Curve.h"
#include "Sketch.h"
class CircularArc final : public Curve {
public:
friend class Coincident<CircularArc>;
friend class Distance<CircularArc>;
friend class Radius;
friend class Tangency;
CircularArc() : Curve(), Radius(std::make_shared<Variable>(0.0)) {};
CircularArc(CircularArc const *c) : Curve(c->Start, c->End, c->ForConstruction), Center(c->Center), Radius(c->Radius) {};
......@@ -23,10 +16,29 @@ 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) {};
std::shared_ptr<Vertex> center() const { return Center; };
size_t set_equation_index(size_t i) override {
EquationIndex = i;
return 2;
};
size_t radius_index() const { return Radius->get_index(); };
bool is_coincident(std::shared_ptr<Curve> const &c) const override;
double a(double s, bool orientation) const override;
double area() const override;
double da(double s, bool orientation) const override;
double length() const override { throw; };
double radius() const { return Radius->value(); };
using Curve::on_manifold;
using Curve::on_segment;
void get_verticies(std::list<std::shared_ptr<Vertex>> &v, Direction dir = Direction::Forward) const override {
if (dir == Direction::Forward) {
v.push_back(Start);
......@@ -39,42 +51,25 @@ public:
}
};
size_t set_equation_index(size_t i) override {
EquationIndex = i;
return 2;
};
void register_parameters(Sketch *s) override { s->add_parameter(Radius); };
void update(Eigen::MatrixXd &J, Eigen::VectorXd &r) override;
sPoint point(double s) const override;
Vertex tangent(double s, bool orientation) const override;
double length() const override { throw; };
double area() const override;
double a(double s, bool orientation) const override;
void replace_verticies(std::vector<std::shared_ptr<Vertex>> oldv, std::vector<std::shared_ptr<Vertex>> newv) override;
double da(double s, bool orientation) const override;
void update(Eigen::MatrixXd &J, Eigen::VectorXd &r) override;
std::pair<double, double> supremum() const override;
using Curve::on_manifold;
std::shared_ptr<Curve> clone() const override { return std::make_shared<CircularArc>(this); };
using Curve::on_segment;
std::shared_ptr<Vertex> center() const { return Center; };
Direction is_identical(std::shared_ptr<Curve> const &c) const override;
Direction is_identical(std::shared_ptr<Curve> const &c, std::shared_ptr<Vertex> const &origin, double const angle) const override;
bool is_coincident(std::shared_ptr<Curve> const &c) const override;
std::shared_ptr<Curve> clone() const override { return std::make_shared<CircularArc>(this); };
sPoint point(double s) const override;
void replace_verticies(std::vector<std::shared_ptr<Vertex>> oldv, std::vector<std::shared_ptr<Vertex>> newv) override;
Vertex tangent(double s, bool orientation) const override;
protected:
std::shared_ptr<Vertex> Center;
......@@ -84,14 +79,13 @@ protected:
bool on_segment(const double x, const double y) const override;
Direction is_identical(const double r, const double xc, const double yc, const double xs, const double ys, const double xe, const double ye) const;
private:
double s_to_a(double s) const;
double a_to_s(double a) const;
double arc_angle() const;
Direction is_identical(const double r, const double xc, const double yc, const double xs, const double ys, const double xe, const double ye) const;
};
#endif //OERSTED_CIRCULARARC_H
#include "Sketch.hpp"
#include "Coincident.h"
#include "CircularArc.h"
#include "LineSegment.h"
template<>
void Coincident<CircularArc>::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) {
const double rc = Element->radius();
const double xc = Element->Center->x();
const double yc = Element->Center->y();
const double xc = Element->center()->x();
const double yc = Element->center()->y();
const double xp = Point->x();
const double yp = Point->y();
......@@ -17,13 +19,13 @@ void Coincident<CircularArc>::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) {
r(EquationIndex) = dr - rc;
J(EquationIndex, Element->Radius->get_index()) = -dr / rc;
J(EquationIndex, Element->radius_index()) = -dr / rc;
J(EquationIndex, Element->Center->X->get_index()) -= dx;
J(EquationIndex, Element->Center->Y->get_index()) -= dy;
J(EquationIndex, Element->center()->x_index()) -= dx;
J(EquationIndex, Element->center()->y_index()) -= dy;
J(EquationIndex, Point->X->get_index()) += dx;
J(EquationIndex, Point->Y->get_index()) += dy;
J(EquationIndex, Point->x_index()) += dx;
J(EquationIndex, Point->y_index()) += dy;
}
template
......@@ -34,10 +36,10 @@ void Coincident<LineSegment>::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) {
const double xp = Point->x();
const double yp = Point->y();
const double x0 = Element->Start->x();
const double y0 = Element->Start->y();
const double x1 = Element->End->x();
const double y1 = Element->End->y();
const double x0 = Element->start()->x();
const double y0 = Element->start()->y();
const double x1 = Element->end()->x();
const double y1 = Element->end()->y();
double dx0 = x0 - xp;
double dy0 = y0 - yp;
......@@ -62,16 +64,16 @@ void Coincident<LineSegment>::update(Eigen::MatrixXd &J, Eigen::VectorXd &r) {
f0 = scale * (dy1 - cross * dx0) / dr0;
f1 = scale * (dy0 + cross * dx1) / dr1;
J(EquationIndex, Point->X->get_index()) -= f0 - f1;
J(EquationIndex, Element->Start->X->get_index()) += f0;
J(EquationIndex, Element->End->X->get_index()) -= f1;
J(EquationIndex, Point->x_index()) -= f0 - f1;
J(EquationIndex, Element->start()->x_index()) += f0;
J(EquationIndex, Element->end()->x_index()) -= f1;
f0 = scale * (dx1 + cross * dy0) / dr0;
f1 = scale * (dx0 - cross * dy1) / dr1;
J(EquationIndex, Point->Y->get_index()) += f0 - f1;
J(EquationIndex, Element->Start->Y->get_index()) -= f0;
J(EquationIndex, Element->End->Y->get_index()) += f1;
J(EquationIndex, Point->y_index()) += f0 - f1;
J(EquationIndex, Element->start()->y_index()) -= f0;
J(EquationIndex, Element->end()->y_index()) += f1;
}
template
......
#ifndef OERSTED_COINCIDENT_H
#define OERSTED_COINCIDENT_H
#include "Constraint.h"
class Vertex;
template<class T>
class Coincident : public Constraint {
public:
std::shared_ptr<Vertex> Point;
std::shared_ptr<T> Element;
// Constructors
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 {
EquationIndex = i;
return 1;
};
void update(Eigen::MatrixXd &J, Eigen::VectorXd &r) override;
protected:
std::shared_ptr<Vertex> Point;
std::shared_ptr<T> Element;
};
#endif //OERSTED_COINCIDENT_H
#include "Sketch.hpp"
#include "Constellation.h"
#include "Sketch.h"
#include "Star.h"
#include "Branch.h"
#include "Curve.h"
#include "Contour.h"
Constellation::Constellation(Sketch const *s) {
for (size_t i = 0; i != s->size_verticies(); ++i) {
......
#ifndef OERSTED_CONSTELLATION_H
#define OERSTED_CONSTELLATION_H
#include "Sketch.h"
#include <list>
#include <vector>
#include <memory>
class Branch;
class Contour;
class Curve;
class Star;
class Sketch;
class Constellation {
public:
// Constructors
Constellation() {};
Constellation(Sketch const *s);
......@@ -19,13 +26,13 @@ public:
private:
std::list<Star> Stars;
void pop(std::shared_ptr<Curve> c = std::shared_ptr<Curve>());
bool find_closed_contour(std::vector<std::shared_ptr<Curve>> &curves, std::vector<bool> &orientation);
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);
void pop(std::shared_ptr<Curve> c = std::shared_ptr<Curve>());
bool find_closed_contour(std::vector<std::shared_ptr<Curve>> &curves, std::vector<bool> &orientation);
void supremum(std::list<Star>::iterator &s_out, std::list<Branch>::iterator &b_out);
};
#endif //OERSTED_CONSTELLATION_H
\ No newline at end of file
#include "Sketch.hpp"
\ No newline at end of file
#include "Constraint.h"
\ No newline at end of file