Skip to content

Commit

Permalink
Enable conditional compilation for double precision support (#205)
Browse files Browse the repository at this point in the history
Co-authored-by: notgiven688 <[email protected]>
Co-authored-by: Wulferis <[email protected]>
  • Loading branch information
3 people authored Nov 24, 2024
1 parent 7f9c23a commit 16d53b9
Show file tree
Hide file tree
Showing 68 changed files with 1,783 additions and 1,658 deletions.
52 changes: 30 additions & 22 deletions .github/workflows/jitter-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ on:
push:
branches: [ main ]
pull_request:
types: [opened, reopened, edited]

permissions:
id-token: write
contents: write
checks: write
actions: write

env:
CONFIGURATION: Release
TEST_RESULTS_DIR: ./TestResults

jobs:
build:
build-and-test:

runs-on: ubuntu-latest

Expand All @@ -22,23 +25,28 @@ jobs:
working-directory: ./src/JitterTests

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test -c Release --no-restore --test-adapter-path:. --logger "trx;LogFileName=test-results.trx"
#run: dotnet test -c Release --no-restore --test-adapter-path:. --logger:"junit;LogFilePath=test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose"

- name: TestReport
uses: dorny/test-reporter@v1
if: success() || failure() # run this step even if previous step failed
with:
name: JitterTests # Name of the check run which will be created
path: ./src/JitterTests/TestResults/test-results.trx # Path to test results
reporter: dotnet-trx # Format of test results
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --configuration ${{ env.CONFIGURATION }} --no-restore

- name: Run Tests
run: |
mkdir -p ${{ env.TEST_RESULTS_DIR }}
# Run Single Precision Tests
dotnet test --configuration ${{ env.CONFIGURATION }} --no-restore \
--test-adapter-path:. --logger "trx;LogFileName=single-precision.trx"
# Run Double Precision Tests
dotnet test --configuration ${{ env.CONFIGURATION }} -p:DefineConstants="USE_DOUBLE_PRECISION" --no-restore \
--test-adapter-path:. --logger "trx;LogFileName=double-precision.trx"
if: always()
114 changes: 57 additions & 57 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ on:
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NuGetDirectory: ${{ github.workspace}}/nuget
NuGetDirectory: ${{ github.workspace }}/nuget

defaults:
run:
shell: pwsh

jobs:

create_nuget:

runs-on: ubuntu-latest
Expand All @@ -33,103 +32,104 @@ jobs:
working-directory: ./src/Jitter2

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Get all history to allow automatic versioning using MinVer
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Get all history to allow automatic versioning using MinVer

# Install the .NET SDK indicated in the global.json file
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- run: dotnet add package MinVer
- name: Add MinVer and Reproducible Builds
run: |
dotnet add package MinVer
dotnet add package DotNet.ReproducibleBuilds
- run: dotnet add package DotNet.ReproducibleBuilds
# Pack single-precision version
- name: Pack Single Precision
run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}

# Create the NuGet package in the folder from the environment variable NuGetDirectory
- run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}
# Pack double-precision version
- name: Pack Double Precision
run: dotnet pack --configuration Release -p:DoublePrecision=true --output ${{ env.NuGetDirectory }}

