class CTioga2::Graphics::Types::FillUntil

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

Attributes

type[RW]

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

value[RW]

An accessory value (when necessary)

Public Class Methods

from_text(str) click to toggle source

Builds from text

# 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

Public Instance Methods

close_path(t, bounds, first, last) click to toggle source

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
# 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) click to toggle source

Returns the effective value of the

# 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?() click to toggle source

If there is actually a closing

# File lib/ctioga2/graphics/types/fill.rb, line 63
def fill?
  return @type != :none
end
horizontal?() click to toggle source

Wether we are closing with a horizontal line

# File lib/ctioga2/graphics/types/fill.rb, line 73
def horizontal?
  return (@type == :y || @type == :bottom || @type = :top)
end
vertical?() click to toggle source

Wether we are closing by a vertical line

# File lib/ctioga2/graphics/types/fill.rb, line 68
def vertical?
  return (@type == :x || @type == :left || @type = :right)
end