Utils.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the LICENSE
  5. * file in the root directory of this source tree.
  6. */
  7. #include "Utils.h"
  8. using namespace facebook;
  9. YGFlexDirection YGFlexDirectionCross(
  10. const YGFlexDirection flexDirection,
  11. const YGDirection direction) {
  12. return YGFlexDirectionIsColumn(flexDirection)
  13. ? YGResolveFlexDirection(YGFlexDirectionRow, direction)
  14. : YGFlexDirectionColumn;
  15. }
  16. float YGFloatMax(const float a, const float b) {
  17. if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
  18. return fmaxf(a, b);
  19. }
  20. return yoga::isUndefined(a) ? b : a;
  21. }
  22. float YGFloatMin(const float a, const float b) {
  23. if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
  24. return fminf(a, b);
  25. }
  26. return yoga::isUndefined(a) ? b : a;
  27. }
  28. bool YGValueEqual(const YGValue& a, const YGValue& b) {
  29. if (a.unit != b.unit) {
  30. return false;
  31. }
  32. if (a.unit == YGUnitUndefined ||
  33. (yoga::isUndefined(a.value) && yoga::isUndefined(b.value))) {
  34. return true;
  35. }
  36. return fabs(a.value - b.value) < 0.0001f;
  37. }
  38. bool YGFloatsEqual(const float a, const float b) {
  39. if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) {
  40. return fabs(a - b) < 0.0001f;
  41. }
  42. return yoga::isUndefined(a) && yoga::isUndefined(b);
  43. }
  44. float YGFloatSanitize(const float val) {
  45. return yoga::isUndefined(val) ? 0 : val;
  46. }
  47. YGFloatOptional YGFloatOptionalMax(YGFloatOptional op1, YGFloatOptional op2) {
  48. if (op1 >= op2) {
  49. return op1;
  50. }
  51. if (op2 > op1) {
  52. return op2;
  53. }
  54. return op1.isUndefined() ? op2 : op1;
  55. }