Решение на Трета задача от Веселин Генадиев

Обратно към всички решения

Към профила на Веселин Генадиев

Резултати

  • 5 точки от тестове
  • 0 бонус точки
  • 5 точки общо
  • 57 успешни тест(а)
  • 12 неуспешни тест(а)

Код

module Graphics
class Renderers
class Ascii
end
class Html
end
end
class Canvas
@content
@html_header
@html_footer
attr_reader :width
attr_reader :height
def initialize width, height
@width = width
@height = height
@content = Array.new(@width) { Array.new(@height, '-') }
set_html_header
set_html_footer
end
def set_pixel x, y
@content[y][x] = '@'
end
def pixel_at? x, y
@content[y][x].eql? '@'
end
def draw figure
figure.draw self if figure.respond_to? :draw
end
def render_as renderer
return render_as_ascii if renderer.equal? Graphics::Renderers::Ascii
return render_as_html if renderer.equal? Graphics::Renderers::Html
end
private
def render_as_ascii
@content.map { |row| row.join }.join("\n")
end
def render_as_html
@html_header + @content.map { |row| row.join }.join('<br>').
gsub('@', '<b></b>').gsub('-', '<i></i>') + @html_footer
end
def set_html_header
@html_header = '<!DOCTYPE html><html><head><title>Rendered Canvas</title>
<style type="text/css">.canvas {font-size: 1px;line-height: 1px;}.canvas * {
display: inline-block;width: 10px;height: 10px;border-radius: 5px;}.canvas i {
background-color: #eee; }.canvas b {background-color: #333;}</style></head><body>
<div class="canvas">'
end
def set_html_footer
@html_footer = '</div></body></html>'
end
end
class Point
attr_reader :x
attr_reader :y
def initialize x, y
@x = x
@y = y
end
def draw canvas
canvas.set_pixel x, y
end
def eql? other
@x == other.x && @y == other.y
end
def ==(other)
self.eql? other
end
def <(other)
if @x == other.x
@y < other.y
else
@x < other.x
end
end
def hash
@x << @y
end
end
class Line
@error
@step_x
@step_y
@delta_x
@delta_y
@points
attr_reader :from
attr_reader :to
def initialize from, to
@from = from < to ? from : to
@to = from < to ? to : from
initialize_rasterization_details
end
def draw canvas
rasterize_points(@from.x, @from.y).each { |point| point.draw canvas }
end
def eql? other
@from == other.from && @to == other.to
end
def ==(other)
self.eql? other
end
def hash
@from.hash << @to.hash
end
private
def initialize_rasterization_details
@delta_x = (@to.x - @from.x).abs
@delta_y = (@to.y - @from.y).abs
@step_x = @from.x < @to.x ? 1 : -1
@step_y = @from.y < @to.y ? 1 : -1
@error = @delta_x - @delta_y
@points = [@from]
end
def rasterize_points column, row
while column != @to.x || row != @to.y
error_doubled = @error << 1
@error, column = @error - @delta_y, column + @step_x if error_doubled >= -@delta_y
@error, row = @error + @delta_x, row + @step_y if error_doubled <= @delta_x
@points << Point.new(column, row)
end
@points
end
end
class Rectangle
attr_reader :left
attr_reader :right
attr_reader :top_left
attr_reader :top_right
attr_reader :bottom_left
attr_reader :bottom_right
def initialize left, right
@left = left < right ? left : right
@right = left < right ? right : left
@top_left = Point.new [@left.x, @right.x].min, [@left.y, @right.y].min
@top_right = Point.new [@left.x, @right.x].max, [@left.y, @right.y].min
@bottom_left = Point.new [@left.x, @right.x].min, [@left.y, @right.y].max
@bottom_right = Point.new [@left.x, @right.x].max, [@left.y, @right.y].max
end
def draw canvas
Line.new(@top_left, @top_right).draw canvas
Line.new(@top_right, @bottom_right).draw canvas
Line.new(@bottom_right, @bottom_left).draw canvas
Line.new(@bottom_left, @top_left).draw canvas
end
def eql? other
@top_left == other.top_left && @top_right == other.top_right &&
@bottom_left == other.bottom_left && @bottom_right == other.bottom_right
end
def ==(other)
self.eql? other
end
def hash
@top_left.hash << @top_right.hash + @bottom_left.hash << @bottom_right.hash
end
end
end

Лог от изпълнението

..........FF.F.F.FFF.FFF.FF..........................................

Failures:

  1) Graphics Canvas drawing of shapes and rasterization of points works for multiple ones
     Failure/Error: canvas.set_pixel 4, 4
     NoMethodError:
       undefined method `[]=' for nil:NilClass
     # /tmp/d20131223-4637-1rnbi02/solution.rb:26:in `set_pixel'
     # /tmp/d20131223-4637-1rnbi02/spec.rb:57:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Graphics Canvas drawing of shapes and rasterization of lines works with simple horizontal lines
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "--------\n---@@@@-\n--------"
            got: "---\n---@@@@\n---\n---\n---\n---\n---\n---"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,9 @@
       ---------
       ----@@@@-
       ---------
       +---
       +---@@@@
       +---
       +---
       +---
       +---
       +---
       +---
     # /tmp/d20131223-4637-1rnbi02/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-1rnbi02/spec.rb:73:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) Graphics Canvas drawing of shapes and rasterization of lines works with lines with a small slope
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "----------\n-@@-------\n---@@@@---\n-------@@-\n----------"
            got: "-----\n-@@--\n---@@@@\n-----@@\n-----\n-----\n-----\n-----\n-----\n-----"
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,11 @@
       -----------
       --@@-------
       ----@@@@---
       --------@@-
       -----------
       +-----
       +-@@--
       +---@@@@
       +-----@@
       +-----
       +-----
       +-----
       +-----
       +-----
       +-----
     # /tmp/d20131223-4637-1rnbi02/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-1rnbi02/spec.rb:100:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) Graphics Canvas drawing of shapes and rasterization of lines works with multiple lines
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "-@--------\n-@@-------\n-@-@@@@---\n-@-----@@-\n----------"
            got: "-@---\n-@@--\n-@-@@@@\n-@---@@\n-----\n-----\n-----\n-----\n-----\n-----"
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,11 @@
       --@--------
       --@@-------
       --@-@@@@---
       --@-----@@-
       -----------
       +-@---
       +-@@--
       +-@-@@@@
       +-@---@@
       +-----
       +-----
       +-----
       +-----
       +-----
       +-----
     # /tmp/d20131223-4637-1rnbi02/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-1rnbi02/spec.rb:132:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) Graphics Canvas drawing of shapes and rasterization of rectangles works with simple rects
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "----------\n-@@@@@@@@-\n-@------@-\n-@@@@@@@@-\n----------"
            got: "-----\n-@@@@@@@@\n-@---@\n-@@@@@@@@\n-----\n-----\n-----\n-----\n-----\n-----"
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,11 @@
       -----------
       --@@@@@@@@-
       --@------@-
       --@@@@@@@@-
       -----------
       +-----
       +-@@@@@@@@
       +-@---@
       +-@@@@@@@@
       +-----
       +-----
       +-----
       +-----
       +-----
       +-----
     # /tmp/d20131223-4637-1rnbi02/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-1rnbi02/spec.rb:158:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) Graphics Canvas drawing of shapes and rasterization of rectangles works with rects defined with their bottom left and top right points
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "----------\n-@@@@@@@@-\n-@------@-\n-@@@@@@@@-\n----------"
            got: "-----\n-@@@@@@@@\n-@---@\n-@@@@@@@@\n-----\n-----\n-----\n-----\n-----\n-----"
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,11 @@
       -----------
       --@@@@@@@@-
       --@------@-
       --@@@@@@@@-
       -----------
       +-----
       +-@@@@@@@@
       +-@---@
       +-@@@@@@@@
       +-----
       +-----
       +-----
       +-----
       +-----
       +-----
     # /tmp/d20131223-4637-1rnbi02/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-1rnbi02/spec.rb:171:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) Graphics Canvas drawing of shapes and rasterization of rectangles works with rects with a zero height as a line
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "----------\n-@@@@@@@@-\n----------"
            got: "---\n-@@@@@@@@\n---\n---\n---\n---\n---\n---\n---\n---"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,11 @@
       -----------
       --@@@@@@@@-
       -----------
       +---
       +-@@@@@@@@
       +---
       +---
       +---
       +---
       +---
       +---
       +---
       +---
     # /tmp/d20131223-4637-1rnbi02/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-1rnbi02/spec.rb:184:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) Graphics Renderers Ascii renders a grid of the size of the canvas
     Failure/Error: lines.size.should eq 3
       
       expected: 3
            got: 4
       
       (compared using ==)
     # /tmp/d20131223-4637-1rnbi02/spec.rb:240:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) Graphics Renderers Ascii renders blank canvases
     Failure/Error: canvas.render_as(ascii).should eq rendering('
       
       expected: "----\n----\n----"
            got: "---\n---\n---\n---"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,5 @@
       -----
       -----
       -----
       +---
       +---
       +---
       +---
     # /tmp/d20131223-4637-1rnbi02/spec.rb:245:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) Graphics Renderers Ascii renders simple canvases
     Failure/Error: canvas.render_as(ascii).should eq rendering('
       
       expected: "@---\n----\n---@"
            got: "@--\n---\n---@\n---"
       
       (compared using ==)
       
       Diff:
       
       @@ -1,4 +1,5 @@
       -@---
       -----
       +@--
       +---
        ---@
       +---
     # /tmp/d20131223-4637-1rnbi02/spec.rb:256:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) Graphics Renderers Html renders a grid of the size of the canvas
     Failure/Error: lines.size.should eq 3
       
       expected: 3
            got: 4
       
       (compared using ==)
     # /tmp/d20131223-4637-1rnbi02/spec.rb:283:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) Graphics Renderers Html renders simple canvases
     Failure/Error: html_rendering_of(canvas).should eq [
       
       expected: "<i></i><i></i><i></i><i></i><br><i></i><b></b><i></i><i></i><br><i></i><b></b><i></i><i></i>"
            got: "<i></i><i></i><i></i><br><i></i><b></b><i></i><br><i></i><b></b><i></i><br><i></i><i></i><i></i>"
       
       (compared using ==)
     # /tmp/d20131223-4637-1rnbi02/spec.rb:291:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.08877 seconds
69 examples, 12 failures

Failed examples:

rspec /tmp/d20131223-4637-1rnbi02/spec.rb:51 # Graphics Canvas drawing of shapes and rasterization of points works for multiple ones
rspec /tmp/d20131223-4637-1rnbi02/spec.rb:69 # Graphics Canvas drawing of shapes and rasterization of lines works with simple horizontal lines
rspec /tmp/d20131223-4637-1rnbi02/spec.rb:96 # Graphics Canvas drawing of shapes and rasterization of lines works with lines with a small slope
rspec /tmp/d20131223-4637-1rnbi02/spec.rb:127 # Graphics Canvas drawing of shapes and rasterization of lines works with multiple lines
rspec /tmp/d20131223-4637-1rnbi02/spec.rb:154 # Graphics Canvas drawing of shapes and rasterization of rectangles works with simple rects
rspec /tmp/d20131223-4637-1rnbi02/spec.rb:167 # Graphics Canvas drawing of shapes and rasterization of rectangles works with rects defined with their bottom left and top right points
rspec /tmp/d20131223-4637-1rnbi02/spec.rb:180 # Graphics Canvas drawing of shapes and rasterization of rectangles works with rects with a zero height as a line
rspec /tmp/d20131223-4637-1rnbi02/spec.rb:237 # Graphics Renderers Ascii renders a grid of the size of the canvas
rspec /tmp/d20131223-4637-1rnbi02/spec.rb:244 # Graphics Renderers Ascii renders blank canvases
rspec /tmp/d20131223-4637-1rnbi02/spec.rb:252 # Graphics Renderers Ascii renders simple canvases
rspec /tmp/d20131223-4637-1rnbi02/spec.rb:280 # Graphics Renderers Html renders a grid of the size of the canvas
rspec /tmp/d20131223-4637-1rnbi02/spec.rb:287 # Graphics Renderers Html renders simple canvases

История (2 версии и 0 коментара)

Веселин обнови решението на 22.12.2013 19:52 (преди почти 11 години)

+module Graphics
+ class Renderers
+ class Ascii
+ end
+ class Html
+ end
+ end
+
+ class Canvas
+ @content
+ @html_header
+ @html_footer
+
+ attr_reader :width
+ attr_reader :height
+
+ def initialize width, height
+ @width = width
+ @height = height
+ @content = Array.new(@width) { Array.new(@height, '-') }
+ set_html_header
+ set_html_footer
+ end
+
+ def set_pixel x, y
+ @content[y][x] = '@'
+ end
+
+ def pixel_at? x, y
+ @content[y][x].eql? '@'
+ end
+
+ def draw figure
+ figure.draw self if figure.respond_to? :draw
+ end
+
+ def render_as renderer
+ return render_as_ascii if renderer.equal? Graphics::Renderers::Ascii
+ return render_as_html if renderer.equal? Graphics::Renderers::Html
+ end
+
+ private
+ def render_as_ascii
+ @content.map { |row| row.join }.join("\n")
+ end
+
+ def render_as_html
+ @html_header + @content.map { |row| row.join }.join('<br>').
+ gsub('@', '<b></b>').gsub('-', '<i></i>') + @html_footer
+ end
+
+ def set_html_header
+ @html_header = '<!DOCTYPE html><html><head><title>Rendered Canvas</title>
+<style type="text/css">.canvas {font-size: 1px;line-height: 1px;}.canvas * {
+display: inline-block;width: 10px;height: 10px;border-radius: 5px;}.canvas i {
+background-color: #eee; }.canvas b {background-color: #333;}</style></head><body>
+<div class="canvas">'
+ end
+
+ def set_html_footer
+ @html_footer = '</div></body></html>'
+ end
+ end
+
+ class Point
+ attr_reader :x
+ attr_reader :y
+
+ def initialize x, y
+ @x = x
+ @y = y
+ end
+
+ def draw canvas
+ canvas.set_pixel x, y
+ end
+
+ def eql? other
+ @x == other.x && @y == other.y
+ end
+
+ def ==(other)
+ self.eql? other
+ end
+
+ def <(other)
+ if @x == other.x
+ @y < other.y
+ else
+ @x < other.x
+ end
+ end
+
+ def hash
+ @x << @y
+ end
+ end
+
+ class Line
+ @error
+ @step_x
+ @step_y
+ @delta_x
+ @delta_y
+ @points
+
+ attr_reader :from
+ attr_reader :to
+
+ def initialize from, to
+ @from = from < to ? from : to
+ @to = from < to ? to : from
+ initialize_rasterization_details
+ end
+
+ def draw canvas
+ rasterize_points(@from.x, @from.y).each { |point| point.draw canvas }
+ end
+
+ def eql? other
+ @from == other.from && @to == other.to
+ end
+
+ def ==(other)
+ self.eql? other
+ end
+
+ def hash
+ @from.hash << @to.hash
+ end
+
+ private
+ def initialize_rasterization_details
+ @delta_x = (@to.x - @from.x).abs
+ @delta_y = (@to.y - @from.y).abs
+ @step_x = @from.x < @to.x ? 1 : -1
+ @step_y = @from.y < @to.y ? 1 : -1
+ @error = @delta_x - @delta_y
+ @points = [@from]
+ end
+
+ def rasterize_points column, row
+ while column != @to.x || row != @to.y
+ error_doubled = @error << 1
+ @error, column = @error - @delta_y, column + @step_x if error_doubled > -@delta_y
+ @error, row = @error + @delta_x, row + @step_y if error_doubled < @delta_x
+ @points << Point.new(column, row)
+ end
+ @points
+ end
+ end
+
+ class Rectangle
+ attr_reader :left
+ attr_reader :right
+ attr_reader :top_left
+ attr_reader :top_right
+ attr_reader :bottom_left
+ attr_reader :bottom_right
+
+ def initialize left, right
+ @left = left < right ? left : right
+ @right = left < right ? right : left
+ @top_left = Point.new [@left.x, @right.x].min, [@left.y, @right.y].min
+ @top_right = Point.new [@left.x, @right.x].max, [@left.y, @right.y].min
+ @bottom_left = Point.new [@left.x, @right.x].min, [@left.y, @right.y].max
+ @bottom_right = Point.new [@left.x, @right.x].max, [@left.y, @right.y].max
+ end
+
+ def draw canvas
+ Line.new(@top_left, @top_right).draw canvas
+ Line.new(@top_right, @bottom_right).draw canvas
+ Line.new(@bottom_right, @bottom_left).draw canvas
+ Line.new(@bottom_left, @top_left).draw canvas
+ end
+
+ def eql? other
+ @top_left == other.top_left && @top_right == other.top_right &&
+ @bottom_left == other.bottom_left && @bottom_right == other.bottom_right
+ end
+
+ def ==(other)
+ self.eql? other
+ end
+
+ def hash
+ @top_left.hash << @top_right.hash + @bottom_left.hash << @bottom_right.hash
+ end
+ end
+end

Веселин обнови решението на 22.12.2013 20:16 (преди почти 11 години)

module Graphics
class Renderers
class Ascii
end
class Html
end
end
class Canvas
@content
@html_header
@html_footer
attr_reader :width
attr_reader :height
def initialize width, height
@width = width
@height = height
@content = Array.new(@width) { Array.new(@height, '-') }
set_html_header
set_html_footer
end
def set_pixel x, y
@content[y][x] = '@'
end
def pixel_at? x, y
@content[y][x].eql? '@'
end
def draw figure
figure.draw self if figure.respond_to? :draw
end
def render_as renderer
return render_as_ascii if renderer.equal? Graphics::Renderers::Ascii
return render_as_html if renderer.equal? Graphics::Renderers::Html
end
private
def render_as_ascii
@content.map { |row| row.join }.join("\n")
end
def render_as_html
@html_header + @content.map { |row| row.join }.join('<br>').
gsub('@', '<b></b>').gsub('-', '<i></i>') + @html_footer
end
def set_html_header
@html_header = '<!DOCTYPE html><html><head><title>Rendered Canvas</title>
<style type="text/css">.canvas {font-size: 1px;line-height: 1px;}.canvas * {
display: inline-block;width: 10px;height: 10px;border-radius: 5px;}.canvas i {
background-color: #eee; }.canvas b {background-color: #333;}</style></head><body>
<div class="canvas">'
end
def set_html_footer
@html_footer = '</div></body></html>'
end
end
class Point
attr_reader :x
attr_reader :y
def initialize x, y
@x = x
@y = y
end
def draw canvas
canvas.set_pixel x, y
end
def eql? other
@x == other.x && @y == other.y
end
def ==(other)
self.eql? other
end
def <(other)
if @x == other.x
@y < other.y
else
@x < other.x
end
end
def hash
@x << @y
end
end
class Line
@error
@step_x
@step_y
@delta_x
@delta_y
@points
attr_reader :from
attr_reader :to
def initialize from, to
@from = from < to ? from : to
@to = from < to ? to : from
initialize_rasterization_details
end
def draw canvas
rasterize_points(@from.x, @from.y).each { |point| point.draw canvas }
end
def eql? other
@from == other.from && @to == other.to
end
def ==(other)
self.eql? other
end
def hash
@from.hash << @to.hash
end
private
def initialize_rasterization_details
@delta_x = (@to.x - @from.x).abs
@delta_y = (@to.y - @from.y).abs
@step_x = @from.x < @to.x ? 1 : -1
@step_y = @from.y < @to.y ? 1 : -1
@error = @delta_x - @delta_y
@points = [@from]
end
def rasterize_points column, row
while column != @to.x || row != @to.y
error_doubled = @error << 1
- @error, column = @error - @delta_y, column + @step_x if error_doubled > -@delta_y
- @error, row = @error + @delta_x, row + @step_y if error_doubled < @delta_x
+ @error, column = @error - @delta_y, column + @step_x if error_doubled >= -@delta_y
+ @error, row = @error + @delta_x, row + @step_y if error_doubled <= @delta_x
@points << Point.new(column, row)
end
@points
end
end
class Rectangle
attr_reader :left
attr_reader :right
attr_reader :top_left
attr_reader :top_right
attr_reader :bottom_left
attr_reader :bottom_right
def initialize left, right
@left = left < right ? left : right
@right = left < right ? right : left
@top_left = Point.new [@left.x, @right.x].min, [@left.y, @right.y].min
@top_right = Point.new [@left.x, @right.x].max, [@left.y, @right.y].min
@bottom_left = Point.new [@left.x, @right.x].min, [@left.y, @right.y].max
@bottom_right = Point.new [@left.x, @right.x].max, [@left.y, @right.y].max
end
def draw canvas
Line.new(@top_left, @top_right).draw canvas
Line.new(@top_right, @bottom_right).draw canvas
Line.new(@bottom_right, @bottom_left).draw canvas
Line.new(@bottom_left, @top_left).draw canvas
end
def eql? other
@top_left == other.top_left && @top_right == other.top_right &&
@bottom_left == other.bottom_left && @bottom_right == other.bottom_right
end
def ==(other)
self.eql? other
end
def hash
@top_left.hash << @top_right.hash + @bottom_left.hash << @bottom_right.hash
end
end
end