Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flip geometry types from double to float, per community feedback #258

Merged
merged 1 commit into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions UnitTest/TestComponentCSharp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ public void TestAsyncOperationWithProgress()
[Fact]
public void TestPointTypeMapping()
{
var pt = new Point { X = 3.14, Y = 42 };
var pt = new Point { X = 3.14F, Y = 42 };
TestObject.PointProperty = pt;
Assert.Equal(pt.X, TestObject.PointProperty.X);
Assert.Equal(pt.Y, TestObject.PointProperty.Y);
Expand All @@ -1061,7 +1061,7 @@ public void TestPointTypeMapping()
[Fact]
public void TestRectTypeMapping()
{
var rect = new Rect { X = 3.14, Y = 42, Height = 3.14, Width = 42 };
var rect = new Rect { X = 3.14F, Y = 42, Height = 3.14F, Width = 42 };
TestObject.RectProperty = rect;
Assert.Equal(rect.X, TestObject.RectProperty.X);
Assert.Equal(rect.Y, TestObject.RectProperty.Y);
Expand All @@ -1073,7 +1073,7 @@ public void TestRectTypeMapping()
[Fact]
public void TestSizeTypeMapping()
{
var size = new Size { Height = 3.14, Width = 42 };
var size = new Size { Height = 3.14F, Width = 42 };
TestObject.SizeProperty = size;
Assert.Equal(size.Height, TestObject.SizeProperty.Height);
Assert.Equal(size.Width, TestObject.SizeProperty.Width);
Expand Down
128 changes: 64 additions & 64 deletions cswinrt/strings/additions/Windows.Foundation/Windows.Foundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ public struct Point : IFormattable
float _x;
float _y;

public Point(double x, double y)
public Point(float x, float y)
{
_x = (float)x;
_y = (float)y;
_x = x;
_y = y;
}

public double X
public float X
{
get { return _x; }
set { _x = (float)value; }
set { _x = value; }
}

public double Y
public float Y
{
get { return _y; }
set { _y = (float)value; }
set { _y = value; }
}

public override string ToString()
Expand Down Expand Up @@ -98,37 +98,37 @@ public struct Rect : IFormattable
private float _width;
private float _height;

private const double EmptyX = double.PositiveInfinity;
private const double EmptyY = double.PositiveInfinity;
private const double EmptyWidth = double.NegativeInfinity;
private const double EmptyHeight = double.NegativeInfinity;
private const float EmptyX = float.PositiveInfinity;
private const float EmptyY = float.PositiveInfinity;
private const float EmptyWidth = float.NegativeInfinity;
private const float EmptyHeight = float.NegativeInfinity;

private static readonly Rect s_empty = CreateEmptyRect();

public Rect(double x,
double y,
double width,
double height)
public Rect(float x,
float y,
float width,
float height)
{
if (width < 0)
throw new ArgumentOutOfRangeException(nameof(width), SR.ArgumentOutOfRange_NeedNonNegNum);
if (height < 0)
throw new ArgumentOutOfRangeException(nameof(height), SR.ArgumentOutOfRange_NeedNonNegNum);

_x = (float)x;
_y = (float)y;
_width = (float)width;
_height = (float)height;
_x = x;
_y = y;
_width = width;
_height = height;
}

public Rect(Point point1,
Point point2)
{
_x = (float)Math.Min(point1.X, point2.X);
_y = (float)Math.Min(point1.Y, point2.Y);
_x = Math.Min(point1.X, point2.X);
_y = Math.Min(point1.Y, point2.Y);

_width = (float)Math.Max(Math.Max(point1.X, point2.X) - _x, 0);
_height = (float)Math.Max(Math.Max(point1.Y, point2.Y) - _y, 0);
_width = Math.Max(Math.Max(point1.X, point2.X) - _x, 0);
_height = Math.Max(Math.Max(point1.Y, point2.Y) - _y, 0);
}

public Rect(Point location, Size size)
Expand All @@ -139,79 +139,79 @@ public Rect(Point location, Size size)
}
else
{
_x = (float)location.X;
_y = (float)location.Y;
_width = (float)size.Width;
_height = (float)size.Height;
_x = location.X;
_y = location.Y;
_width = size.Width;
_height = size.Height;
}
}

public double X
public float X
{
get { return _x; }
set { _x = (float)value; }
set { _x = value; }
}

public double Y
public float Y
{
get { return _y; }
set { _y = (float)value; }
set { _y = value; }
}

public double Width
public float Width
{
get { return _width; }
set
{
if (value < 0)
throw new ArgumentOutOfRangeException(nameof(Width), SR.ArgumentOutOfRange_NeedNonNegNum);

_width = (float)value;
_width = value;
}
}

public double Height
public float Height
{
get { return _height; }
set
{
if (value < 0)
throw new ArgumentOutOfRangeException(nameof(Height), SR.ArgumentOutOfRange_NeedNonNegNum);

_height = (float)value;
_height = value;
}
}

public double Left
public float Left
{
get { return _x; }
}

public double Top
public float Top
{
get { return _y; }
}

public double Right
public float Right
{
get
{
if (IsEmpty)
{
return double.NegativeInfinity;
return float.NegativeInfinity;
}

return _x + _width;
}
}

public double Bottom
public float Bottom
{
get
{
if (IsEmpty)
{
return double.NegativeInfinity;
return float.NegativeInfinity;
}

return _y + _height;
Expand Down Expand Up @@ -241,10 +241,10 @@ public void Intersect(Rect rect)
}
else
{
double left = Math.Max(X, rect.X);
double top = Math.Max(Y, rect.Y);
float left = Math.Max(X, rect.X);
float top = Math.Max(Y, rect.Y);

// Max with 0 to prevent double weirdness from causing us to be (-epsilon..0)
// Max with 0 to prevent float weirdness from causing us to be (-epsilon..0)
Width = Math.Max(Math.Min(X + Width, rect.X + rect.Width) - left, 0);
Height = Math.Max(Math.Min(Y + Height, rect.Y + rect.Height) - top, 0);

Expand All @@ -261,31 +261,31 @@ public void Union(Rect rect)
}
else if (!rect.IsEmpty)
{
double left = Math.Min(Left, rect.Left);
double top = Math.Min(Top, rect.Top);
float left = Math.Min(Left, rect.Left);
float top = Math.Min(Top, rect.Top);


// We need this check so that the math does not result in NaN
if ((rect.Width == double.PositiveInfinity) || (Width == double.PositiveInfinity))
if ((rect.Width == float.PositiveInfinity) || (Width == float.PositiveInfinity))
{
Width = double.PositiveInfinity;
Width = float.PositiveInfinity;
}
else
{
// Max with 0 to prevent double weirdness from causing us to be (-epsilon..0)
double maxRight = Math.Max(Right, rect.Right);
// Max with 0 to prevent float weirdness from causing us to be (-epsilon..0)
float maxRight = Math.Max(Right, rect.Right);
Width = Math.Max(maxRight - left, 0);
}

// We need this check so that the math does not result in NaN
if ((rect.Height == double.PositiveInfinity) || (Height == double.PositiveInfinity))
if ((rect.Height == float.PositiveInfinity) || (Height == float.PositiveInfinity))
{
Height = double.PositiveInfinity;
Height = float.PositiveInfinity;
}
else
{
// Max with 0 to prevent double weirdness from causing us to be (-epsilon..0)
double maxBottom = Math.Max(Bottom, rect.Bottom);
// Max with 0 to prevent float weirdness from causing us to be (-epsilon..0)
float maxBottom = Math.Max(Bottom, rect.Bottom);
Height = Math.Max(maxBottom - top, 0);
}

Expand All @@ -299,7 +299,7 @@ public void Union(Point point)
Union(new Rect(point, point));
}

private bool ContainsInternal(double x, double y)
private bool ContainsInternal(float x, float y)
{
return ((x >= X) && (x - Width <= X) &&
(y >= Y) && (y - Height <= Y));
Expand Down Expand Up @@ -329,8 +329,8 @@ private static Rect CreateEmptyRect()

// the width and height properties prevent assignment of
// negative numbers so assign directly to the backing fields.
rect._width = (float)EmptyWidth;
rect._height = (float)EmptyHeight;
rect._width = EmptyWidth;
rect._height = EmptyHeight;

return rect;
}
Expand Down Expand Up @@ -414,37 +414,37 @@ public struct Size

private static readonly Size s_empty = CreateEmptySize();

public Size(double width, double height)
public Size(float width, float height)
{
if (width < 0)
throw new ArgumentOutOfRangeException(nameof(width), SR.ArgumentOutOfRange_NeedNonNegNum);
if (height < 0)
throw new ArgumentOutOfRangeException(nameof(height), SR.ArgumentOutOfRange_NeedNonNegNum);
_width = (float)width;
_height = (float)height;
_width = width;
_height = height;
}

public double Width
public float Width
{
get { return _width; }
set
{
if (value < 0)
throw new ArgumentOutOfRangeException(nameof(Width), SR.ArgumentOutOfRange_NeedNonNegNum);

_width = (float)value;
_width = value;
}
}

public double Height
public float Height
{
get { return _height; }
set
{
if (value < 0)
throw new ArgumentOutOfRangeException(nameof(Height), SR.ArgumentOutOfRange_NeedNonNegNum);

_height = (float)value;
_height = value;
}
}

Expand Down