Skip to content

Commit

Permalink
Merge pull request ExtendRealityLtd#793 from bddckr/fix-ControllerEve…
Browse files Browse the repository at this point in the history
…nts-garbage

perf(ControllerEvents): don't create garbage on vector comparison
  • Loading branch information
thestonefox authored Jan 7, 2017
2 parents d49cebf + a491404 commit f8d0ec9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Assets/VRTK/Scripts/Interactions/VRTK_ControllerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace VRTK
{
using UnityEngine;
using System;

/// <summary>
/// Event Payload
Expand Down Expand Up @@ -1065,8 +1066,9 @@ private void EmitAlias(ButtonAlias type, bool touchDown, float buttonPressure, r

private bool Vector2ShallowEquals(Vector2 vectorA, Vector2 vectorB)
{
return (vectorA.x.ToString("F" + axisFidelity) == vectorB.x.ToString("F" + axisFidelity) &&
vectorA.y.ToString("F" + axisFidelity) == vectorB.y.ToString("F" + axisFidelity));
var distanceVector = vectorA - vectorB;
return Math.Round(Mathf.Abs(distanceVector.x), axisFidelity, MidpointRounding.AwayFromZero) < float.Epsilon
&& Math.Round(Mathf.Abs(distanceVector.y), axisFidelity, MidpointRounding.AwayFromZero) < float.Epsilon;
}

private void DisableEvents()
Expand Down

0 comments on commit f8d0ec9

Please sign in to comment.