forked from microsoft/react-native-windows
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Style): Adds percent style support
Fixes microsoft#1044
- Loading branch information
Showing
10 changed files
with
153 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 14 additions & 8 deletions
22
ReactWindows/ReactNative.Shared/UIManager/EpsilonEqualityComparer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
using System; | ||
using Facebook.Yoga; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace ReactNative.UIManager | ||
{ | ||
class EpsilonEqualityComparer : IEqualityComparer<float> | ||
class EpsilonEqualityComparer : IEqualityComparer<YogaValue> | ||
{ | ||
private const float Epsilon = .00001f; | ||
private const int Decimals = 4; | ||
|
||
public static EpsilonEqualityComparer Instance { get; } = new EpsilonEqualityComparer(); | ||
|
||
public bool Equals(float x, float y) | ||
public bool Equals(YogaValue x, YogaValue y) | ||
{ | ||
if (float.IsNaN(x) || float.IsNaN(y)) | ||
if (x.Unit != y.Unit) | ||
{ | ||
return float.IsNaN(x) && float.IsNaN(y); | ||
return false; | ||
} | ||
|
||
return Math.Abs(x - y) < Epsilon; | ||
if (float.IsNaN(x.Value) || float.IsNaN(y.Value)) | ||
{ | ||
return float.IsNaN(x.Value) && float.IsNaN(y.Value); | ||
} | ||
|
||
return Math.Abs(x.Value - y.Value) < Epsilon; | ||
} | ||
|
||
public int GetHashCode(float obj) | ||
public int GetHashCode(YogaValue obj) | ||
{ | ||
return Math.Round(obj, Decimals).GetHashCode(); | ||
return (Math.Round(obj.Value, Decimals).GetHashCode()*397) ^ (int) obj.Unit; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.