Решение на Трета задача от Моника Димитрова

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

Към профила на Моника Димитрова

Резултати

  • 4 точки от тестове
  • 0 бонус точки
  • 4 точки общо
  • 51 успешни тест(а)
  • 18 неуспешни тест(а)

Код

module Graphics
require 'set'
class Canvas
def initialize(width = 1, height = 1)
@height = height
@width = width
@canvas = initialize_canvas @width, @height
end
def initialize_canvas(width, height)
canvas = {}
0.upto(height - 1) do |i|
canvas[i] = Array.new(width, 0)
end
canvas
end
def width
@width
end
def height
@height
end
def get_canvas
@canvas
end
def set_pixel(x, y)
@canvas[y][x] = 1
end
def pixel_at?(x, y)
@canvas[y][x] == 1
end
def draw(figure)
if figure.is_a? Point
set_pixel(figure.x, figure.y)
else
(figure.pixels_to_draw).each { |point| set_pixel(point[0], point[1]) }
end
end
def render_as(renderer)
renderer.render @canvas, @width, @height
end
end
module Renderers
class Ascii
def self.render canvas, width, height
rendered = ''
0.upto(height - 1) do |j|
rendered << canvas[j].join.to_s + "\n"
end
rendered.gsub!(/[01]/, '0' => '-', '1' => '@')
rendered.chomp
end
end
class Html
def self.render canvas, width, height
rendered = ' <!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">'
0.upto(height - 1) do |j|
rendered << canvas[j].join.to_s
rendered << '<br>' if j < height - 1
end
rendered.gsub!(/[01]/, '0' => '<i></i>', '1' => '<b></b>')
rendered << '</div></body></html>'
end
end
end
class Point
def initialize(x, y)
@x = x
@y = y
end
def x
@x
end
def y
@y
end
def ==(other)
@x == other.x and @y == other.y
end
def eql?(other)
@x.eql? other.x and @y.eql? other.y
end
end
class Line
def initialize(from, to)
@from = from
@to = to
end
def from
@from.y > @to.y ? @from : @to
end
def to
@from.y > @to.y ? @to : @from
end
def ==(other)
points = Set.new([[from.x, from.y], [to.x, to.y]])
points_other = Set.new([[other.from.x, other.from.y],[other.to.x, other.to.y]])
points == points_other
end
def eql?(other)
points = Set.new([[from.x, from.y], [to.x, to.y]])
points_other = Set.new([[other.from.x, other.from.y],[other.to.x, other.to.y]])
points.eql? points_other
end
def pixels_to_draw
pixels = []
if from.y == to.y
(from.x).downto(to.x) { |x| pixels << [x, from.y] }
elsif from.x == to.x
(from.y).downto(to.y) { |y| pixels << [from.x, y] }
end
pixels
end
end
class Rectangle
def initialize(left, right)
@left = left
@right = right
end
def left
@left.x < @right.x ? @left : @right
end
def right
@left.x < @right.x ? @right : @left
end
def top_left
if left.y < right.y
left
else
top_left = Point.new(left.x, right.y)
end
end
def top_right
top_right = Point.new(right.x, left.y)
end
def bottom_left
bottom_left = Point.new(left.x, right.y)
end
def bottom_right
if left.x < right.x
right
else
bottom_right = Point.new(right.x, left.y)
end
end
def pixels_to_draw
pixels = []
pixels.concat Line.new(top_left, top_right).pixels_to_draw
pixels.concat Line.new(top_left, bottom_left).pixels_to_draw
pixels.concat Line.new(bottom_left, bottom_right).pixels_to_draw
pixels.concat Line.new(top_right, bottom_right).pixels_to_draw
pixels
end
end
end

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

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

