preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Edge.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <array>
5#include <iostream>
6
8#include "mesh/Vertex.hpp"
10#include "utils/assertion.hpp"
11
12namespace precice::mesh {
13
15class Edge {
16public:
18 static constexpr int vertexCount{2};
19
26 Edge(
27 Vertex &vertexOne,
28 Vertex &vertexTwo);
29
31 int getDimensions() const;
32
34 Vertex &vertex(int i);
35
37 const Vertex &vertex(int i) const;
38
40 double getLength() const;
41
43 const Eigen::VectorXd getCenter() const;
44
46 double getEnclosingRadius() const;
47
49 bool connectedTo(const Edge &other) const;
50
57 bool operator==(const Edge &other) const;
58
60 bool operator!=(const Edge &other) const;
61
63 bool operator<(const Edge &other) const
64 {
65 return std::make_tuple(_vertices[0]->getID(), _vertices[1]->getID()) <
66 std::make_tuple(other._vertices[0]->getID(), other._vertices[1]->getID());
67 }
68
69private:
72};
73
74// ------------------------------------------------------ HEADER IMPLEMENTATION
75
77 int i)
78{
79 PRECICE_ASSERT((i == 0) || (i == 1), i);
80 return *_vertices[i];
81}
82
83inline const Vertex &Edge::vertex(
84 int i) const
85{
86 PRECICE_ASSERT((i == 0) || (i == 1), i);
87 return *_vertices[i];
88}
89
90inline int Edge::getDimensions() const
91{
92 return _vertices[0]->getDimensions();
93}
94
95std::ostream &operator<<(std::ostream &stream, const Edge &edge);
96
97} // namespace precice::mesh
#define PRECICE_ASSERT(...)
Definition assertion.hpp:85
Linear edge of a mesh, defined by two Vertex objects.
Definition Edge.hpp:15
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
int getDimensions() const
Returns number of spatial dimensions (2 or 3) the edge is embedded to.
Definition Edge.hpp:90
static constexpr int vertexCount
Amount of vertices.
Definition Edge.hpp:18
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:76
std::array< Vertex *, 2 > _vertices
Pointers to Vertex objects defining the edge, ordered by Vertex::getID().
Definition Edge.hpp:71
bool operator<(const Edge &other) const
Weak ordering based on vertex ids.
Definition Edge.hpp:63
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
T make_tuple(T... args)
provides Mesh, Data and primitives.
std::ostream & operator<<(std::ostream &os, const BoundingBox &bb)