All pastes #409548 Raw Edit

Anonymous

public ruby v1 · immutable
#409548 ·published 2007-03-25 19:48 UTC
rendered paste body
require 'constraint'class Rectangle    attr_reader :top_left, :top_right, :bottom_right, :bottom_left        def initialize top_left, bottom_right        @top_left = top_left        @bottom_right = bottom_right        @top_right = Point.new(bottom_right.x, top_left.y)        @bottom_left = Point.new(top_left.x, bottom_right.y)                Constraint.new [top_left, top_right], &Constraint::SAME_Y        Constraint.new [bottom_left, bottom_right], &Constraint::SAME_Y        Constraint.new [top_left, bottom_left], &Constraint::SAME_X        Constraint.new [top_right, bottom_right], &Constraint::SAME_X    end        def width        top_right.x - top_left.x    end        def height        bottom_left.y - top_left.y    end        def area        width * height    endend