Class: CTioga2::Graphics::Types::FillUntil

Inherits:
Object
  • Object
show all
Defined in:
lib/ctioga2/graphics/types/fill.rb

Overview

This class provides a way to close a path in order to fill a curve.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#typeObject

The type of closing: :top, :bottom, :left, :right, :x, :y, :close, :xy or :none



29
30
31
# File 'lib/ctioga2/graphics/types/fill.rb', line 29

def type
  @type
end

#valueObject

An accessory value (when necessary)



32
33
34
# File 'lib/ctioga2/graphics/types/fill.rb', line 32

def value
  @value
end

Class Method Details

.from_text(str) ⇒ Object

Builds from text



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ctioga2/graphics/types/fill.rb', line 35

def self.from_text(str)
  ret = FillUntil.new
  case str
  when /^\s*(left|right|top|bottom)\s*$/
    ret.type = $1.downcase.to_sym
  when /^\s*axis|xaxis\s*$/
    ret.type = :y
    ret.value = 0
  when /^\s*yaxis\s*$/
    ret.type = :x
    ret.value = 0
  when /^\s*(x|y)\s*[:=]\s*(.*)$/
    ret.type = $1.downcase.to_sym
    ret.value = $2.to_f
  when /^\s*close\s*$/
    ret.type = :close
  when /^\s*xy\s*[:=]\s*(.*)$/
    ret.type = :xy
    ret.value = Point.from_text($1)
  else
    ret.type = :y
    ret.value = str.to_f
  end

  return ret
end

Instance Method Details

#close_path(t, bounds, first, last) ⇒ Object

Closes the current path according to the current style, based on:

* _bounds_, the boundaries of the plot
* _first_, the first point ([x, y])
* _last_, the last point


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ctioga2/graphics/types/fill.rb', line 93

def close_path(t, bounds, first, last)
  tp = @type
  target = effective_value(bounds)

  case tp
  when :none
    raise "Close the path !"
  when :x, :left, :right
    t.append_point_to_path(target, last[1])
    t.append_point_to_path(target, first[1])
  when :y, :bottom, :top
    t.append_point_to_path(last[0], target)
    t.append_point_to_path(first[0], target)
  when :xy
    t.append_point_to_path(* target.to_figure_xy(t))
  when :close
  else
    raise "Should not be here"
  end
  t.close_path
end

#effective_value(bounds) ⇒ Object

Returns the effective value of the



78
79
80
81
82
83
84
85
86
87
# File 'lib/ctioga2/graphics/types/fill.rb', line 78

def effective_value(bounds)
  case @type
  when :bottom, :top
    return bounds.send(@type)
  when :left, :right
    return bounds.send(@type)
  else
    return @value
  end
end

#fill?Boolean

If there is actually a closing

Returns:

  • (Boolean)


63
64
65
# File 'lib/ctioga2/graphics/types/fill.rb', line 63

def fill?
  return @type != :none
end

#horizontal?Boolean

Wether we are closing with a horizontal line

Returns:

  • (Boolean)


73
74
75
# File 'lib/ctioga2/graphics/types/fill.rb', line 73

def horizontal?
  return (@type == :y || @type == :bottom || @type = :top)
end

#vertical?Boolean

Wether we are closing by a vertical line

Returns:

  • (Boolean)


68
69
70
# File 'lib/ctioga2/graphics/types/fill.rb', line 68

def vertical?
  return (@type == :x || @type == :left || @type = :right)
end