Class: SimplicialComplex::Complex

Inherits:
Object
  • Object
show all
Defined in:
lib/simplicial_complex/complex.rb

Instance Method Summary collapse

Constructor Details

#initializeComplex

Returns a new instance of Complex.



3
4
5
# File 'lib/simplicial_complex/complex.rb', line 3

def initialize
  @simplices = Array.new
end

Instance Method Details

#add_simplex(simplex) ⇒ Object

Adds a simplex to the complex



8
9
10
11
12
13
14
# File 'lib/simplicial_complex/complex.rb', line 8

def add_simplex(simplex)
  (0..simplex.dim).each do |d|
    simplex.faces(d).each do |face|
      @simplices << face unless @simplices.include?(face)
    end
  end
end

#betti(dim) ⇒ Object

Computes the dim-Betti of the complex



47
48
49
# File 'lib/simplicial_complex/complex.rb', line 47

def betti(dim)
  
end

#dimObject

Computes the dimension of the complex



22
23
24
# File 'lib/simplicial_complex/complex.rb', line 22

def dim
  @simplices.map {|simplex| simplex.dim}.max
end

#remove_simplex(simplex) ⇒ Object

Removes a simplex from the complex



17
18
19
# File 'lib/simplicial_complex/complex.rb', line 17

def remove_simplex(simplex)
  @simplices.delete(simplex)
end

#simplices(dim) ⇒ Object

Computes the simplices of certain dimension



27
28
29
30
31
32
33
# File 'lib/simplicial_complex/complex.rb', line 27

def simplices(dim)
  simplices = Array.new
  @simplices.each do |simplex|
    simplices << simplex if simplex.dim == dim
  end
  simplices
end

#star(vertex) ⇒ Object

Outputs the star of a vertex



42
43
44
# File 'lib/simplicial_complex/complex.rb', line 42

def star(vertex)
  
end

#to_json(*args) ⇒ Object



51
52
53
# File 'lib/simplicial_complex/complex.rb', line 51

def to_json(*args)
  {dim: dim, simplices: @simplices}.to_json(*args)
end

#verticesObject

Outputs the vertices



37
38
39
# File 'lib/simplicial_complex/complex.rb', line 37

def vertices
  simplices(0).map {|simplex| simplex.vertices[0]}
end