Class: SimplicialComplex::Complex
- Inherits:
-
Object
- Object
- SimplicialComplex::Complex
- Defined in:
- lib/simplicial_complex/complex.rb
Instance Method Summary collapse
-
#add_simplex(simplex) ⇒ Object
Adds a simplex to the complex.
-
#betti(dim) ⇒ Object
Computes the dim-Betti of the complex.
-
#dim ⇒ Object
Computes the dimension of the complex.
-
#initialize ⇒ Complex
constructor
A new instance of Complex.
-
#remove_simplex(simplex) ⇒ Object
Removes a simplex from the complex.
-
#simplices(dim) ⇒ Object
Computes the simplices of certain dimension.
-
#star(vertex) ⇒ Object
Outputs the star of a vertex.
- #to_json(*args) ⇒ Object
-
#vertices ⇒ Object
Outputs the vertices.
Constructor Details
#initialize ⇒ Complex
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 |
#dim ⇒ Object
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 |
#vertices ⇒ Object
Outputs the vertices
37 38 39 |
# File 'lib/simplicial_complex/complex.rb', line 37 def vertices simplices(0).map {|simplex| simplex.vertices[0]} end |