module Draught::Boxlike

Constants

POSITION_METHODS

Public Instance Methods

bottom_edge() click to toggle source
# File lib/draught/boxlike.rb, line 72
def bottom_edge
  @bottom_edge ||= lower_left.y
end
box_type() click to toggle source
# File lib/draught/boxlike.rb, line 20
def box_type
  raise NotImplementedError, "includers of Boxlike must implement #box_type"
end
centre() click to toggle source
# File lib/draught/boxlike.rb, line 52
def centre
  @centre ||= lower_left.translate(Draught::Vector.new(width/2.0, height/2.0))
end
centre_left() click to toggle source
# File lib/draught/boxlike.rb, line 36
def centre_left
  @centre_left ||= lower_left.translate(Draught::Vector.new(0, height/2.0))
end
centre_right() click to toggle source
# File lib/draught/boxlike.rb, line 44
def centre_right
  @centre_right ||= lower_right.translate(Draught::Vector.new(0, height / 2.0))
end
containers() click to toggle source
# File lib/draught/boxlike.rb, line 100
def containers
  raise NotImplementedError
end
corners() click to toggle source
# File lib/draught/boxlike.rb, line 56
def corners
  [lower_left, lower_right, upper_right, upper_left]
end
disjoint?(other_box) click to toggle source
# File lib/draught/boxlike.rb, line 108
def disjoint?(other_box)
  horizontal_disjoint?(other_box) || vertical_disjoint?(other_box)
end
height() click to toggle source
# File lib/draught/boxlike.rb, line 16
def height
  raise NotImplementedError, "includers of Boxlike must implement #height"
end
include_point?(point) click to toggle source
# File lib/draught/boxlike.rb, line 112
def include_point?(point)
  horizontal_extent.include?(point.x) && vertical_extent.include?(point.y)
end
left_edge() click to toggle source
# File lib/draught/boxlike.rb, line 60
def left_edge
  @left_edge ||= lower_left.x
end
lower_centre() click to toggle source
# File lib/draught/boxlike.rb, line 40
def lower_centre
  @lower_centre ||= lower_left.translate(Draught::Vector.new(width/2.0, 0))
end
lower_left() click to toggle source
# File lib/draught/boxlike.rb, line 8
def lower_left
  raise NotImplementedError, "includers of Boxlike must implement #lower_left"
end
lower_right() click to toggle source
# File lib/draught/boxlike.rb, line 24
def lower_right
  @lower_right ||= lower_left.translate(Draught::Vector.new(width, 0))
end
min_gap() click to toggle source
# File lib/draught/boxlike.rb, line 116
def min_gap
  0
end
move_to(point, opts = {}) click to toggle source
# File lib/draught/boxlike.rb, line 76
def move_to(point, opts = {})
  reference_position_method = opts.fetch(:position, :lower_left)
  if invalid_position_method?(reference_position_method)
    raise ArgumentError, ":position option must be a valid position (one of #{POSITION_METHODS.map(&:inspect).join(', ')}), rather than #{opts[:position].inspect}" 
  end

  reference_point = send(reference_position_method)
  translation = Draught::Vector.translation_between(reference_point, point)
  return self if translation == Draught::Vector::NULL
  translate(translation)
end
overlaps?(other_box) click to toggle source
# File lib/draught/boxlike.rb, line 104
def overlaps?(other_box)
  !disjoint?(other_box)
end
paths() click to toggle source
# File lib/draught/boxlike.rb, line 96
def paths
  raise NotImplementedError
end
right_edge() click to toggle source
# File lib/draught/boxlike.rb, line 64
def right_edge
  @right_edge ||= upper_right.x
end
top_edge() click to toggle source
# File lib/draught/boxlike.rb, line 68
def top_edge
  @top_edge ||= upper_right.y
end
transform(transformer) click to toggle source
# File lib/draught/boxlike.rb, line 92
def transform(transformer)
  raise NotImplementedError
end
translate(point) click to toggle source
# File lib/draught/boxlike.rb, line 88
def translate(point)
  raise NotImplementedError
end
upper_centre() click to toggle source
# File lib/draught/boxlike.rb, line 48
def upper_centre
  @upper_centre ||= upper_left.translate(Draught::Vector.new(width/2.0, 0))
end
upper_left() click to toggle source
# File lib/draught/boxlike.rb, line 32
def upper_left
  @upper_left ||= lower_left.translate(Draught::Vector.new(0, height))
end
upper_right() click to toggle source
# File lib/draught/boxlike.rb, line 28
def upper_right
  @upper_right ||= lower_left.translate(Draught::Vector.new(width, height))
end
width() click to toggle source
# File lib/draught/boxlike.rb, line 12
def width
  raise NotImplementedError, "includers of Boxlike must implement #width"
end

Private Instance Methods

horizontal_disjoint?(other_box) click to toggle source
# File lib/draught/boxlike.rb, line 122
def horizontal_disjoint?(other_box)
  other_box.left_edge == right_edge || other_box.right_edge == left_edge ||
    other_box.left_edge > right_edge || other_box.right_edge < left_edge
end
horizontal_extent() click to toggle source
# File lib/draught/boxlike.rb, line 132
def horizontal_extent
  @horizontal_extent ||= lower_left.x..upper_right.x
end
invalid_position_method?(method_name) click to toggle source
# File lib/draught/boxlike.rb, line 140
def invalid_position_method?(method_name)
  !valid_position_method?(method_name)
end
valid_position_method?(method_name) click to toggle source
# File lib/draught/boxlike.rb, line 144
def valid_position_method?(method_name)
  POSITION_METHODS.include?(method_name)
end
vertical_disjoint?(other_box) click to toggle source
# File lib/draught/boxlike.rb, line 127
def vertical_disjoint?(other_box)
  other_box.bottom_edge == top_edge || other_box.top_edge == bottom_edge ||
    other_box.top_edge < bottom_edge || other_box.bottom_edge > top_edge
end
vertical_extent() click to toggle source
# File lib/draught/boxlike.rb, line 136
def vertical_extent
  @vertical_extent ||= lower_left.y..upper_right.y
end