Class: GridGenerator::BaseLine

Inherits:
Object
  • Object
show all
Defined in:
lib/grid_generator/base_line.rb

Constant Summary collapse

COLOURS =
{
  fill: "#d0d0d0",
  stroke: "#404040"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aObject (readonly)

Returns the value of attribute a.



12
13
14
# File 'lib/grid_generator/base_line.rb', line 12

def a
  @a
end

#bObject (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_svgObject



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

#x1Object



30
31
32
# File 'lib/grid_generator/base_line.rb', line 30

def x1
  a[0,0]
end

#x2Object



38
39
40
# File 'lib/grid_generator/base_line.rb', line 38

def x2
  b[0,0]
end

#y1Object



34
35
36
# File 'lib/grid_generator/base_line.rb', line 34

def y1
  a[1,0]
end

#y2Object



42
43
44
# File 'lib/grid_generator/base_line.rb', line 42

def y2
  b[1,0]
end