# Publish the NuGet package as an artifact, so they can be used in the following jobs
- uses: actions/upload-artifact@v4
with:
name: nuget
if-no-files-found: error
retention-days: 7
path: ${{ env.NuGetDirectory }}/*
# Upload artifacts
- uses: actions/upload-artifact@v4
with:
name: nuget
if-no-files-found: error
retention-days: 7
path: ${{ env.NuGetDirectory }}/*

validate_nuget:
runs-on: ubuntu-latest

needs: [ create_nuget ]
runs-on: ubuntu-latest
needs: [create_nuget]
steps:
# Install the .NET SDK indicated in the global.json file
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v4
- name: Download NuGet Packages
uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}

- name: Install nuget validator
- name: Install NuGet Validator
run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global

# Validate metadata and content of the NuGet package
# https://www.nuget.org/packages/Meziantou.Framework.NuGetPackageValidation.Tool#readme-body-tab
# If some rules are not applicable, you can disable them
# using the --excluded-rules or --excluded-rule-ids option
- name: Validate package
run: meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg")
- name: Validate NuGet Packages
run: |
foreach ($file in Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg) {
meziantou.validate-nuget-package $file
}
run_test:

runs-on: ubuntu-latest

defaults:
run:
working-directory: ./src/Jitter2

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Run Tests - Single Precision
run: dotnet test --configuration Release

- name: Run tests
run: dotnet test --configuration Release
- name: Run Tests - Double Precision
run: dotnet test --configuration Release -p:DoublePrecision=true

deploy:
# Publish only when creating a GitHub Release
# https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
# You can update this logic if you want to manage releases differently

if: github.event_name == 'release'
runs-on: ubuntu-latest
needs: [ validate_nuget, run_test ]
needs: [validate_nuget, run_test]
steps:
# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}

# Install the .NET SDK indicated in the global.json file
- name: Setup .NET Core
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

# Publish all NuGet packages to NuGet.org
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
# If you retry a failed workflow, already published packages will be skipped without error.
- name: Publish NuGet package
- name: Download NuGet Packages
uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}

- name: Publish NuGet Packages
run: |
dotnet nuget add source --username notgiven688 --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/notgiven688/index.json"
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
foreach ($file in Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg) {
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push $file --source "github" --skip-duplicate
}
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
.vs
imgui.ini
[Bb]in/
[Oo]bj/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ public interface INarrowPhaseFilter
/// <returns>False if the collision should be filtered out, true otherwise.</returns>
bool Filter(RigidBodyShape shapeA, RigidBodyShape shapeB,
ref JVector pointA, ref JVector pointB,
ref JVector normal, ref float penetration);
ref JVector normal, ref Real penetration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,28 @@ public class TriangleEdgeCollisionFilter : INarrowPhaseFilter
/// A tweakable parameter. Collision points that are closer than this value to a triangle edge
/// are considered as edge collisions and might be modified or discarded entirely.
/// </summary>
public float EdgeThreshold { get; set; } = 0.05f;
public Real EdgeThreshold { get; set; } = (Real)0.05;

private float cosAT = 0.99f;
private Real cosAT = (Real)0.99;

/// <summary>
/// A tweakable parameter.
/// </summary>
public float ProjectionThreshold { get; set; } = 0.5f;
public Real ProjectionThreshold { get; set; } = (Real)0.5;

/// <summary>
/// A tweakable parameter that defines the threshold to determine when two normals
/// are considered identical.
/// </summary>
public JAngle AngleThreshold
{
get => JAngle.FromRadiant(MathF.Acos(cosAT));
set => cosAT = MathF.Cos(value.Radiant);
get => JAngle.FromRadiant(MathR.Acos(cosAT));
set => cosAT = MathR.Cos(value.Radiant);
}

/// <inheritdoc />
public bool Filter(RigidBodyShape shapeA, RigidBodyShape shapeB,
ref JVector pointA, ref JVector pointB, ref JVector normal, ref float penetration)
ref JVector pointA, ref JVector pointB, ref JVector normal, ref Real penetration)
{
TriangleShape? ts1 = shapeA as TriangleShape;
TriangleShape? ts2 = shapeB as TriangleShape;
Expand Down Expand Up @@ -100,22 +100,22 @@ public bool Filter(RigidBodyShape shapeA, RigidBodyShape shapeB,
tshape.GetWorldVertices(out JVector a, out JVector b, out JVector c);

JVector n, pma;
float d0, d1, d2;
Real d0, d1, d2;

// TODO: this can be optimized
n = b - a;
pma = collP - a;
d0 = (pma - JVector.Dot(pma, n) * n * (1.0f / n.LengthSquared())).LengthSquared();
d0 = (pma - JVector.Dot(pma, n) * n * ((Real)1.0 / n.LengthSquared())).LengthSquared();

n = c - a;
pma = collP - a;
d1 = (pma - JVector.Dot(pma, n) * n * (1.0f / n.LengthSquared())).LengthSquared();
d1 = (pma - JVector.Dot(pma, n) * n * ((Real)1.0 / n.LengthSquared())).LengthSquared();

n = c - b;
pma = collP - b;
d2 = (pma - JVector.Dot(pma, n) * n * (1.0f / n.LengthSquared())).LengthSquared();
d2 = (pma - JVector.Dot(pma, n) * n * ((Real)1.0 / n.LengthSquared())).LengthSquared();

if (MathF.Min(MathF.Min(d0, d1), d2) > EdgeThreshold) return true;
if (MathR.Min(MathR.Min(d0, d1), d2) > EdgeThreshold) return true;

JVector nnormal;

Expand Down Expand Up @@ -153,8 +153,8 @@ public bool Filter(RigidBodyShape shapeA, RigidBodyShape shapeB,
{
// tnormal and nnormal are the same
// --------------------------------
float f5 = JVector.Dot(normal, nnormal);
float f6 = JVector.Dot(normal, tnormal);
Real f5 = JVector.Dot(normal, nnormal);
Real f6 = JVector.Dot(normal, tnormal);

if (f5 > f6)
{
Expand Down Expand Up @@ -211,16 +211,16 @@ public bool Filter(RigidBodyShape shapeA, RigidBodyShape shapeB,
// \
// \
// \ tnormal
float f1 = proj % nnormal * cross;
float f2 = proj % tnormal * cross;
Real f1 = proj % nnormal * cross;
Real f2 = proj % tnormal * cross;

bool between = f1 * f2 <= 0.0f;
bool between = f1 * f2 <= (Real)0.0;

if (!between)
{
// not in-between, snap normal
float f3 = JVector.Dot(normal, nnormal);
float f4 = JVector.Dot(normal, tnormal);
Real f3 = JVector.Dot(normal, nnormal);
Real f4 = JVector.Dot(normal, tnormal);

if (f3 > f4)
{
Expand Down
Loading

0 comments on commit 16d53b9

Please sign in to comment.