Fishnet 2.0.1
Framework for Graph-Based Analysis of GIS Vector Data
Loading...
Searching...
No Matches
Triangle.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4
5#include <fishnet/Vec2D.hpp>
8#include "Ring.hpp"
9#include "SimplePolygon.hpp"
10
11namespace fishnet::geometry {
12
18template<fishnet::math::Number T>
19class Triangle : public SimplePolygon<T> {
20public:
21 using numeric_type = T;
22 constexpr static GeometryType type = GeometryType::POLYGON;
23
30 Triangle(const Vec2D<T> & a, const Vec2D<T> & b, const Vec2D<T> & c)
31 : SimplePolygon<T>(Ring<T>({a, b, c})) {}
32
36 constexpr util::view_of<Vec2D<T>> auto getPoints() const noexcept {
37 return this->getBoundary().getPoints();
38 }
39
43 constexpr util::view_of<Segment<T>> auto getSegments() const noexcept {
44 return this->getBoundary().getSegments();
45 }
46
47 constexpr std::string toString() const noexcept {
48 auto pts = getPoints();
49 return "Triangle{" + pts[0].toString() + ", " + pts[1].toString() + ", " + pts[2].toString() + "}";
50 }
51};
52
53// Deduction guide
54template<math::Number T>
55Triangle(const Vec2D<T> &, const Vec2D<T> &, const Vec2D<T> &) -> Triangle<T>;
56
57static_assert(IPolygon<Triangle<double>>);
58static_assert(Shape<Triangle<double>>);
59// Explicit template instantiation
61} // namespace fishnet::geometry
Implementation of a ring.
Definition Ring.hpp:31
Simple polygon implementation with no holes.
Definition SimplePolygon.hpp:13
constexpr const Ring< T > & getBoundary() const noexcept
Definition SimplePolygon.hpp:35
Triangle shape implementation Inherits from SimplePolygon<T> (a 3-vertex ring)
Definition Triangle.hpp:19
Triangle(const Vec2D< T > &a, const Vec2D< T > &b, const Vec2D< T > &c)
Construct a Triangle from three vertices.
Definition Triangle.hpp:30
constexpr util::view_of< Vec2D< T > > auto getPoints() const noexcept
Get the three vertices as a random access range.
Definition Triangle.hpp:36
T numeric_type
Definition Triangle.hpp:21
static constexpr GeometryType type
Definition Triangle.hpp:22
constexpr util::view_of< Segment< T > > auto getSegments() const noexcept
Get the three edges as a range of segments.
Definition Triangle.hpp:43
constexpr std::string toString() const noexcept
Definition Triangle.hpp:47
Implementation of a two-dimensional vector.
Definition Vec2D.hpp:16
Interface for a polygon A polygon is a two-dimensional shape defined by a boundary and zero or more h...
Definition IPolygon.hpp:98
A geometry enclosing an area: a ring, a polygon or a multi-polygon.
Definition IGeometry.hpp:23
Definition CollectionConcepts.hpp:45
Definition BoundingBoxWrapper.hpp:5
GeometryType
Definition GeometryBase.hpp:6