Logo

Programming-Idioms

History of Idiom 179 > diff from v9 to v10

Edit summary for version 10 by Admiral Apfel:
New Csharp implementation by user [Admiral Apfel]

Version 9

2019-09-26, 13:37:07

Version 10

2019-09-26, 14:02:18

Idiom #179 Get center of a rectangle

Return the center c of the rectangle with coördinates(x1,y1,x2,y2)

Idiom #179 Get center of a rectangle

Return the center c of the rectangle with coördinates(x1,y1,x2,y2)

Code
class Point
{
	public float X { get; }
	public float Y { get; }

	public Point(float x, float y)
	{
		X = x;
		Y = y;
	}
}

class Rectangle
{
	Point Point1;
	Point Point2;

	public Rectangle(Point point1, Point point2)
	{
		Point1 = point1;
		Point2 = point2;
	}

	public Point GetCenter()
	{
		return new Point(
		(Point1.X + Point2.X) / 2,
		(Point1.Y + Point2.Y) / 2
		);
	}
}