class SimplicialComplex::Simplex

Attributes

dim[R]
vertices[R]

Public Class Methods

new(dim, vertices = nil) click to toggle source

Constructor method

# File lib/simplicial_complex/simplex.rb, line 7
def initialize(dim, vertices = nil)
  @dim      = dim
  @vertices = vertices || Array.new(@dim + 1, Vertex.new(nil)) 
end

Public Instance Methods

==(other) click to toggle source
# File lib/simplicial_complex/simplex.rb, line 16
def ==(other)
  @vertices.to_set == other.vertices.to_set
end
face?(other) click to toggle source
# File lib/simplicial_complex/simplex.rb, line 12
def face?(other)
  @vertices.to_set <= other.vertices.to_set
end
faces(dim = @dim -1) click to toggle source

Computes the faces of dimension dim

# File lib/simplicial_complex/simplex.rb, line 21
def faces(dim = @dim -1)
  faces = Array.new
  
  if dim < 0 || dim > @dim
    puts 'Faces of this dimension do not exist.'
    
  elsif dim == @dim
    faces << self
    
  else
    @vertices.combination(dim+1) do |combination|
    faces << Simplex.new(dim, combination)
    end
end
  faces
end
to_json(*args) click to toggle source
# File lib/simplicial_complex/simplex.rb, line 38
def to_json(*args)
  {dim: @dim, vertices: @vertices}.to_json(*args)
end