In Files

Parent

Included Modules

Files

MathViz::Term

Base class for graphable objects. It also contain the operators, which return MathViz::Operation subclasses.

Attributes

name[RW]

Graphviz node name; see MathViz::Term#name_terms!

Public Class Methods

binop(op) click to toggle source

Define op as a binary operator

# File lib/mathviz.rb, line 347
def self.binop(op)
  define_method(op) do |c|
    MathViz::Operation.new(op, self, c)
  end
end
list_terms(env) click to toggle source

Return a list of all MathViz::Terms accessible from a binding

# File lib/mathviz.rb, line 335
def self.list_terms(env)
  eval("local_variables", env).map { |var|
    value = eval(var.to_s, env)
    if (value.kind_of?(MathViz::Term))
      value
    else
      nil
    end
  }.compact
end
name_terms!(env) click to toggle source

Assign names to named MathViz::Terms, so the name can be effiently looked up from the MathViz::Term object.

# File lib/mathviz.rb, line 325
def self.name_terms!(env)
  eval("local_variables", env).each do |var|
    value = eval(var.to_s, env)
    if value.respond_to? :name=
      value.name = var.to_s
    end
  end
end
unop(op) click to toggle source

Define op as an unary operator

# File lib/mathviz.rb, line 354
def self.unop(op)
  define_method(op) do
    MathViz::Operation::Unary.new(op, self)
  end
end

Public Instance Methods

& click to toggle source
# File lib/mathviz.rb, line 494
binop :&
* click to toggle source
# File lib/mathviz.rb, line 470
binop :*
+ click to toggle source
# File lib/mathviz.rb, line 464
binop :+
- click to toggle source
# File lib/mathviz.rb, line 467
binop :-
/ click to toggle source
# File lib/mathviz.rb, line 473
binop :/
< click to toggle source
# File lib/mathviz.rb, line 485
binop :<
<= click to toggle source
# File lib/mathviz.rb, line 488
binop :<=
== click to toggle source
# File lib/mathviz.rb, line 500
binop :==
> click to toggle source
# File lib/mathviz.rb, line 482
binop :>
>= click to toggle source
# File lib/mathviz.rb, line 491
binop :>=
anonymous?() click to toggle source

Only valid after names have been assigned, which means not during graph construction

# File lib/mathviz.rb, line 430
def anonymous?
  !@name
end
ceil click to toggle source
# File lib/mathviz.rb, line 460
unop :ceil
collapse(parentop = nil) click to toggle source

Stub

# File lib/mathviz.rb, line 435
def collapse(parentop = nil)
  [self]
end
color() click to toggle source

Graphviz node color

# File lib/mathviz.rb, line 404
def color
  :black
end
data() click to toggle source

A string representation of the node’s data, typically calculated value with units.

# File lib/mathviz.rb, line 368
def data
  f = to_value
  if (f.kind_of?(TrueClass) || f.kind_of?(FalseClass))
    f.to_s
  elsif (!f.respond_to? :finite?)
    f.to_s + with_units
  elsif (!f.finite?)
    MathViz::Infinity.to_s
  elsif (f.floor == f)
    f.to_i.to_s + with_units
  else
    f.to_s + with_units
  end
end
floor click to toggle source
# File lib/mathviz.rb, line 457
unop :floor
generated?() click to toggle source

Helper to avoid duplicate nodes

# File lib/mathviz.rb, line 425
def generated?
  !name.nil?
end
label() click to toggle source

Text label for graph nodes

# File lib/mathviz.rb, line 390
def label
  if (@name)
    [data, node].join("\n")
  else
    data
  end
end
max click to toggle source
# File lib/mathviz.rb, line 476
binop :max
min click to toggle source
# File lib/mathviz.rb, line 479
binop :min
shape() click to toggle source

Graphviz node shape

# File lib/mathviz.rb, line 399
def shape
  :ellipse
end
style() click to toggle source

Graphviz node line style

# File lib/mathviz.rb, line 409
def style
  if anonymous?
    :dotted
  elsif constant?
    :solid
  else
    :dashed
  end
end
to_dot(g) click to toggle source

Extend Graphviz g with a representation of this object

# File lib/mathviz.rb, line 420
def to_dot(g)
  g[node] [:label => label, :shape => shape, :color => color, :style => style]
end
to_i() click to toggle source
# File lib/mathviz.rb, line 383
def to_i
  f = to_value
  return MathViz::Infinity unless f.finite?
  f.to_i
end
to_s() click to toggle source
# File lib/mathviz.rb, line 363
def to_s
  @name || anon
end
| click to toggle source
# File lib/mathviz.rb, line 497
binop :|

[Validate]

Generated with the Darkfish Rdoc Generator 2.