Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Philip Trettner
typed-geometry
Commits
502b9b36
Commit
502b9b36
authored
Feb 06, 2021
by
Aaron Grabowy
Browse files
Added intersects aabb for box2in3 (+boundary); Fixed edges_of(box2in3)
parent
b58c4385
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/typed-geometry/functions/objects/edges.hh
View file @
502b9b36
...
...
@@ -60,14 +60,14 @@ template <class ScalarT, class TraitsT>
}
template
<
class
ScalarT
,
int
DomainD
,
class
TraitsT
>
[[
nodiscard
]]
constexpr
array
<
segment
<
2
,
ScalarT
>
,
4
>
edges_of
(
box
<
2
,
ScalarT
,
DomainD
,
TraitsT
>
const
&
b
)
[[
nodiscard
]]
constexpr
array
<
segment
<
DomainD
,
ScalarT
>
,
4
>
edges_of
(
box
<
2
,
ScalarT
,
DomainD
,
TraitsT
>
const
&
b
)
{
const
auto
vs
=
vertices_of
(
b
);
return
{{{
vs
[
0
],
vs
[
1
]},
{
vs
[
1
],
vs
[
2
]},
{
vs
[
2
],
vs
[
3
]},
{
vs
[
3
],
vs
[
0
]}}};
}
template
<
class
ScalarT
,
int
DomainD
,
class
TraitsT
>
[[
nodiscard
]]
constexpr
array
<
segment
<
3
,
ScalarT
>
,
12
>
edges_of
(
box
<
3
,
ScalarT
,
DomainD
,
TraitsT
>
const
&
b
)
[[
nodiscard
]]
constexpr
array
<
segment
<
DomainD
,
ScalarT
>
,
12
>
edges_of
(
box
<
3
,
ScalarT
,
DomainD
,
TraitsT
>
const
&
b
)
{
const
auto
vs
=
vertices_of
(
b
);
return
{{
...
...
src/typed-geometry/functions/objects/intersection.hh
View file @
502b9b36
...
...
@@ -187,6 +187,11 @@ template <class Obj, class... Objs>
{
return
(
intersects
(
obj
,
objs
)
||
...);
}
template
<
class
Obj
,
class
ObjT
,
u64
N
,
size_t
...
I
>
[[
nodiscard
]]
constexpr
bool
intersects_any_array
(
Obj
const
&
obj
,
array
<
ObjT
,
N
>
objs
,
std
::
index_sequence
<
I
...
>
)
{
return
intersects_any
(
obj
,
objs
[
I
]...);
}
// Solves the quadratic equation ax^2 + bx + c = 0
template
<
class
ScalarT
>
...
...
@@ -1174,10 +1179,10 @@ template <int D, class ScalarT>
auto
const
e
=
dot
(
b
.
max
-
center
,
abs
(
axis
));
return
{
c
-
e
,
c
+
e
};
}
template
<
int
D
,
class
ScalarT
>
[[
nodiscard
]]
constexpr
hit_interval
<
ScalarT
>
shadow
(
box
<
D
,
ScalarT
>
const
&
b
,
vec
<
D
,
ScalarT
>
const
&
axis
)
template
<
int
Object
D
,
class
ScalarT
,
int
DomainD
>
[[
nodiscard
]]
constexpr
hit_interval
<
ScalarT
>
shadow
(
box
<
Object
D
,
ScalarT
,
DomainD
>
const
&
b
,
vec
<
D
omainD
,
ScalarT
>
const
&
axis
)
{
auto
const
e
=
dot
(
abs
(
b
.
half_extents
*
vec
<
D
,
ScalarT
>::
one
),
abs
(
axis
));
auto
const
e
=
dot
(
abs
(
b
.
half_extents
*
vec
<
Object
D
,
ScalarT
>::
one
),
abs
(
axis
));
auto
const
c
=
dot
(
b
.
center
,
axis
);
return
{
c
-
e
,
c
+
e
};
}
...
...
@@ -1268,22 +1273,32 @@ template <int D, class ScalarT>
return
!
contained
;
}
template
<
int
D
,
class
ScalarT
>
[[
nodiscard
]]
constexpr
bool
intersects
(
box
<
D
,
ScalarT
>
const
&
box
,
aabb
<
D
,
ScalarT
>
const
&
b
)
template
<
int
Object
D
,
class
ScalarT
,
int
DomainD
>
[[
nodiscard
]]
constexpr
bool
intersects
(
box
<
Object
D
,
ScalarT
,
DomainD
>
const
&
box
,
aabb
<
D
omainD
,
ScalarT
>
const
&
b
)
{
using
vec_t
=
vec
<
D
,
ScalarT
>
;
using
vec_t
=
vec
<
D
omainD
,
ScalarT
>
;
auto
axes
=
std
::
vector
<
vec_t
>
();
for
(
auto
i
=
0
;
i
<
D
;
++
i
)
for
(
auto
i
=
0
;
i
<
Domain
D
;
++
i
)
{
auto
d
=
vec_t
::
zero
;
d
[
i
]
=
ScalarT
(
1
);
axes
.
push_back
(
d
);
if
constexpr
(
D
>
1
)
axes
.
push_back
(
box
.
half_extents
[
i
]);
if
constexpr
(
D
>
2
)
if
constexpr
(
DomainD
>
1
)
{
if
constexpr
(
ObjectD
==
2
&&
DomainD
==
3
)
{
if
(
i
==
2
)
// box2in3
axes
.
push_back
(
normal_of
(
box
));
else
axes
.
push_back
(
box
.
half_extents
[
i
]);
}
else
axes
.
push_back
(
box
.
half_extents
[
i
]);
}
if
constexpr
(
DomainD
>
2
)
axes
.
push_back
(
cross
(
axes
[
axes
.
size
()
-
2
],
axes
[
axes
.
size
()
-
1
]));
static_assert
(
D
<
4
&&
"Not implemented for 4D"
);
static_assert
(
D
omainD
<
4
&&
"Not implemented for 4D"
);
}
return
detail
::
intersects_SAT
(
box
,
b
,
axes
);
...
...
@@ -1306,6 +1321,11 @@ template <int D, class ScalarT>
return
intersects
(
solidBox
,
b
);
}
template
<
class
ScalarT
>
[[
nodiscard
]]
constexpr
bool
intersects
(
box_boundary
<
2
,
ScalarT
,
3
>
const
&
box
,
aabb
<
3
,
ScalarT
>
const
&
b
)
{
return
detail
::
intersects_any_array
(
b
,
edges_of
(
box
),
std
::
make_index_sequence
<
4
>
{});
}
template
<
int
D
,
class
ScalarT
>
[[
nodiscard
]]
constexpr
bool
intersects
(
sphere
<
D
,
ScalarT
>
const
&
a
,
aabb
<
D
,
ScalarT
>
const
&
b
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment