Skip to content

Commit

Permalink
Tree SweepBuilder will now try to output more balanced outputs for pa…
Browse files Browse the repository at this point in the history
…thological inputs.
  • Loading branch information
RossNordby committed Jul 7, 2020
1 parent 5f9479b commit e7f092c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion BepuPhysics/BepuPhysics.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.3.0-beta0</Version>
<Version>2.3.0-beta1</Version>
<Company>Bepu Entertainment LLC</Company>
<Authors>Ross Nordby</Authors>
<Description>Speedy real time physics simulation library.</Description>
Expand Down
11 changes: 9 additions & 2 deletions BepuPhysics/Trees/Tree_SweepBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,15 @@ unsafe void FindPartitionForAxis(BoundingBox* boundingBoxes, BoundingBox* aMerge
var subtreeIndex = indexMap[i];
BoundingBox.CreateMerged(bMerged, boundingBoxes[subtreeIndex], out bMerged);

var aCost = i * ComputeBoundsMetric(ref aMerged[aIndex]);
var bCost = (count - i) * ComputeBoundsMetric(ref bMerged);
//Note the modifications to the cost function compare to raw SAH.
//First, we include a very mildly quadratic term for the counts so that skewed distributions are penalized.
//This penalty is weak enough that it should effectively never come into play except in pathological cases, like all bounding boxes overlapping.
//Second, we include an extremely small (the smallest normal floating point number) baseline to the evaluated bounds metric.
//This ensures that even a set of perfectly overlapping zero bounds will use a midpoint split rather than a skewed split.
const float normalEpsilon = 1.1754943508e-38f;
var aCost = i * (1f + i * 0.001f) * (normalEpsilon + ComputeBoundsMetric(ref aMerged[aIndex]));
var bCount = count - i;
var bCost = bCount * (1f + bCount * 0.001f) * (normalEpsilon + ComputeBoundsMetric(ref bMerged));

var totalCost = aCost + bCost;
if (totalCost < cost)
Expand Down
2 changes: 1 addition & 1 deletion BepuUtilities/BepuUtilities.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<AssemblyName>BepuUtilities</AssemblyName>
<RootNamespace>BepuUtilities</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.3.0-beta0</Version>
<Version>2.3.0-beta1</Version>
<Company>Bepu Entertainment LLC</Company>
<Authors>Ross Nordby</Authors>
<Description>Supporting utilities library for BEPUphysics v2.</Description>
Expand Down

0 comments on commit e7f092c

Please sign in to comment.