Failures:

  1) Graphics Canvas can't be constructed with no arguments
     Failure/Error: expect { Graphics::Canvas.new }.to raise_error(ArgumentError)
       expected ArgumentError but nothing was raised
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:13:in `block (3 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 renders multiple drawn shapes
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "@@@@@@@@@@@@@@@\n@-------------@\n@-@@@@@@@@@@@-@\n@-@---------@-@\n@-@------@@-@-@\n@-@---@@@---@-@\n@-@-@@------@-@\n@-@---------@-@\n@-@-@@@@----@-@\n@-@-@-------@-@\n@-@---------@-@\n@-@---------@-@\n@-@@@@@@@@@@@-@\n@-------------@\n@@@@@@@@@@@@@@@"
            got: "@@@@@@@@@@@@@@@\n@-------------@\n@-@@@@@@@@@@@-@\n@-@---------@-@\n@-@---------@-@\n@-@---------@-@\n@-@---------@-@\n@-@---------@-@\n@-@-@@@@----@-@\n@-@-@-------@-@\n@-@---------@-@\n@-@---------@-@\n@-@@@@@@@@@@@-@\n@-------------@\n@@@@@@@@@@@@@@@"
       
       (compared using ==)
       
       Diff:
       @@ -2,9 +2,9 @@
        @-------------@
        @-@@@@@@@@@@@-@
        @-@---------@-@
       -@-@------@@-@-@
       -@-@---@@@---@-@
       -@-@-@@------@-@
       +@-@---------@-@
       +@-@---------@-@
       +@-@---------@-@
        @-@---------@-@
        @-@-@@@@----@-@
        @-@-@-------@-@
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:211: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)>'

  3) 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-1x1ohx9/solution.rb:31:in `set_pixel'
     # /tmp/d20131223-4637-1x1ohx9/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)>'

  4) 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----------"
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,6 @@
        ----------
       --@@-------
       ----@@@@---
       --------@@-
       +----------
       +----------
       +----------
        ----------
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-1x1ohx9/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)>'

  5) Graphics Canvas drawing of shapes and rasterization of lines works with lines with a significant slope, with swapped ends
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "----------\n-@--------\n-@--------\n--@-------\n--@-------\n--@-------\n--@-------\n---@------\n---@------\n----------"
            got: "----------\n----------\n----------\n----------\n----------\n----------\n----------\n----------\n----------\n----------"
       
       (compared using ==)
       
       Diff:
       @@ -1,11 +1,11 @@
        ----------
       --@--------
       --@--------
       ---@-------
       ---@-------
       ---@-------
       ---@-------
       ----@------
       ----@------
       +----------
       +----------
       +----------
       +----------
       +----------
       +----------
       +----------
       +----------
        ----------
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:113: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 lines works with multiple lines
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "-@--------\n-@@-------\n-@-@@@@---\n-@-----@@-\n----------"
            got: "-@--------\n-@--------\n-@--------\n-@--------\n----------"
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,6 @@
        -@--------
       --@@-------
       --@-@@@@---
       --@-----@@-
       +-@--------
       +-@--------
       +-@--------
        ----------
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-1x1ohx9/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)>'

  7) 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----------"
       
       (compared using ==)
       
       Diff:
       @@ -1,6 +1,6 @@
        ----------
        -@@@@@@@@-
       --@------@-
       --@@@@@@@@-
       +--------@-
       +--------@-
        ----------
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-1x1ohx9/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)>'

  8) Graphics shapes Point comparison for equality returns the same hash for the same points
     Failure/Error: a1.hash.should eq a2.hash
       
       expected: 575148069
            got: 647949051
       
       (compared using ==)
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:361: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)>'

  9) Graphics shapes Line initialization with swapped points puts the top point of vertical lines in the from field
     Failure/Error: vertical_line.from.y.should eq 1
       
       expected: 1
            got: 8
       
       (compared using ==)
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:413:in `block (6 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 shapes Line initialization with swapped points puts the bottom point of vertical lines in the to field
     Failure/Error: vertical_line.to.y.should eq 8
       
       expected: 8
            got: 1
       
       (compared using ==)
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:418:in `block (6 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 shapes Line comparison for equality returns the same hash if the lines are the same
     Failure/Error: a.hash.should eq b.hash
       
       expected: 692288727
            got: 281282473
       
       (compared using ==)
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:465: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)>'

  12) Graphics shapes Rectangle comparison for equality is true if rectangle points are the same
     Failure/Error: (a == b).should be_true
       expected: true value
            got: false
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:526: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)>'

  13) Graphics shapes Rectangle comparison for equality is true if rectangle points are the same, even if swapped
     Failure/Error: (a == b).should be_true
       expected: true value
            got: false
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:533: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)>'

  14) Graphics shapes Rectangle comparison for equality is true for rectangles defined with different diagonal corners
     Failure/Error: (a == b).should be_true
       expected: true value
            got: false
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:540: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)>'

  15) Graphics shapes Rectangle comparison for equality works with eql? as well
     Failure/Error: a.should eql b
       
       expected: #<Graphics::Rectangle:0xb9704964 @left=#<Graphics::Point:0xb9704a18 @x=1, @y=1>, @right=#<Graphics::Point:0xb97049b4 @x=10, @y=14>>
            got: #<Graphics::Rectangle:0xb9704a54 @left=#<Graphics::Point:0xb9704ab8 @x=1, @y=1>, @right=#<Graphics::Point:0xb9704a7c @x=10, @y=14>>
       
       (compared using eql?)
       
       Diff:
       @@ -1,4 +1,4 @@
       -#<Graphics::Rectangle:0xb9704964
       - @left=#<Graphics::Point:0xb9704a18 @x=1, @y=1>,
       - @right=#<Graphics::Point:0xb97049b4 @x=10, @y=14>>
       +#<Graphics::Rectangle:0xb9704a54
       + @left=#<Graphics::Point:0xb9704ab8 @x=1, @y=1>,
       + @right=#<Graphics::Point:0xb9704a7c @x=10, @y=14>>
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:548: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)>'

  16) Graphics shapes Rectangle comparison for equality returns the same hash if the rectangles are the same
     Failure/Error: a.hash.should eq b.hash
       
       expected: 950252241
            got: -421933557
       
       (compared using ==)
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:556: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)>'

  17) Graphics shapes Rectangle comparison for equality returns the same hash for rectangles defined with different diagonal corners
     Failure/Error: a.hash.should eq b.hash
       
       expected: -367228569
            got: 649800995
       
       (compared using ==)
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:563: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)>'

  18) Graphics shapes Rectangle corners bottom right
     Failure/Error: rect.bottom_right.y.should eq 4
       
       expected: 4
            got: 2
       
       (compared using ==)
     # /tmp/d20131223-4637-1x1ohx9/spec.rb:590: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)>'

