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

Adds Sketch methods for selecting periodic verticies

parent 6f7e6a18
......@@ -203,7 +203,7 @@ void Sketch::save_as<SaveMethod::Rasterize>(std::string path, std::string file_n
fs.close();
}
std::vector<ContinuousBoundaryPair> Sketch::select_periodic_boundary_pairs(std::shared_ptr<Vertex> v0, double_t angle) const {
std::vector<ContinuousBoundaryPair> Sketch::select_periodic_boundary_pairs(std::shared_ptr<Vertex const> const &v0, double_t angle) const {
std::vector<ContinuousBoundaryPair> cbp;
std::vector<std::shared_ptr<Curve const>> bc = Boundary->curves();
......@@ -247,7 +247,7 @@ std::vector<ContinuousBoundaryPair> Sketch::select_periodic_boundary_pairs(std::
return cbp;
}
std::vector<std::shared_ptr<Curve const>> Sketch::select_radial_boundary(std::shared_ptr<Vertex> v0, double_t radius) const {
std::vector<std::shared_ptr<Curve const>> Sketch::select_radial_boundary(std::shared_ptr<Vertex const> const &v0, double_t radius) const {
std::vector<std::shared_ptr<Curve const>> rb;
std::vector<std::shared_ptr<Curve const>> bc = Boundary->curves();
......@@ -260,4 +260,15 @@ std::vector<std::shared_ptr<Curve const>> Sketch::select_radial_boundary(std::sh
}
return rb;
}
std::shared_ptr<Vertex const> Sketch::select_periodic_vertex(std::shared_ptr<Vertex const> const &v, std::shared_ptr<Vertex const> const &origin, double_t angle) const {
for(auto const &v_test : Verticies) {
if (v_test->is_identical(v, origin, angle)) {
return v_test;
}
}
std::shared_ptr<Vertex const> nullv;
return nullv;
}
\ No newline at end of file
......@@ -83,9 +83,11 @@ public:
std::vector<std::shared_ptr<Curve const>> const curves() { return std::vector<std::shared_ptr<Curve const>>{Curves.begin(),Curves.end()};};
std::vector<ContinuousBoundaryPair> select_periodic_boundary_pairs(std::shared_ptr<Vertex> v0, double_t angle) const;
std::vector<ContinuousBoundaryPair> select_periodic_boundary_pairs(std::shared_ptr<Vertex const> const &v0, double_t angle) const;
std::vector<std::shared_ptr<Curve const>> select_radial_boundary(std::shared_ptr<Vertex> v0, double_t radius) const;
std::vector<std::shared_ptr<Curve const>> select_radial_boundary(std::shared_ptr<Vertex const> const &v0, double_t radius) const;
std::shared_ptr<Vertex const> select_periodic_vertex(std::shared_ptr<Vertex const> const &v1, std::shared_ptr<Vertex const> const &origin, double_t angle) const;
private:
std::vector<std::shared_ptr<Variable>> Variables;
......
......@@ -26,6 +26,19 @@ public:
bool operator==(Vertex const &v) { return (v.X == X) && (v.Y == Y); };
bool is_identical(std::shared_ptr<Vertex const> const &v, std::shared_ptr<Vertex const> const &origin, double_t angle) const {
double_t xr = v->x() - origin->x();
double_t yr = v->y() - origin->y();
double_t rr = sqrt(xr * xr + yr * yr);
double_t ar = atan2(yr, xr);
ar += angle * M_PI / 180.0;
xr = origin->x() + rr * cos(ar) - x();
yr = origin->y() + rr * sin(ar) - y();
return (sqrt(xr * xr + yr * yr) < rr * FLT_EPSILON);
}
double atan() const { return std::atan2(y(), x()); };
double hypot() const { return std::hypot(x(), y()); };
......
......@@ -202,8 +202,28 @@ TEST(Library_Integration, Quadrter_Circle_Mirror_Copy_Uniform_Current_Density) {
}
}
// TODO: Select periodic verticies
// auto sk.select_periodic_vertex(v0,v1,90.0);
auto v1p = sk.select_periodic_vertex(v1, v0, 90.0);
{
ASSERT_TRUE(v1p); // Make sure that returned vertex pointer is not null
double_t x0 = v0->x();
double_t y0 = v0->y();
double_t x1 = v1->x();
double_t y1 = v1->y();
double_t x2 = v1p->x();
double_t y2 = v1p->y();
double_t dx = x1 - x0;
double_t dy = y1 - y0;
double_t dr = std::hypot(dx, dy);
double_t da = std::atan2(dy, dx);
da += M_PI / 2.0;
x1 = x0 + dr * std::cos(da);
y1 = y0 + dr * std::sin(da);
EXPECT_NEAR(x1, x2, dr * FLT_EPSILON);
EXPECT_NEAR(y1, y2, dr * FLT_EPSILON);
}
// Create Mesh
Mesh me{sk};
......
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