Pangolin
Header-only C++20 plane computational geometry library
Loading...
Searching...
No Matches
shape.hpp File Reference

Runtime variant wrapper over the currently implemented shape types. More...

#include "shape/polygonset.hpp"
#include <compare>
#include <concepts>
#include <functional>
#include <optional>
#include <ostream>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <variant>
#include <vector>

Go to the source code of this file.

Classes

struct  pgl::Shape< PointType >
 Runtime variant wrapper over the supported primitive shapes. More...

Namespaces

namespace  pgl

Macros

Per-alternative accessors

Named shorthands for holdsAlternative and getIf, one family per stored alternative: isPoint() / getIfPoint(), isSegment() / getIfSegment(), and so on through every alternative of Variant.

These test which alternative is stored, not the geometry of the stored value. This differs from the same-named methods on the concrete shapes, where isPoint() asks whether the shape's point set is a single point: a Shape holding a Triangle whose vertices coincide reports isTriangle() and not isPoint(). Reach through with getIfTriangle()->isPoint() to ask the geometric question.

getIf... returns a pointer into the stored variant, nullptr when another alternative is active. The EmptyShape alternative has no such pair; use holdsAlternative<EmptyShape<PointType>>(), since empty() asks the geometric question and is also true for, say, an empty Rectangle.

#define PGL_SHAPE_ALTERNATIVE(Name, Type)

Functions

template<class T, class... Ts>
 pgl::Shape (const std::variant< T, Ts... > &) -> Shape< detail::shape_point_type_t< T > >
template<class T, class... Ts>
 pgl::Shape (const std::optional< std::variant< T, Ts... > > &) -> Shape< detail::shape_point_type_t< T > >
template<class PointType, class TranslationNumber, class TranslationLabel>
constexpr auto pgl::operator- (const Shape< PointType > &shape, const Point< TranslationNumber, TranslationLabel > &translation)
 Translates a shape by a negated point.
template<class PointType, class Scalar>
requires (!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
constexpr auto pgl::operator* (const Shape< PointType > &shape, const Scalar &scalar)
 Scales a shape around the origin.
template<class Scalar, class PointType>
requires (!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
constexpr auto pgl::operator* (const Scalar &scalar, const Shape< PointType > &shape)
 Scales a shape around the origin.
template<class PointType, class Scalar>
requires (!detail::is_point_v<Scalar> && !TransformationConcept<Scalar>)
constexpr auto pgl::operator/ (const Shape< PointType > &shape, const Scalar &scalar)
 Divides a shape around the origin.
template<class PointType>
std::ostream & pgl::operator<< (std::ostream &stream, const Shape< PointType > &shape)
 Streams the currently stored alternative.

Detailed Description

Runtime variant wrapper over the currently implemented shape types.

Most of Pangolin is static and template-based; Shape exists for places where runtime dispatch over heterogeneous shapes is more convenient.

Macro Definition Documentation

◆ PGL_SHAPE_ALTERNATIVE

#define PGL_SHAPE_ALTERNATIVE ( Name,
Type )
Value:
\
[[nodiscard]] constexpr bool is##Name() const { \
return std::holds_alternative<Type>(value_); \
} \ \
[[nodiscard]] constexpr const Type* getIf##Name() const { \
return std::get_if<Type>(&value_); \
} \ \
[[nodiscard]] constexpr Type* getIf##Name() { \
return std::get_if<Type>(&value_); \
}