Finished in 0.0936 seconds
69 examples, 18 failures

Failed examples:

rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:12 # Graphics Canvas can't be constructed with no arguments
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:203 # Graphics Canvas drawing of shapes and rasterization renders multiple drawn shapes
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:51 # Graphics Canvas drawing of shapes and rasterization of points works for multiple ones
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:96 # Graphics Canvas drawing of shapes and rasterization of lines works with lines with a small slope
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:109 # Graphics Canvas drawing of shapes and rasterization of lines works with lines with a significant slope, with swapped ends
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:127 # Graphics Canvas drawing of shapes and rasterization of lines works with multiple lines
rspec /tmp/d20131223-4637-1x1ohx9/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-1x1ohx9/spec.rb:360 # Graphics shapes Point comparison for equality returns the same hash for the same points
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:411 # Graphics shapes Line initialization with swapped points puts the top point of vertical lines in the from field
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:416 # Graphics shapes Line initialization with swapped points puts the bottom point of vertical lines in the to field
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:461 # Graphics shapes Line comparison for equality returns the same hash if the lines are the same
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:522 # Graphics shapes Rectangle comparison for equality is true if rectangle points are the same
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:529 # Graphics shapes Rectangle comparison for equality is true if rectangle points are the same, even if swapped
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:536 # Graphics shapes Rectangle comparison for equality is true for rectangles defined with different diagonal corners
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:543 # Graphics shapes Rectangle comparison for equality works with eql? as well
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:552 # Graphics shapes Rectangle comparison for equality returns the same hash if the rectangles are the same
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:559 # Graphics shapes Rectangle comparison for equality returns the same hash for rectangles defined with different diagonal corners
rspec /tmp/d20131223-4637-1x1ohx9/spec.rb:587 # Graphics shapes Rectangle corners bottom right

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

Моника обнови решението на 22.12.2013 21:16 (преди почти 11 години)

