Example #1
0
        public static bool AreClose(Rect rect1, Rect rect2)
        {
            if (rect1.IsEmpty)
            {
                return(rect2.IsEmpty);
            }

            return(!rect2.IsEmpty && DoubleUtils.AreClose(rect1.X, rect2.X) && (DoubleUtils.AreClose(rect1.Y, rect2.Y) && DoubleUtils.AreClose(rect1.Height, rect2.Height)) && DoubleUtils.AreClose(rect1.Width, rect2.Width));
        }
Example #2
0
 public static bool AreClose(Size size1, Size size2)
 {
     return(DoubleUtils.AreClose(size1.Width, size2.Width) && DoubleUtils.AreClose(size1.Height, size2.Height));
 }
Example #3
0
 public static bool AreClose(Vector vector1, Vector vector2)
 {
     return(DoubleUtils.AreClose(vector1.X, vector2.X) && DoubleUtils.AreClose(vector1.Y, vector2.Y));
 }
Example #4
0
 public static bool AreClose(Size a, Size b)
 {
     return(DoubleUtils.AreClose(a.Width, b.Width, XamlConstants.LayoutComparisonPrecision) &&
            DoubleUtils.AreClose(a.Height, b.Height, XamlConstants.LayoutComparisonPrecision));
 }
Example #5
0
 public static bool IsCloseTo(this double self, double value, int precision)
 {
     return(DoubleUtils.AreClose(self, value, precision));
 }
Example #6
0
 public static bool IsCloseTo(this double self, double value)
 {
     return(DoubleUtils.AreClose(self, value));
 }
Example #7
0
 public static bool AreClose(Point a, Point b)
 {
     return(DoubleUtils.AreClose(a.X, b.X, XamlConstants.LayoutComparisonPrecision) && DoubleUtils.AreClose(a.Y, b.Y, XamlConstants.LayoutComparisonPrecision));
 }
Example #8
0
        private static void FromString(string s, CultureInfo cultureInfo, out double value, out FlexLengthUnitType unit)
        {
            var normalized = s.Trim().ToLowerInvariant();

            unit = FlexLengthUnitType.Pixel;

            var strLen     = normalized.Length;
            var strLenUnit = 0;
            var unitFactor = 1.0;

            var i = 0;

            if (normalized == UnitStrings[i])
            {
                strLenUnit = UnitStrings[i].Length;
                unit       = (FlexLengthUnitType)i;
            }
            else
            {
                for (i = 1; i < UnitStrings.Length; ++i)
                {
                    if (normalized.EndsWith(UnitStrings[i], StringComparison.Ordinal) == false)
                    {
                        continue;
                    }

                    strLenUnit = UnitStrings[i].Length;
                    unit       = (FlexLengthUnitType)i;

                    break;
                }
            }

            if (i >= UnitStrings.Length)
            {
                for (i = 0; i < PixelUnitStrings.Length; ++i)
                {
                    if (normalized.EndsWith(PixelUnitStrings[i], StringComparison.Ordinal) == false)
                    {
                        continue;
                    }

                    strLenUnit = PixelUnitStrings[i].Length;
                    unitFactor = PixelUnitFactors[i];

                    break;
                }
            }

            if (strLen == strLenUnit && (unit == FlexLengthUnitType.Auto || unit == FlexLengthUnitType.Star))
            {
                value = 1;
            }
            else
            {
                Debug.Assert(unit == FlexLengthUnitType.Pixel || DoubleUtils.AreClose(unitFactor, 1.0));

                var valueString = normalized.Substring(0, strLen - strLenUnit);

                value = Convert.ToDouble(valueString, cultureInfo) * unitFactor;
            }
        }