Select your favorite languages :
- Or search :
template <typename T> struct Point { T x = {}; T y = {}; }; template <typename T> struct Rectangle { Point<T> upper_left; Point<T> lower_right; }; template <typename T> Point<T> get_center(const Rectangle<T>& rect) { return { .x = (rect.upper_left.x + rect.lower_right.x) / 2, .y = (rect.upper_left.y + rect.lower_right.y) / 2, }; }
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 ); } }
class Point { public $x; public $y; public function __construct(float x, float y) { $this->x = x; $this->y = y; } } class Rectangle { private $point1; private $point2; public function __construct(Point $point1, Point $point2) { $this->point1 = $point1; $this->point2 = $point2; } public function getCenter(): Point { return new Point( ($this->point1->x + $this->point2->x) / 2, ($this->point1->y + $this->point2->y) / 2 ); } }
Bart