+module Graphics
+ require 'set'
+ class Canvas
+ def initialize(width = 1, height = 1)
+ @height = height
+ @width = width
+ @canvas = initialize_canvas @width, @height
+ end
+
+ def initialize_canvas(width, height)
+ canvas = {}
+ 0.upto(height - 1) do |i|
+ canvas[i] = Array.new(width, 0)
+ end
+ canvas
+ end
+
+ def width
+ @width
+ end
+
+ def height
+ @height
+ end
+
+ def get_canvas
+ @canvas
+ end
+
+ def set_pixel(x, y)
+ @canvas[y][x] = 1
+ end
+
+ def pixel_at?(x, y)
+ @canvas[y][x] == 1
+ end
+
+ def draw(figure)
+ if figure.is_a? Point
+ set_pixel(figure.x, figure.y)
+ else
+ (figure.pixels_to_draw).each { |point| set_pixel(point[0], point[1]) }
+ end
+ end
+
+ def render_as(renderer)
+ renderer.render @canvas, @width, @height
+ end
+ end
+
+ module Renderers
+ class Ascii
+ def self.render canvas, width, height
+ rendered = ''
+ 0.upto(height - 1) do |j|
+ rendered << canvas[j].join.to_s + "\n"
+ end
+ rendered.gsub!(/[01]/, '0' => '-', '1' => '@')
+ rendered.chomp
+ end
+ end
+
+ class Html
+ def self.render canvas, width, height
+ rendered = ' <!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">'
+ 0.upto(height - 1) do |j|
+ rendered << canvas[j].join.to_s
+ rendered << '<br>' if j < height - 1
+ end
+ rendered.gsub!(/[01]/, '0' => '<i></i>', '1' => '<b></b>')
+ rendered << '</div></body></html>'
+ end
+ end
+ end
+
+ class Point
+ def initialize(x, y)
+ @x = x
+ @y = y
+ end
+
+ def x
+ @x
+ end
+
+ def y
+ @y
+ end
+
+ def ==(other)
+ @x == other.x and @y == other.y
+ end
+
+ def eql?(other)
+ @x.eql? other.x and @y.eql? other.y
+ end
+ end
+
+ class Line
+ def initialize(from, to)
+ @from = from
+ @to = to
+ end
+
+ def from
+ @from.y > @to.y ? @from : @to
+ end
+
+ def to
+ @from.y > @to.y ? @to : @from
+ end
+
+ def ==(other)
+ points = Set.new([[from.x, from.y], [to.x, to.y]])
+ points_other = Set.new([[other.from.x, other.from.y],[other.to.x, other.to.y]])
+ points == points_other
+ end
+
+ def eql?(other)
+ points = Set.new([[from.x, from.y], [to.x, to.y]])
+ points_other = Set.new([[other.from.x, other.from.y],[other.to.x, other.to.y]])
+ points.eql? points_other
+ end
+
+ def pixels_to_draw
+ pixels = []
+ if from.y == to.y
+ (from.x).downto(to.x) { |x| pixels << [x, from.y] }
+ elsif from.x == to.x
+ (from.y).downto(to.y) { |y| pixels << [from.x, y] }
+ end
+ pixels
+ end
+ end
+
+ class Rectangle
+ def initialize(left, right)
+ @left = left
+ @right = right
+ end
+
+ def left
+ @left.x < @right.x ? @left : @right
+ end
+
+ def right
+ @left.x < @right.x ? @right : @left
+ end
+
+ def top_left
+ if left.y < right.y
+ left
+ else
+ top_left = Point.new(left.x, right.y)
+ end
+ end
+
+ def top_right
+ top_right = Point.new(right.x, left.y)
+ end
+
+ def bottom_left
+ bottom_left = Point.new(left.x, right.y)
+ end
+
+ def bottom_right
+ if left.x < right.x
+ right
+ else
+ bottom_right = Point.new(right.x, left.y)
+ end
+ end
+
+ def pixels_to_draw
+ pixels = []
+ pixels.concat Line.new(top_left, top_right).pixels_to_draw
+ pixels.concat Line.new(top_left, bottom_left).pixels_to_draw
+ pixels.concat Line.new(bottom_left, bottom_right).pixels_to_draw
+ pixels.concat Line.new(top_right, bottom_right).pixels_to_draw
+ pixels
+ end
+ end
+end