-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathProjectedTriangleSweepBenchmarks.cs
More file actions
101 lines (93 loc) · 3.08 KB
/
Copy pathProjectedTriangleSweepBenchmarks.cs
File metadata and controls
101 lines (93 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using BenchmarkDotNet.Attributes;
using FixedMathSharp.Geometry;
namespace FixedMathSharp.Benchmarks;
[MemoryDiagnoser]
public class ProjectedTriangleSweepBenchmarks
{
private FixedTriangle _triangle;
private Vector3d _ordinaryOrigin;
private Vector2d _ordinaryCircleStart;
private Vector3d _scalarFaceOrigin;
private Vector2d _scalarFaceCircleStart;
private Vector3d _contactSlabCenter;
[GlobalSetup]
public void Setup()
{
_triangle = new FixedTriangle(
new Vector3d(Fixed64.Zero, Fixed64.Zero, -Fixed64.One),
new Vector3d(Fixed64.Zero, Fixed64.Zero, Fixed64.One),
new Vector3d(Fixed64.Two, Fixed64.Zero, Fixed64.Zero));
_ordinaryOrigin = Vector3d.Zero;
_ordinaryCircleStart = new Vector2d((Fixed64)(-2), Fixed64.Zero);
_scalarFaceOrigin =
new Vector3d(Fixed64.MaxValue, Fixed64.Zero, Fixed64.Zero);
_scalarFaceCircleStart = new Vector2d(
Fixed64.MaxValue - Fixed64.Two,
Fixed64.Zero);
_contactSlabCenter =
new Vector3d(Fixed64.Half, Fixed64.Zero, Fixed64.Zero);
if (OrdinaryProjectedTriangleSweep() != Fixed64.FromFraction(3, 2)
|| ScalarFaceProjectedTriangleSweep()
!= Fixed64.FromFraction(3, 2)
|| !TriangleCircleSlabContact()
|| !TriangleCapsuleSlabContact())
{
throw new System.InvalidOperationException(
"Projected-triangle benchmark scenarios must intersect.");
}
}
[Benchmark(Baseline = true)]
public Fixed64 OrdinaryProjectedTriangleSweep()
{
_ = _triangle.TryGetFiniteSlabProjectedCircleSweep(
_ordinaryOrigin,
FixedQuaternion.Identity,
_ordinaryCircleStart,
Vector2d.Right,
(Fixed64)4,
Fixed64.Half,
Fixed64.Zero,
Fixed64.Zero,
out Fixed64 distance,
out _);
return distance;
}
[Benchmark]
public Fixed64 ScalarFaceProjectedTriangleSweep()
{
_ = _triangle.TryGetFiniteSlabProjectedCircleSweep(
_scalarFaceOrigin,
FixedQuaternion.Identity,
_scalarFaceCircleStart,
Vector2d.Right,
(Fixed64)4,
Fixed64.Half,
Fixed64.Zero,
Fixed64.Zero,
out Fixed64 distance,
out _);
return distance;
}
[Benchmark]
public bool TriangleCircleSlabContact() =>
_triangle.TryGetCircleSlabContact(
_ordinaryOrigin,
FixedQuaternion.Identity,
_contactSlabCenter,
Fixed64.Zero,
Fixed64.One,
Fixed64.One,
out _);
[Benchmark]
public bool TriangleCapsuleSlabContact() =>
_triangle.TryGetCenteredCapsuleSlabContact(
_ordinaryOrigin,
FixedQuaternion.Identity,
_contactSlabCenter,
Fixed64.Zero,
Vector2d.Forward,
Fixed64.Two,
Fixed64.One,
Fixed64.One,
out _);
}