Skip to content

intersection methods #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7e42258
working on color types
Philip-Trettner Jun 20, 2021
bcd8baa
complemented implementation report and added intersection(segment3, s…
aaronkreuz Jun 1, 2022
c04d8e5
Merge branch 'develop' into upstream_develop
aaronkreuz Jun 1, 2022
13d2286
added intersection(segment3, hemisphere3) and tests for intersection(…
aaronkreuz Jun 3, 2022
86d4535
added test for intersection(segment3, hemisphere3) and fixed bugs in …
aaronkreuz Jun 14, 2022
ebe6d0b
Merge branch 'develop' of https://github.com/project-arcana/typed-geo…
aaronkreuz Jun 14, 2022
aa60901
Merge branch 'develop' into upstream_develop
aaronkreuz Jun 14, 2022
9a54ed4
adapted test for intersection(segment3, hemisphere3)
aaronkreuz Jun 15, 2022
44942ae
added intersection(sphere3,plane3) and intersection(segment3, tube3) …
aaronkreuz Jun 21, 2022
3d21d23
added intersection(plane3, tube3) -> ellipse, incl. test cases
aaronkreuz Jun 22, 2022
1ebc38e
intersection(plane3-inf_cylinder3) incl. test
aaronkreuz Jun 28, 2022
9fcf79f
added intersection(sphere2in3, plane3)
aaronkreuz Jul 4, 2022
c594703
added test for intersection(disk3, plane3)
aaronkreuz Jul 5, 2022
b65f8d0
fixed some minor bugs
aaronkreuz Jul 5, 2022
8a796c2
fixed template errors
aaronkreuz Jul 5, 2022
0578b4a
added few more intersection(segment3, boundary_obj) cases, optimized …
aaronkreuz Jul 6, 2022
a0f8a07
impl-report condition
aaronkreuz Jul 12, 2022
41b057f
Merge branch 'develop' of https://github.com/project-arcana/typed-geo…
aaronkreuz Sep 5, 2022
c05d6e1
code review, optimization, variable renaming
aaronkreuz Oct 12, 2022
dfff17e
Merge remote-tracking branch 'origin/develop' into feature/colors
Philip-Trettner Oct 23, 2022
abaaa14
initial color work
Philip-Trettner Oct 23, 2022
07bd40b
many more color functions
Philip-Trettner Nov 1, 2022
01b1e97
different umul for windows
Philip-Trettner Nov 11, 2022
d20b775
SFINAE for tg::to_string
Philip-Trettner Nov 21, 2022
10b8dd5
implemented faster triangle-triangle intersection method (devillers a…
aaronkreuz Dec 7, 2022
b72d51c
tri_tri fixes
aaronkreuz Dec 16, 2022
4c788d8
fixed tri_tri insec devillers
aaronkreuz Dec 22, 2022
c99c441
devillers intersection fixed and optimized
aaronkreuz Jan 11, 2023
9635e3b
Merge branch 'develop' into upstream_develop
aaronkreuz Jan 11, 2023
f383e78
fixed intersects(triangle3, triangle3) projection on plane in coplana…
aaronkreuz Jan 24, 2023
ce56943
fixed coplanar (2D) triangle-triangle intersects and added test
aaronkreuz Jan 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ target_link_libraries(typed-geometry PUBLIC
if (TG_EXPORT_LITERALS)
target_compile_definitions(typed-geometry PUBLIC TG_EXPORT_LITERALS)
endif()

if(TG_IMPLEMENTATION_REPORT)
target_compile_definitions(typed-geometry PUBLIC TG_IMPLEMENTATION_REPORT)
endif()
23 changes: 23 additions & 0 deletions src/typed-geometry/detail/color-literals.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <clean-core/string_view.hh>

#include <typed-geometry/types/color.hh>
#include <typed-geometry/types/srgb.hh>

#include <typed-geometry/functions/color/string-conversions.hh>

namespace tg
{
namespace literals
{
constexpr srgb8 operator""_srgb8(char const* str, size_t s) { return srgb8::from_hex_string({str, s}); }
constexpr srgba8 operator""_srgba8(char const* str, size_t s) { return srgba8::from_hex_string({str, s}); }
constexpr color3 operator""_color3(char const* str, size_t s) { return color3::from_hex_string({str, s}); }
constexpr color4 operator""_color4(char const* str, size_t s) { return color4::from_hex_string({str, s}); }
} // namespace literals
} // namespace tg

#ifdef TG_EXPORT_LITERALS
using namespace tg::literals;
#endif
111 changes: 111 additions & 0 deletions src/typed-geometry/detail/color_traits.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#pragma once

#include <clean-core/macros.hh>

#include <typed-geometry/detail/scalar_traits.hh>
#include <typed-geometry/detail/utility.hh>
#include <typed-geometry/types/fwd.hh>
#include <typed-geometry/types/scalars/default.hh>

namespace tg
{
enum class alpha_type
{
/// no alpha in the type, e.g. (R, G, B)
none,

/// extra alpha component, e.g. (R, G, B, A)
straight,

/// premultiplied alpha, e.g. (aR, aG, aB, a)
premultiplied
};

template <class T>
struct color_traits
{
static constexpr bool is_color = false;
};

/// checks if a type is a color
/// e.g. is_color<tg::color4> == true
/// but is_color<tg::vec3> == false
template <class T>
static constexpr bool is_color = color_traits<T>::is_color;

template <class T>
static constexpr bool has_alpha = color_traits<T>::alpha != alpha_type::none;
template <class T>
static constexpr bool has_straight_alpha = color_traits<T>::alpha == alpha_type::straight;
template <class T>
static constexpr bool has_premultiplied_alpha = color_traits<T>::alpha == alpha_type::premultiplied;

template <class T>
using linear_color_t_of = typename color_traits<T>::linear_color_t;

namespace detail
{
template <class ScalarT>
struct color_scalar
{
static_assert(always_false<ScalarT>, "this scalar type is not cleared for use with colors");
};

template <>
struct color_scalar<f32>
{
static constexpr f32 to_float(f32 v) { return v; }
static constexpr f32 from_float(f32 v) { return v; }

static constexpr f32 one() { return 1.f; }
};
template <>
struct color_scalar<u8>
{
static constexpr f32 to_float(u8 v) { return v / 255.f; }
static constexpr u8 from_float(f32 v)
{
v *= 256;
return u8(v < 0 ? 0 : v > 255 ? 255 : int(v));
}

static constexpr u8 one() { return 255; }
};
}

/// converts a float value to the appropriate value for storing it as a certain color scalar type
/// e.g. if ScalarT is u8, we store 255 * v
template <class ScalarT>
constexpr ScalarT color_scalar_from_float(float v)
{
return detail::color_scalar<ScalarT>::from_float(v);
}
/// converts a color storage type back to float [0..1]
template <class ScalarT>
constexpr float color_scalar_to_float(ScalarT v)
{
return detail::color_scalar<ScalarT>::to_float(v);
}

namespace detail
{
/// helper for implementing color traits
/// NOTE: D is WITH alpha!
template <int D, class ScalarT, alpha_type Alpha>
struct base_color_traits
{
using scalar_t = ScalarT;

/// the linear RGB type appropriate for this color
/// is usually color3 or color4 (if alpha)
/// (or double versions for larger types)
using linear_color_t = std::conditional_t<Alpha == alpha_type::none, //
color<3, fractional_result<ScalarT>>,
color<4, fractional_result<ScalarT>>>;

static constexpr alpha_type alpha = Alpha;
static constexpr bool is_color = true;
static constexpr int comps = D;
};
}
}
Loading