Commits (45)
......@@ -17,7 +17,7 @@ PenaltyBreakString: 50
IndentWidth: 4
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortFunctionsOnASingleLine: Inline
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
#BraceBreakingStyle: ???
......@@ -32,7 +32,8 @@ IndentCaseLabels: false
# Spaces
DerivePointerAlignment: true
DerivePointerAlignment: false
PointerAlignment: Left
DerivePointerBinding: true
MaxEmptyLinesToKeep: 2
SpaceAfterControlStatementKeyword: true
......@@ -50,5 +51,6 @@ AccessModifierOffset: -4
# Comments
FixNamespaceComments: false
AlignTrailingComments: true
CommentPragmas: '!Api.*'
cmake_minimum_required(VERSION 3.8)
project(TypedGeometry)
option(TG_EXPORT_LITERALS "if true, spills tg::literals into the global namespace (i.e. 180_deg works out of the box)" ON)
# ===============================================
# Create target
......@@ -18,3 +20,7 @@ target_include_directories(typed-geometry PUBLIC "src")
if (CMAKE_CXX_STANDARD GREATER_EQUAL 17)
target_compile_definitions(typed-geometry PUBLIC TG_SUPPORT_CXX17)
endif()
if (TG_EXPORT_LITERALS)
target_compile_definitions(typed-geometry PUBLIC TG_EXPORT_LITERALS)
endif()
......@@ -90,7 +90,7 @@ auto p = uniform(rng, obj);
### C++ 17 Features
* deduction guides: `auto v = tg::vec(1, 2.5f, 3)`
* deduction guides: `auto v = tg::vec(1, 2.5f, 3)`, `auto p = tg::pos(v);`
* structured binding: `auto [x, y, z] = tg::vec3(...)`
## Dependencies
......
#pragma once
#include "../types/angle.hh"
#include "errors.hh"
namespace tg
{
template <class T>
constexpr T pi = static_cast<T>(3.14159265358979323846);
constexpr angle<T> tau = angle<T>::from_radians(static_cast<T>(6.28318530717958647693));
template <class T>
constexpr angle<T> pi = angle<T>::from_radians(static_cast<T>(3.14159265358979323846));
template <class T>
constexpr T nan = static_cast<T>(0.0 / 0.0);
template <class T>
constexpr T epsilon = type_error::unsupported_type<T>::value;
template <>
constexpr float epsilon<float> = 1.19209290E-07F; // FLT_EPSILON
template <>
constexpr double epsilon<double> = 2.2204460492503131e-16; // DBL_EPSILON
// TODO: proper min vs. lowest
// template <class T>
......
#pragma once
#include <typed-geometry/types/objects/hyperplane.hh>
#include <typed-geometry/detail/functions/dot.hh>
// Header for all constructors that depend on functions
namespace tg
{
template <int D, class ScalarT>
constexpr hyperplane<D, ScalarT>::hyperplane(vec_t n, pos_t p) : n(n), d(dot(p, n))
{
}
}
#pragma once
namespace tg
{
namespace type_error
{
template <class T>
struct unknown_scalar_type;
template <class Base, int Bits>
struct unsupported_scalar_type;
template <class T>
struct unknown_type;
template <class A, class B>
struct cannot_promote_types;
template <class T>
struct unsupported_type;
template <int D>
struct only_support_four_dimensions;
}
}
......@@ -24,7 +24,12 @@
#include "functions/outer_product.hh"
#include "functions/project.hh"
#include "functions/rasterize.hh"
#include "functions/rotation.hh"
#include "functions/scaling.hh"
#include "functions/submatrix.hh"
#include "functions/subvector.hh"
#include "functions/tangent.hh"
#include "functions/translation.hh"
#include "functions/uniform.hh"
#include "functions/volume.hh"
#include "functions/intersection.hh"
......@@ -36,4 +36,10 @@ pos<D, fractional_result<ScalarT>> centroid(segment<D, ScalarT> const& p)
{
return mix(p.a, p.b, fractional_result<ScalarT>(0.5));
}
template <int D, class ScalarT>
pos<D, ScalarT> centroid(sphere<D, ScalarT> const& p)
{
return p.center;
}
} // namespace tg
......@@ -3,8 +3,8 @@
#include <cmath>
#include "../../types/objects/box.hh"
#include "../../types/pos.hh"
#include "../../types/objects/triangle.hh"
#include "../../types/pos.hh"
// For a given primitive and a position, return whether the first contains the latter
......@@ -23,6 +23,11 @@ constexpr bool contains(pos<D, ScalarT> const& b, pos<D, ScalarT> const& o, Scal
return b == o;
}
template <class ScalarT>
constexpr bool contains(box<1, ScalarT> const& b, ScalarT const& o, ScalarT eps = ScalarT(0))
{
return b.min.x - eps <= o && o <= b.max.x + eps;
}
template <class ScalarT>
constexpr bool contains(box<1, ScalarT> const& b, pos<1, ScalarT> const& o, ScalarT eps = ScalarT(0))
{
......@@ -74,4 +79,33 @@ constexpr bool contains(triangle<2, ScalarT> const& t, pos<2, ScalarT> const& p,
return ((A0 >= -eps) == (A1 >= -eps)) && ((A1 >= -eps) == (A2 >= -eps));
}
template <class ScalarT>
constexpr bool contains(triangle<3, ScalarT> const& t, pos<3, ScalarT> const& p)
{
// TODO
// use eps?
// does this also work for triangles where vertices are not ordered cc? should it?
auto n = normal(t);
// checking whether point lies on right side of any edge
auto e = t.v1 - t.v0;
auto C = cross(e, p - t.v0);
if (dot(n, C) < 0)
return false;
e = t.v2 - t.v1;
C = cross(e, p - t.v1);
if (dot(n, C) < 0)
return false;
e = t.v0 - t.v2;
C = cross(e, p - t.v2);
if (dot(n, C) < 0)
return false;
// point always on left side
return true;
}
} // namespace tg
......@@ -30,7 +30,24 @@ constexpr array<ScalarT, 3> coordinates(triangle<2, ScalarT> const& t, pos<2, Sc
auto A2 = cross(pv0, pv1);
auto A_inv = ScalarT(1) / A;
return {A0 * A_inv, A1 * A_inv, A2 * A_inv};
return {{A0 * A_inv, A1 * A_inv, A2 * A_inv}};
}
template <class ScalarT>
constexpr array<ScalarT, 3> coordinates(triangle<3, ScalarT> const& t, pos<3, ScalarT> const& p)
{
auto pv0 = t.v0 - p;
auto pv1 = t.v1 - p;
auto pv2 = t.v2 - p;
auto n = cross(t.v1 - t.v0, t.v2 - t.v0);
auto A = length(n);
n /= A;
auto A0 = dot(cross(pv1, pv2), n);
auto A1 = dot(cross(pv2, pv0), n);
auto A2 = dot(cross(pv0, pv1), n);
auto A_inv = ScalarT(1) / A;
return {{A0 * A_inv, A1 * A_inv, A2 * A_inv}};
}
template <int D, class ScalarT>
......