Class: GridGenerator::BaseLine
- Inherits:
-
Object
- Object
- GridGenerator::BaseLine
- Defined in:
- lib/grid_generator/base_line.rb
Constant Summary collapse
- COLOURS =
{ fill: "#d0d0d0", stroke: "#404040" }
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
Instance Method Summary collapse
- #+(offset) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(a:, b:) ⇒ BaseLine
constructor
A new instance of BaseLine.
- #to_svg ⇒ Object
- #x1 ⇒ Object
- #x2 ⇒ Object
- #y1 ⇒ Object
- #y2 ⇒ Object
Constructor Details
#initialize(a:, b:) ⇒ BaseLine
Returns a new instance of BaseLine.
8 9 10 |
# File 'lib/grid_generator/base_line.rb', line 8 def initialize(a:, b:) @a, @b = a, b end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
12 13 14 |
# File 'lib/grid_generator/base_line.rb', line 12 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
12 13 14 |
# File 'lib/grid_generator/base_line.rb', line 12 def b @b end |
Instance Method Details
#+(offset) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/grid_generator/base_line.rb', line 20 def +(offset) if offset.class == Matrix new_a = a + offset new_b = b + offset self.class.new(a: new_a, b: new_b) else raise ArgumentError, "Offset must be Matrix" end end |
#==(other) ⇒ Object
14 15 16 17 18 |
# File 'lib/grid_generator/base_line.rb', line 14 def ==(other) self.class == other.class && self.a == other.a && self.b == other.b end |
#to_svg ⇒ Object
46 47 48 |
# File 'lib/grid_generator/base_line.rb', line 46 def to_svg "<line x1=\"#{x1}\" y1=\"#{y1}\" x2=\"#{x2}\" y2=\"#{y2}\" style=\"stroke:#{COLOURS[:stroke]};stroke-width:1\" />" end |
#x1 ⇒ Object
30 31 32 |
# File 'lib/grid_generator/base_line.rb', line 30 def x1 a[0,0] end |
#x2 ⇒ Object
38 39 40 |
# File 'lib/grid_generator/base_line.rb', line 38 def x2 b[0,0] end |
#y1 ⇒ Object
34 35 36 |
# File 'lib/grid_generator/base_line.rb', line 34 def y1 a[1,0] end |
#y2 ⇒ Object
42 43 44 |
# File 'lib/grid_generator/base_line.rb', line 42 def y2 b[1,0] end |