2016-09-22 16:22:34 -07:00
|
|
|
|
/**
|
2018-09-11 15:27:47 -07:00
|
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-09-22 16:22:34 -07:00
|
|
|
|
*
|
2018-02-16 18:24:55 -08:00
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-09-22 16:22:34 -07:00
|
|
|
|
*/
|
|
|
|
|
|
2016-12-02 11:18:16 -08:00
|
|
|
|
namespace Facebook.Yoga
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public static class YogaConstants
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2018-10-09 17:25:23 -07:00
|
|
|
|
/**
|
|
|
|
|
* Large positive number signifies that the property(float) is undefined. Earlier we used to have
|
|
|
|
|
* YGundefined as NAN, but the downside of this is that we can't use -ffast-math compiler flag as
|
|
|
|
|
* it assumes all floating-point calculation involve and result into finite numbers. For more
|
|
|
|
|
* information regarding -ffast-math compiler flag in clang, have a look at
|
|
|
|
|
* https://clang.llvm.org/docs/UsersManual.html#cmdoption-ffast-math
|
|
|
|
|
*/
|
|
|
|
|
public const float Undefined = 10E20F;
|
2016-09-22 16:22:34 -07:00
|
|
|
|
|
|
|
|
|
public static bool IsUndefined(float value)
|
|
|
|
|
{
|
2018-10-09 17:25:23 -07:00
|
|
|
|
// Value of a float in the case of it being not defined is 10.1E20. Earlier it used to be NAN,
|
|
|
|
|
// the benefit of which
|
|
|
|
|
// was that if NAN is involved in any mathematical expression the result was NAN. But since we
|
|
|
|
|
// want to have `-ffast-math`
|
|
|
|
|
// flag being used by compiler which assumes that the floating point values are not NAN and Inf,
|
|
|
|
|
// we represent YGUndefined as 10.1E20.
|
|
|
|
|
// But now if YGUndefined is involved in any mathematical operations this value(10.1E20) would
|
|
|
|
|
// change.
|
|
|
|
|
// So the following check makes sure that if the value is outside a range (-10E8, 10E8) then it
|
|
|
|
|
// is undefined.
|
|
|
|
|
return value >= 10E8F || value <= -10E8;
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
Add feature to use percentage as value unit
Summary:
Adds the feature to use percentage as a value unit.
You can use the function ```YGPx(float)``` and ```YGPercent(float)``` for convenience.
I did some benchmarks:
```
Without Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.146683 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.490101 ms
Huge nested layout: median: 23.000000 ms, stddev: 0.928291 ms
Stack with flex: median: 0.000000 ms, stddev: 0.170587 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.143384 ms
Nested flex: median: 0.000000 ms, stddev: 0.477791 ms
Huge nested layout: median: 22.000000 ms, stddev: 2.129779 ms
With Percentage Feature - Release x86:
Stack with flex: median: 0.000000 ms, stddev: 0.132951 ms
Align stretch in undefined axis: median: 0.000000 ms, stddev: 0.136525 ms
Nested flex: median: 0.000000 ms, stddev: 0.489570 ms
Huge nested layout: median: 21.000000 ms, stddev: 1.390476 ms
Closes https://github.com/facebook/yoga/pull/258
Reviewed By: dshahidehpour
Differential Revision: D4361945
Pulled By: emilsjolander
fbshipit-source-id: a8f5bc63ad352eb9410d792729e56664468cd76a
2017-01-02 05:20:37 -08:00
|
|
|
|
|
|
|
|
|
public static bool IsUndefined(YogaValue value)
|
|
|
|
|
{
|
|
|
|
|
return value.Unit == YogaUnit.Undefined;
|
|
|
|
|
}
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|