Module: Draught::Boxlike
- Included in:
- BoundingBox, Container, Line, Path, Sheet
- Defined in:
- lib/draught/boxlike.rb
Constant Summary collapse
- POSITION_METHODS =
[:lower_left, :lower_centre, :lower_right, :centre_right, :upper_right, :upper_centre, :upper_left, :centre_left, :centre]
Instance Method Summary collapse
- #bottom_edge ⇒ Object
- #box_type ⇒ Object
- #centre ⇒ Object
- #centre_left ⇒ Object
- #centre_right ⇒ Object
- #containers ⇒ Object
- #corners ⇒ Object
- #disjoint?(other_box) ⇒ Boolean
- #height ⇒ Object
- #include_point?(point) ⇒ Boolean
- #left_edge ⇒ Object
- #lower_centre ⇒ Object
- #lower_left ⇒ Object
- #lower_right ⇒ Object
- #min_gap ⇒ Object
- #move_to(point, opts = {}) ⇒ Object
- #overlaps?(other_box) ⇒ Boolean
- #paths ⇒ Object
- #right_edge ⇒ Object
- #top_edge ⇒ Object
- #transform(transformer) ⇒ Object
- #translate(point) ⇒ Object
- #upper_centre ⇒ Object
- #upper_left ⇒ Object
- #upper_right ⇒ Object
- #width ⇒ Object
Instance Method Details
#bottom_edge ⇒ Object
72 73 74 |
# File 'lib/draught/boxlike.rb', line 72 def bottom_edge @bottom_edge ||= lower_left.y end |
#box_type ⇒ Object
20 21 22 |
# File 'lib/draught/boxlike.rb', line 20 def box_type raise NotImplementedError, "includers of Boxlike must implement #box_type" end |
#centre ⇒ Object
52 53 54 |
# 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 ⇒ Object
36 37 38 |
# 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 ⇒ Object
44 45 46 |
# File 'lib/draught/boxlike.rb', line 44 def centre_right @centre_right ||= lower_right.translate(Draught::Vector.new(0, height / 2.0)) end |
#containers ⇒ Object
100 101 102 |
# File 'lib/draught/boxlike.rb', line 100 def containers raise NotImplementedError end |
#corners ⇒ Object
56 57 58 |
# File 'lib/draught/boxlike.rb', line 56 def corners [lower_left, lower_right, upper_right, upper_left] end |
#disjoint?(other_box) ⇒ Boolean
108 109 110 |
# File 'lib/draught/boxlike.rb', line 108 def disjoint?(other_box) horizontal_disjoint?(other_box) || vertical_disjoint?(other_box) end |
#height ⇒ Object
16 17 18 |
# File 'lib/draught/boxlike.rb', line 16 def height raise NotImplementedError, "includers of Boxlike must implement #height" end |
#include_point?(point) ⇒ Boolean
112 113 114 |
# File 'lib/draught/boxlike.rb', line 112 def include_point?(point) horizontal_extent.include?(point.x) && vertical_extent.include?(point.y) end |
#left_edge ⇒ Object
60 61 62 |
# File 'lib/draught/boxlike.rb', line 60 def left_edge @left_edge ||= lower_left.x end |
#lower_centre ⇒ Object
40 41 42 |
# 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 ⇒ Object
8 9 10 |
# File 'lib/draught/boxlike.rb', line 8 def lower_left raise NotImplementedError, "includers of Boxlike must implement #lower_left" end |
#lower_right ⇒ Object
24 25 26 |
# File 'lib/draught/boxlike.rb', line 24 def lower_right @lower_right ||= lower_left.translate(Draught::Vector.new(width, 0)) end |
#min_gap ⇒ Object
116 117 118 |
# File 'lib/draught/boxlike.rb', line 116 def min_gap 0 end |
#move_to(point, opts = {}) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# 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) ⇒ Boolean
104 105 106 |
# File 'lib/draught/boxlike.rb', line 104 def overlaps?(other_box) !disjoint?(other_box) end |
#paths ⇒ Object
96 97 98 |
# File 'lib/draught/boxlike.rb', line 96 def paths raise NotImplementedError end |
#right_edge ⇒ Object
64 65 66 |
# File 'lib/draught/boxlike.rb', line 64 def right_edge @right_edge ||= upper_right.x end |
#top_edge ⇒ Object
68 69 70 |
# File 'lib/draught/boxlike.rb', line 68 def top_edge @top_edge ||= upper_right.y end |
#transform(transformer) ⇒ Object
92 93 94 |
# File 'lib/draught/boxlike.rb', line 92 def transform(transformer) raise NotImplementedError end |
#translate(point) ⇒ Object
88 89 90 |
# File 'lib/draught/boxlike.rb', line 88 def translate(point) raise NotImplementedError end |
#upper_centre ⇒ Object
48 49 50 |
# 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 ⇒ Object
32 33 34 |
# File 'lib/draught/boxlike.rb', line 32 def upper_left @upper_left ||= lower_left.translate(Draught::Vector.new(0, height)) end |
#upper_right ⇒ Object
28 29 30 |
# File 'lib/draught/boxlike.rb', line 28 def upper_right @upper_right ||= lower_left.translate(Draught::Vector.new(width, height)) end |
#width ⇒ Object
12 13 14 |
# File 'lib/draught/boxlike.rb', line 12 def width raise NotImplementedError, "includers of Boxlike must implement #width" end |