Implementation
D

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
Types
c := CenterPoint(Rect(x1,y1,x2,y2));
Point = Struct.new(:x, :y)

Rect  = Struct.new(:x1, :y1, :x2, :y2) do
  def center  
    Point.new((x1+x2)/2.0, (y1+y2)/2.0)
  end
end

c = Rect.new(0,0,2,5).center
const center = ({x1, y1, x2, y2}) => ({x: (x1 + x2) / 2, y: (y1 + y2) / 2})
class Point {
  constructor (x, y) {
    this.x = x
    this.y = y
  }
}
const center = ({x1, y1, x2, y2}) => new Point ((x1 + x2) / 2, (y1 + y2) / 2)