@ -0,0 +1,35 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GEOM_PRIMITIVE_BOX_HPP | |||
#define ANTKEEPER_GEOM_PRIMITIVE_BOX_HPP | |||
#include "geom/primitive/hyperrectangle.hpp" | |||
namespace geom { | |||
namespace primitive { | |||
/// 3-dimensional hyperrectangle. | |||
template <class T> | |||
using box = hyperrectangle<T, 3>; | |||
} // namespace primitive | |||
} // namespace geom | |||
#endif // ANTKEEPER_GEOM_PRIMITIVE_BOX_HPP |
@ -0,0 +1,35 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GEOM_PRIMITIVE_CIRCLE_HPP | |||
#define ANTKEEPER_GEOM_PRIMITIVE_CIRCLE_HPP | |||
#include "geom/primitive/hypersphere.hpp" | |||
namespace geom { | |||
namespace primitive { | |||
/// 2-dimensional hypersphere. | |||
template <class T> | |||
using circle = hypersphere<T, 2>; | |||
} // namespace primitive | |||
} // namespace geom | |||
#endif // ANTKEEPER_GEOM_PRIMITIVE_CIRCLE_HPP |
@ -0,0 +1,75 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GEOM_PRIMITIVE_HYPERPLANE_HPP | |||
#define ANTKEEPER_GEOM_PRIMITIVE_HYPERPLANE_HPP | |||
#include "math/vector.hpp" | |||
namespace geom { | |||
namespace primitive { | |||
/** | |||
* *n*-dimensional plane. | |||
* | |||
* @tparam T Real type. | |||
* @tparam N Number of dimensions. | |||
*/ | |||
template <class T, std::size_t N> | |||
struct hyperplane | |||
{ | |||
typedef math::vector<T, N> vector_type; | |||
/// Hyperplane normal. | |||
vector_type normal; | |||
/// Hyperplane constant. | |||
T constant; | |||
/// Constructs a hyperplane. | |||
constexpr hyperplane() noexcept = default; | |||
/** | |||
* Constructs a hyperplane given a point and a normal. | |||
* | |||
* @param point Point. | |||
* @param normal Normal. | |||
*/ | |||
constexpr hyperplane(const vector_type& point, const vector_type& normal) noexcept: | |||
normal(normal), | |||
constant(-math::dot(normal, point)) | |||
{} | |||
/** | |||
* Calculates the signed distance from the hyperplane to a point. | |||
* | |||
* @param point Input point. | |||
* | |||
* @return Signed distance from the hyperplane to @p point. | |||
*/ | |||
constexpr T distance(const vector_type& point) const noexcept | |||
{ | |||
return math::dot(normal, point) + constant; | |||
} | |||
}; | |||
} // namespace primitive | |||
} // namespace geom | |||
#endif // ANTKEEPER_GEOM_PRIMITIVE_HYPERPLANE_HPP |
@ -0,0 +1,162 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GEOM_PRIMITIVE_HYPERRECTANGLE_HPP | |||
#define ANTKEEPER_GEOM_PRIMITIVE_HYPERRECTANGLE_HPP | |||
#include "math/vector.hpp" | |||
#include <algorithm> | |||
namespace geom { | |||
namespace primitive { | |||
/** | |||
* *n*-dimensional axis-aligned rectangle. | |||
* | |||
* @tparam T Real type. | |||
* @tparam N Number of dimensions. | |||
*/ | |||
template <class T, std::size_t N> | |||
struct hyperrectangle | |||
{ | |||
typedef math::vector<T, N> vector_type; | |||
/// Minimum extent of the hyperrectangle. | |||
vector_type min; | |||
/// Maximum extent of the hyperrectangle. | |||
vector_type max; | |||
/** | |||
* Tests whether a point is contained within this hyperrectangle. | |||
* | |||
* @param point Point to test for containment. | |||
* | |||
* @return `true` if the point is contained within this hyperrectangle, `false` otherwise. | |||
*/ | |||
constexpr bool contains(const vector_type& point) const noexcept | |||
{ | |||
for (std::size_t i = 0; i < N; ++i) | |||
if (point[i] < min[i] || point[i] > max[i]) | |||
return false; | |||
return true; | |||
} | |||
/** | |||
* Tests whether another hyperrectangle is contained within this hyperrectangle. | |||
* | |||
* @param other Hyperrectangle to test for containment. | |||
* | |||
* @return `true` if the hyperrectangle is contained within this hyperrectangle, `false` otherwise. | |||
*/ | |||
constexpr bool contains(const hyperrectangle& other) const noexcept | |||
{ | |||
for (std::size_t i = 0; i < N; ++i) | |||
if (other.min[i] < min[i] || other.max[i] > max[i]) | |||
return false; | |||
return true; | |||
} | |||
/// Returns the center position of the hyperrectangle. | |||
constexpr vector_type center() const noexcept | |||
{ | |||
return (min + max) * T{0.5}; | |||
} | |||
/** | |||
* Calculates the signed distance from the hyperrectangle to a point. | |||
* | |||
* @param point Input point. | |||
* | |||
* @return Signed distance from the hyperrectangle to @p point. | |||
*/ | |||
T distance(const vector_type& point) const noexcept | |||
{ | |||
vector_type d = math::abs(point - center()) - size() * T{0.5}; | |||
return math::length(math::max(vector_type::zero(), d)) + std::min<T>(T{0}, math::max(d)); | |||
} | |||
/** | |||
* Extends the hyperrectangle to include a point. | |||
* | |||
* @param point Point to include in the hyperrectangle. | |||
*/ | |||
void extend(const vector_type& point) noexcept | |||
{ | |||
min = math::min(min, point); | |||
max = math::max(max, point); | |||
} | |||
/** | |||
* Extends the hyperrectangle to include another hyperrectangle. | |||
* | |||
* @param other Hyperrectangle to include in this hyperrectangle. | |||
*/ | |||
void extend(const hyperrectangle& other) noexcept | |||
{ | |||
min = math::min(min, other.min); | |||
max = math::max(max, other.max); | |||
} | |||
/** | |||
* Tests whether another hyperrectangle intersects this hyperrectangle. | |||
* | |||
* @param other Hyperrectangle to test for intersection. | |||
* | |||
* @return `true` if the hyperrectangle intersects this hyperrectangle, `false` otherwise. | |||
*/ | |||
constexpr bool intersects(const hyperrectangle& other) const noexcept | |||
{ | |||
for (std::size_t i = 0; i < N; ++i) | |||
if (other.min[i] > max[i] || other.max[i] < min[i]) | |||
return false; | |||
return true; | |||
} | |||
/// Returns the size of the hyperrectangle. | |||
constexpr vector_type size() const noexcept | |||
{ | |||
return max - min; | |||
} | |||
/** | |||
* Returns `false` if any coordinates of `min` are greater than `max`. | |||
*/ | |||
constexpr bool valid() const noexcept | |||
{ | |||
for (std::size_t i = 0; i < N; ++i) | |||
if (min[i] > max[i]) | |||
return false; | |||
return true; | |||
} | |||
/// Calculates the volume of the hyperrectangle. | |||
constexpr T volume() const noexcept | |||
{ | |||
T v = max[0] - min[0]; | |||
for (std::size_t i = 1; i < N; ++i) | |||
v *= max[i] - min[i]; | |||
return v; | |||
} | |||
}; | |||
} // namespace primitive | |||
} // namespace geom | |||
#endif // ANTKEEPER_GEOM_PRIMITIVE_HYPERRECTANGLE_HPP |
@ -0,0 +1,139 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GEOM_PRIMITIVE_HYPERSPHERE_HPP | |||
#define ANTKEEPER_GEOM_PRIMITIVE_HYPERSPHERE_HPP | |||
#include "math/constants.hpp" | |||
#include "math/vector.hpp" | |||
namespace geom { | |||
namespace primitive { | |||
/** | |||
* *n*-dimensional sphere. | |||
* | |||
* @tparam T Real type. | |||
* @tparam N Number of dimensions. | |||
*/ | |||
template <class T, std::size_t N> | |||
struct hypersphere | |||
{ | |||
typedef math::vector<T, N> vector_type; | |||
/// Hypersphere center. | |||
vector_type center; | |||
/// Hypersphere radius. | |||
T radius; | |||
/** | |||
* Tests whether a point is contained within this hypersphere. | |||
* | |||
* @param point Point to test for containment. | |||
* | |||
* @return `true` if the point is contained within this hypersphere, `false` otherwise. | |||
*/ | |||
constexpr bool contains(const vector_type& point) const noexcept | |||
{ | |||
return math::distance_squared(center, point) <= radius * radius; | |||
} | |||
/** | |||
* Tests whether another hypersphere is contained within this hypersphere. | |||
* | |||
* @param other Hypersphere to test for containment. | |||
* | |||
* @return `true` if the hypersphere is contained within this hypersphere, `false` otherwise. | |||
*/ | |||
constexpr bool contains(const hypersphere& other) const noexcept | |||
{ | |||
const T containment_radius = radius - other.radius; | |||
if (containment_radius < T{0}) | |||
return false; | |||
return math::distance_squared(center, other.center) <= containment_radius * containment_radius; | |||
} | |||
/** | |||
* Calculates the signed distance from the hypersphere to a point. | |||
* | |||
* @param point Input point. | |||
* | |||
* @return Signed distance from the hypersphere to @p point. | |||
*/ | |||
T distance(const vector_type& point) const noexcept | |||
{ | |||
return math::distance(center, point) - radius; | |||
} | |||
/** | |||
* Tests whether another hypersphere intersects this hypersphere. | |||
* | |||
* @param other Hypersphere to test for intersection. | |||
* | |||
* @return `true` if the hypersphere intersects this hypersphere, `false` otherwise. | |||
*/ | |||
constexpr bool intersects(const hypersphere& other) const noexcept | |||
{ | |||
const T intersection_radius = radius + other.radius; | |||
return math::distance_squared(center, other.center) <= intersection_radius * intersection_radius; | |||
} | |||
/** | |||
* Volume calculation helper function. | |||
* | |||
* @tparam M Dimension. | |||
* | |||
* @param r Radius. | |||
* | |||
* @return Volume. | |||
*/ | |||
/// @private | |||
/// @{ | |||
template <std::size_t M> | |||
static constexpr T volume(T r) noexcept | |||
{ | |||
return (math::two_pi<T> / static_cast<T>(M)) * r * r * volume<M - 2>(r); | |||
} | |||
template <> | |||
static constexpr T volume<1>(T r) noexcept | |||
{ | |||
return r * T{2}; | |||
} | |||
template <> | |||
static constexpr T volume<0>(T r) noexcept | |||
{ | |||
return T{1}; | |||
} | |||
/// @} | |||
/// Calculates the volume of the hypersphere. | |||
inline constexpr T volume() const noexcept | |||
{ | |||
return volume<N>(radius); | |||
} | |||
}; | |||
} // namespace primitive | |||
} // namespace geom | |||
#endif // ANTKEEPER_GEOM_PRIMITIVE_HYPERSPHERE_HPP |
@ -0,0 +1,199 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GEOM_PRIMITIVE_INTERSECTION_HPP | |||
#define ANTKEEPER_GEOM_PRIMITIVE_INTERSECTION_HPP | |||
#include "geom/primitive/hyperplane.hpp" | |||
#include "geom/primitive/hyperrectangle.hpp" | |||
#include "geom/primitive/hypersphere.hpp" | |||
#include "geom/primitive/ray.hpp" | |||
#include <algorithm> | |||
#include <optional> | |||
namespace geom { | |||
namespace primitive { | |||
/** | |||
* Ray-hyperplane intersection test. | |||
* | |||
* @param ray Ray. | |||
* @param hyperplane Hyperplane. | |||
* | |||
* @return Distance along the ray to the point of intersection, or `std::nullopt` if no intersection occurred. | |||
*/ | |||
/// @{ | |||
template <class T, std::size_t N> | |||
constexpr std::optional<T> intersection(const ray<T, N>& ray, const hyperplane<T, N>& hyperplane) noexcept | |||
{ | |||
const T cos_theta = math::dot(ray.direction, hyperplane.normal); | |||
if (cos_theta != T{0}) | |||
{ | |||
const T t = -hyperplane.distance(ray.origin) / cos_theta; | |||
if (t >= T{0}) | |||
return t; | |||
} | |||
return std::nullopt; | |||
} | |||
template <class T, std::size_t N> | |||
constexpr inline std::optional<T> intersection(const hyperplane<T, N>& hyperplane, const ray<T, N>& ray) noexcept | |||
{ | |||
return intersection<T, N>(ray, hyperplane); | |||
} | |||
/// @} | |||
/** | |||
* Ray-hyperrectangle intersection test. | |||
* | |||
* @param ray Ray. | |||
* @param hyperrectangle Hyperrectangle. | |||
* | |||
* @return Tuple containing the distances along the ray to the first and second points of intersection, or `std::nullopt` if no intersection occurred. | |||
*/ | |||
/// @{ | |||
template <class T, std::size_t N> | |||
constexpr std::optional<std::tuple<T, T>> intersection(const ray<T, N>& ray, const hyperrectangle<T, N>& hyperrectangle) noexcept | |||
{ | |||
T t0 = -std::numeric_limits<T>::infinity(); | |||
T t1 = std::numeric_limits<T>::infinity(); | |||
for (std::size_t i = 0; i < N; ++i) | |||
{ | |||
if (!ray.direction[i]) | |||
{ | |||
if (ray.origin[i] < hyperrectangle.min[i] || ray.origin[i] > hyperrectangle.max[i]) | |||
return std::nullopt; | |||
} | |||
else | |||
{ | |||
T min = (hyperrectangle.min[i] - ray.origin[i]) / ray.direction[i]; | |||
T max = (hyperrectangle.max[i] - ray.origin[i]) / ray.direction[i]; | |||
t0 = std::max(t0, std::min(min, max)); | |||
t1 = std::min(t1, std::max(min, max)); | |||
} | |||
} | |||
if (t0 > t1 || t1 < T{0}) | |||
return std::nullopt; | |||
return {t0, t1}; | |||
} | |||
template <class T, std::size_t N> | |||
constexpr inline std::optional<std::tuple<T, T>> intersection(const hyperrectangle<T, N>& hyperrectangle, const ray<T, N>& ray) noexcept | |||
{ | |||
return intersection<T, N>(ray, hyperrectangle); | |||
} | |||
/// @} | |||
/** | |||
* Ray-hypersphere intersection test. | |||
* | |||
* @param ray Ray. | |||
* @param hypersphere Hypersphere. | |||
* | |||
* @return Tuple containing the distances along the ray to the first and second points of intersection, or `std::nullopt` if no intersection occurred. | |||
*/ | |||
template <class T, std::size_t N> | |||
std::optional<std::tuple<T, T>> intersection(const ray<T, N>& ray, const hypersphere<T, N>& hypersphere) noexcept | |||
{ | |||
const math::vector<T, N> displacement = ray.origin - hypersphere.center; | |||
const T b = math::dot(displacement, ray.direction); | |||
const T c = math::length_squared(displacement) - hypersphere.radius * hypersphere.radius; | |||
T h = b * b - c; | |||
if (h < T{0}) | |||
return std::nullopt; | |||
h = std::sqrt(h); | |||
return std::tuple<float, float>{-b - h, -b + h}; | |||
} | |||
/** | |||
* Hyperrectangle-hyperrectangle intersection test. | |||
* | |||
* @param a First hyperrectangle. | |||
* @param b Second hyperrectangle. | |||
* | |||
* @return `true` if an intersection occurred, `false` otherwise. | |||
*/ | |||
template <class T, std::size_t N> | |||
constexpr inline bool intersection(const hyperrectangle<T, N>& a, const hyperrectangle<T, N>& b) noexcept | |||
{ | |||
return a.intersects(b); | |||
} | |||
/** | |||
* Hyperrectangle-hypersphere intersection test. | |||
* | |||
* @param hyperrectangle Hyperrectangle. | |||
* @param hypersphere Hypersphere. | |||
* | |||
* @return `true` if an intersection occurred, `false` otherwise. | |||
*/ | |||
/// @{ | |||
template <class T, std::size_t N> | |||
constexpr bool intersection(const hyperrectangle<T, N>& hyperrectangle, const hypersphere<T, N>& hypersphere) noexcept | |||
{ | |||
T sqr_distance{0}; | |||
for (std::size_t i = 0; i < N; ++i) | |||
{ | |||
if (hypersphere.center[i] < hyperrectangle.min[i]) | |||
{ | |||
const T difference = hyperrectangle.min[i] - hypersphere.center[i]; | |||
sqr_distance += difference * difference; | |||
} | |||
else if (hypersphere.center[i] > hyperrectangle.max[i]) | |||
{ | |||
const T difference = hypersphere.center[i] - hyperrectangle.max[i]; | |||
sqr_distance += difference * difference; | |||
} | |||
} | |||
return sqr_distance <= hypersphere.radius * hypersphere.radius; | |||
} | |||
template <class T, std::size_t N> | |||
constexpr inline bool intersection(const hypersphere<T, N>& hypersphere, const hyperrectangle<T, N>& hyperrectangle) noexcept | |||
{ | |||
return intersection<T, N>(hyperrectangle, hypersphere); | |||
} | |||
/// @} | |||
/** | |||
* Hypersphere-hypersphere intersection test. | |||
* | |||
* @param a First hypersphere. | |||
* @param b Second hypersphere. | |||
* | |||
* @return `true` if an intersection occurred, `false` otherwise. | |||
*/ | |||
template <class T, std::size_t N> | |||
constexpr inline bool intersection(const hypersphere<T, N>& a, const hypersphere<T, N>& b) noexcept | |||
{ | |||
return a.intersects(b); | |||
} | |||
} // namespace primitive | |||
} // namespace geom | |||
#endif // ANTKEEPER_GEOM_PRIMITIVE_INTERSECTION_HPP |
@ -0,0 +1,59 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GEOM_PRIMITIVE_LINE_SEGMENT_HPP | |||
#define ANTKEEPER_GEOM_PRIMITIVE_LINE_SEGMENT_HPP | |||
#include "math/vector.hpp" | |||
namespace geom { | |||
namespace primitive { | |||
/** | |||
* *n*-dimensional line segment. | |||
* | |||
* @tparam T Real type. | |||
* @tparam N Number of dimensions. | |||
*/ | |||
template <class T, std::size_t N> | |||
struct line_segment | |||
{ | |||
typedef math::vector<T, N> vector_type; | |||
/// First endpoint. | |||
vector_type a; | |||
/// Second endpoint. | |||
vector_type b; | |||
/** | |||
* Calculates the length of the line segment. | |||
* | |||
* @return Length of the line segment. | |||
*/ | |||
T length() const noexcept | |||
{ | |||
return math::distance(a, b); | |||
} | |||
}; | |||
} // namespace primitive | |||
} // namespace geom | |||
#endif // ANTKEEPER_GEOM_PRIMITIVE_LINE_SEGMENT_HPP |
@ -0,0 +1,35 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GEOM_PRIMITIVE_LINE_HPP | |||
#define ANTKEEPER_GEOM_PRIMITIVE_LINE_HPP | |||
#include "geom/primitive/hyperplane.hpp" | |||
namespace geom { | |||
namespace primitive { | |||
/// 2-dimensional hyperplane. | |||
template <class T> | |||
using line = hyperplane<T, 2>; | |||
} // namespace primitive | |||
} // namespace geom | |||
#endif // ANTKEEPER_GEOM_PRIMITIVE_LINE_HPP |
@ -0,0 +1,35 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GEOM_PRIMITIVE_PLANE_HPP | |||
#define ANTKEEPER_GEOM_PRIMITIVE_PLANE_HPP | |||
#include "geom/primitive/hyperplane.hpp" | |||
namespace geom { | |||
namespace primitive { | |||
/// 3-dimensional hyperplane. | |||
template <class T> | |||
using plane = hyperplane<T, 3>; | |||
} // namespace primitive | |||
} // namespace geom | |||
#endif // ANTKEEPER_GEOM_PRIMITIVE_PLANE_HPP |
@ -0,0 +1,61 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GEOM_PRIMITIVE_RAY_HPP | |||
#define ANTKEEPER_GEOM_PRIMITIVE_RAY_HPP | |||
#include "math/vector.hpp" | |||
namespace geom { | |||
namespace primitive { | |||
/** | |||
* Half of a line proceeding from an initial point. | |||
* | |||
* @tparam T Real type. | |||
* @tparam N Number of dimensions. | |||
*/ | |||
template <class T, std::size_t N> | |||
struct ray | |||
{ | |||
typedef math::vector<T, N> vector_type; | |||
/// Ray origin position. | |||
vector_type origin; | |||
/// Ray direction vector. | |||
vector_type direction; | |||
/** | |||
* Extrapolates from the ray origin along the ray direction vector. | |||
* | |||
* @param distance Signed extrapolation distance. | |||
* | |||
* @return Extrapolated coordinates. | |||
*/ | |||
constexpr vector_type extrapolate(T distance) const noexcept | |||
{ | |||
return origin + direction * distance; | |||
} | |||
}; | |||
} // namespace primitive | |||
} // namespace geom | |||
#endif // ANTKEEPER_GEOM_PRIMITIVE_RAY_HPP |
@ -0,0 +1,35 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GEOM_PRIMITIVE_RECTANGLE_HPP | |||
#define ANTKEEPER_GEOM_PRIMITIVE_RECTANGLE_HPP | |||
#include "geom/primitive/hyperrectangle.hpp" | |||
namespace geom { | |||
namespace primitive { | |||
/// 2-dimensional hyperrectangle. | |||
template <class T> | |||
using rectangle = hyperrectangle<T, 2>; | |||
} // namespace primitive | |||
} // namespace geom | |||
#endif // ANTKEEPER_GEOM_PRIMITIVE_RECTANGLE_HPP |
@ -0,0 +1,35 @@ | |||
/* | |||
* Copyright (C) 2021 Christopher J. Howard | |||
* | |||
* This file is part of Antkeeper source code. | |||
* | |||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Antkeeper source code is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
#ifndef ANTKEEPER_GEOM_PRIMITIVE_SPHERE_HPP | |||
#define ANTKEEPER_GEOM_PRIMITIVE_SPHERE_HPP | |||
#include "geom/primitive/hypersphere.hpp" | |||
namespace geom { | |||
namespace primitive { | |||
/// 3-dimensional hypersphere. | |||
template <class T> | |||
using sphere = hypersphere<T, 3>; | |||
} // namespace primitive | |||
} // namespace geom | |||
#endif // ANTKEEPER_GEOM_PRIMITIVE_SPHERE_HPP |