preCICE v3.1.1
Loading...
Searching...
No Matches
Edge.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <algorithm>
3
4#include "Edge.hpp"
7#include "utils/EigenIO.hpp"
8
9namespace precice::mesh {
10
12 Vertex &vertexOne,
13 Vertex &vertexTwo)
14 : _vertices({&vertexOne, &vertexTwo})
15{
16 if (*_vertices[1] < *_vertices[0]) {
17 std::swap(_vertices[0], _vertices[1]);
18 }
19 PRECICE_ASSERT(vertexOne.getDimensions() == vertexTwo.getDimensions(),
20 vertexOne.getDimensions(), vertexTwo.getDimensions());
21}
22
23double Edge::getLength() const
24{
25 double length = (_vertices[1]->getCoords() - _vertices[0]->getCoords()).norm();
26 return length;
27}
28
29const Eigen::VectorXd Edge::getCenter() const
30{
31 return 0.5 * (_vertices[0]->getCoords() + _vertices[1]->getCoords());
32}
33
35{
36 return (_vertices[0]->getCoords() - getCenter()).norm();
37}
38
39bool Edge::connectedTo(const Edge &other) const
40{
41 return _vertices[0] == other._vertices[0] || _vertices[0] == other._vertices[1] || _vertices[1] == other._vertices[0] || _vertices[1] == other._vertices[1];
42}
43
44bool Edge::operator==(const Edge &other) const
45{
46 return std::is_permutation(_vertices.begin(), _vertices.end(), other._vertices.begin(),
47 [](const Vertex *a, const Vertex *b) { return *a == *b; });
48}
49bool Edge::operator!=(const Edge &other) const
50{
51 return !(*this == other);
52}
53
55{
57 return stream << "LINESTRING ("
58 << edge.vertex(0).getCoords().transpose().format(wkt())
59 << ", "
60 << edge.vertex(1).getCoords().transpose().format(wkt())
61 << ')';
62}
63
64} // namespace precice::mesh
#define PRECICE_ASSERT(...)
Definition assertion.hpp:87
Linear edge of a mesh, defined by two Vertex objects.
Definition Edge.hpp:16
double getEnclosingRadius() const
Returns the radius of the enclosing circle of the edge.
Definition Edge.cpp:34
bool operator!=(const Edge &other) const
Not equal, implemented in terms of equal.
Definition Edge.cpp:49
double getLength() const
Returns the length of the edge.
Definition Edge.cpp:23
Edge(Vertex &vertexOne, Vertex &vertexTwo)
Constructor.
Definition Edge.cpp:11
const Eigen::VectorXd getCenter() const
Returns the center of the edge.
Definition Edge.cpp:29
bool operator==(const Edge &other) const
Compares two Edges for equality.
Definition Edge.cpp:44
Vertex & vertex(int i)
Returns the edge's vertex with index 0 or 1.
Definition Edge.hpp:77
std::array< Vertex *, 2 > _vertices
Pointers to Vertex objects defining the edge, ordered by Vertex::getID().
Definition Edge.hpp:72
bool connectedTo(const Edge &other) const
Checks whether both edges share a vertex.
Definition Edge.cpp:39
Vertex of a mesh.
Definition Vertex.hpp:16
Eigen::VectorXd getCoords() const
Returns the coordinates of the vertex.
Definition Vertex.hpp:116
T is_permutation(T... args)
provides Mesh, Data and primitives.
std::ostream & operator<<(std::ostream &os, const BoundingBox &bb)
Eigen::IOFormat wkt()
Definition EigenIO.hpp:9
T swap(T... args)