In Files

Parent

Namespace

Files

MathViz::Operation

n-ary operators

Public Class Methods

new(op, *operands) click to toggle source
# File lib/mathviz.rb, line 565
def initialize(op, *operands)
  super()
  @op = op
  @operands = operands.map{|x| MathViz.term(x)}
end

Public Instance Methods

collapse(parentop = nil) click to toggle source

Combine anonymous nodes with the same operator to simply graph

# File lib/mathviz.rb, line 634
def collapse(parentop = nil)
  @operands = @operands.flat_map {|x| x.collapse(@op)}
  if anonymous? && parentop == @op
    @operands
  else
    [self]
  end
end
color() click to toggle source

Graphviz node color; differentiates basic mathematical operators (+, -, *, /)

# File lib/mathviz.rb, line 587
def color
  case @op
  when :+; :green;
  when :-; :yellow;
  when :*; :blue;
  when :/; :cyan;
  else     :red;
  end
end
constant?() click to toggle source
# File lib/mathviz.rb, line 625
def constant?
  @operands.all?(&:constant?)
end
finite?() click to toggle source
# File lib/mathviz.rb, line 629
def finite?
  @operands.all?(&:finite?)
end
long() click to toggle source

Debugging method; returns string of names and values

# File lib/mathviz.rb, line 572
def long
  n = @name && (@name + " = ")
  "(#{n}#{@op} #{@operands.join(',')} = #{to_value})"
end
shape() click to toggle source

Graphviz node shape; differentiates comparison operators

# File lib/mathviz.rb, line 578
def shape
  if ([:>, :<, :>=, :<=, :&, :|, :==].include? @op)
    :ellipse
  else
    :box
  end
end
to_dot(g) click to toggle source

Extend Graphviz g with a representation of this object, and incoming connections

# File lib/mathviz.rb, line 608
def to_dot(g)
  super
  link_from(g, @operands.first, :normal, false)
  @operands.slice(1..-1).each {|x| link_from(g, x, :onormal, true)}
end
to_value() click to toggle source

Apply the operator to create the derived value.

# File lib/mathviz.rb, line 615
def to_value
  return MathViz::Infinity unless finite?
  @operands.map(&:to_value).reduce(&@op)
end
units() click to toggle source

Apply the operator to create the derived units.

# File lib/mathviz.rb, line 621
def units
  @operands.map(&:units).reduce(&@op)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.