Class: Okab::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/okab/page.rb,
sig/okab.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Path

Returns a new instance of Path.



9
# File 'lib/okab/page.rb', line 9

def initialize = (@commands = [])

Instance Attribute Details

#commands ⇒ Array[String] (readonly)

Returns the value of attribute commands.

Returns:

  • (Array[String])


7
8
9
# File 'lib/okab/page.rb', line 7

def commands
  @commands
end

Instance Method Details

#close ⇒ self

Returns:

  • (self)


13
# File 'lib/okab/page.rb', line 13

def close = command("h")

#curve_to(x1, y1, x2, y2, x3, y3) ⇒ self

Parameters:

  • x1 (Numeric)
  • y1 (Numeric)
  • x2 (Numeric)
  • y2 (Numeric)
  • x3 (Numeric)
  • y3 (Numeric)

Returns:

  • (self)


12
# File 'lib/okab/page.rb', line 12

def curve_to(x1, y1, x2, y2, x3, y3) = command("#{[x1, y1, x2, y2, x3, y3].map { |v| number(v) }.join(' ')} c")

#ellipse(x, y, width, height) ⇒ self

Parameters:

  • x (Numeric)
  • y (Numeric)
  • width (Numeric)
  • height (Numeric)

Returns:

  • (self)


16
17
18
19
20
21
22
23
24
25
# File 'lib/okab/page.rb', line 16

def ellipse(x, y, width, height)
  k = 0.5522847498307936
  cx, cy, rx, ry = x + width / 2.0, y + height / 2.0, width / 2.0, height / 2.0
  move_to(cx + rx, cy)
  curve_to(cx + rx, cy + k * ry, cx + k * rx, cy + ry, cx, cy + ry)
  curve_to(cx - k * rx, cy + ry, cx - rx, cy + k * ry, cx - rx, cy)
  curve_to(cx - rx, cy - k * ry, cx - k * rx, cy - ry, cx, cy - ry)
  curve_to(cx + k * rx, cy - ry, cx + rx, cy - k * ry, cx + rx, cy)
  close
end

#line_to(x, y) ⇒ self

Parameters:

  • x (Numeric)
  • y (Numeric)

Returns:

  • (self)


11
# File 'lib/okab/page.rb', line 11

def line_to(x, y) = command("#{number(x)} #{number(y)} l")

#move_to(x, y) ⇒ self

Parameters:

  • x (Numeric)
  • y (Numeric)

Returns:

  • (self)


10
# File 'lib/okab/page.rb', line 10

def move_to(x, y) = command("#{number(x)} #{number(y)} m")

#rect(x, y, width, height) ⇒ self

Parameters:

  • x (Numeric)
  • y (Numeric)
  • width (Numeric)
  • height (Numeric)

Returns:

  • (self)


14
# File 'lib/okab/page.rb', line 14

def rect(x, y, width, height) = command("#{[x, y, width, height].map { |v| number(v) }.join(' ')} re")