forked from xieyuheng/cell-complex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfour-ways-to-glue-a-square.js
93 lines (86 loc) · 2.6 KB
/
four-ways-to-glue-a-square.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
let cx = require ("../lib/cell-complex")
let hl = require ("../lib/homology")
let ut = require ("../lib/util")
class sphere_t extends cx.cell_complex_t {
constructor () {
super ({ dim: 2 })
this.attach_vertexes (["south", "middle", "north"])
this.attach_edge ("south_long", ["south", "middle"])
this.attach_edge ("north_long", ["middle", "north"])
this.attach_face ("surf", [
"south_long",
"north_long",
["north_long", "rev"],
["south_long", "rev"],
])
}
}
class torus_t extends cx.cell_complex_t {
constructor () {
super ({ dim: 2 })
this.attach_vertex ("origin")
this.attach_edge ("toro", ["origin", "origin"])
this.attach_edge ("polo", ["origin", "origin"])
this.attach_face ("surf", [
"toro",
"polo",
["toro", "rev"],
["polo", "rev"],
])
}
}
class klein_bottle_t extends cx.cell_complex_t {
constructor () {
super ({ dim: 2 })
this.attach_vertex ("origin")
this.attach_edge ("toro", ["origin", "origin"])
this.attach_edge ("cross", ["origin", "origin"])
this.attach_face ("surf", [
"toro",
"cross",
["toro", "rev"],
"cross",
])
}
}
class projective_plane_t extends cx.cell_complex_t {
constructor () {
super ({ dim: 2 })
this.attach_vertexes (["start", "end"])
this.attach_edge ("left_rim", ["start", "end"])
this.attach_edge ("right_rim", ["end", "start"])
this.attach_face ("surf", [
"left_rim", "right_rim",
"left_rim", "right_rim",
])
}
}
let report = {
"sphere": hl.report (new sphere_t ()),
"torus": hl.report (new torus_t ()),
"klein_bottle": hl.report (new klein_bottle_t ()),
"projective_plane": hl.report (new projective_plane_t ()),
}
ut.log (report)
let expected_report = {
sphere:
{ '0': { betti_number: 1, torsion_coefficients: [] },
'1': { betti_number: 0, torsion_coefficients: [] },
'2': { betti_number: 1, torsion_coefficients: [] },
euler_characteristic: 2 },
torus:
{ '0': { betti_number: 1, torsion_coefficients: [] },
'1': { betti_number: 2, torsion_coefficients: [] },
'2': { betti_number: 1, torsion_coefficients: [] },
euler_characteristic: 0 },
klein_bottle:
{ '0': { betti_number: 1, torsion_coefficients: [] },
'1': { betti_number: 1, torsion_coefficients: [ 2 ] },
'2': { betti_number: 0, torsion_coefficients: [] },
euler_characteristic: 0 },
projective_plane:
{ '0': { betti_number: 1, torsion_coefficients: [] },
'1': { betti_number: 0, torsion_coefficients: [ 2 ] },
'2': { betti_number: 0, torsion_coefficients: [] },
euler_characteristic: 1 }
}