Newer
Older
/**
* A {@link Backend_Object} without any further properties known to us
*/
class Pure_Reference {
constructor(label, uri, type) {
this.label = label;
this.uri = uri;
this.type = type ? type : "none";
}
}
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/**
* A fact without any value known to us
*/
class Simple_Fact {
constructor(label, uri, representations, type) {
this.label = label;
this.uri = uri;
this.representations = representations instanceof MathMLElement ? { "default": representations } : representations;
this.type = type ? type : "none";
}
show_value(hint) {
if (hint in this.representations)
return this.representations[hint];
else
return this.representations["default"];
}
}
/**
* A simple point (x,y,z) in 3D space
*/
class Point_Fact {
/**
* @param x The x component of (x,y,z)
* @param y The y component of (x,y,z)
* @param z The z component of (x,y,z)
*/
constructor(label, uri, x, y, z) {
this.label = label;
this.uri = uri;
this.x = x;
this.y = y;
this.z = z;
this.type = "Point_Fact";
}
/**
* @returns "({@link x},{@link y},{@link z})" as MathML \<mrow\> element
*/
show_value() {
const show = document.createElement("mrow");
show.appendChild(document.createElement("mo"))
.textContent = "(";
show.appendChild(document.createElement("mn"))
.textContent = this.x.toString();
show.appendChild(document.createElement("mo"))
.textContent = ",";
show.appendChild(document.createElement("mn"))
.textContent = this.y.toString();
show.appendChild(document.createElement("mo"))
.textContent = ",";
show.appendChild(document.createElement("mn"))
.textContent = this.y.toString();
show.appendChild(document.createElement("mo"))
.textContent = ")";
return show;
}
}
class Angle_Fact {
constructor(label, uri, p1, p2, p3, angel, is_right_angle, _representations) {
this.label = label;
this.uri = uri;
this.p1 = p1;
this.p2 = p2;
this.p3 = p3;
this.angel = angel;
this.is_right_angle = is_right_angle;
this.type = "Angle_Fact";
if (_representations !== undefined) {
this.representations = _representations;
}
else {
this.representations = {};
let show = document.createElement("mn");
show.textContent = `${this.angel / 180 * Math.PI}`;
this.representations.radiants = show;
show = document.createElement("mrow");
show.appendChild(document.createElement("mi"))
.textContent = `${this.angel}`;
show.appendChild(document.createElement("mo"))
.textContent = "°";
this.representations;
}
}
show_value(hint) {
const show = document.createElement("mrow");
switch (hint) {
case "radiants":
case "Radiants":
case "rad":
return this.representations.radiants;
case "degrees": // Degrees is the default
case "Degrees":
case "deg":
default:
show.appendChild(document.createElement("mi"))
.textContent = `${this.angel}`;
show.appendChild(document.createElement("mo"))
.textContent = "°";
break;
}
return show;
}
}
class Line_Fact {
constructor(label, uri, p1, p2, _representations) {
this.label = label;
this.uri = uri;
this.p1 = p1;
this.p2 = p2;
this.type = "Line_Fact";
if (_representations !== undefined) {
this.representations = _representations;
}
else {
this.representations = {};
let show = document.createElement("mrow");
show.appendChild(document.createElement("mtext"))
.textContent = `The Line though `;
show.appendChild(this.p1.label);
show.appendChild(document.createElement("mtext"))
.textContent = ` and `;
show.appendChild(this.p1.label);
this.representations["Semantic Definition"] = show;
show = document.createElement("mrow");
}
}
/**
*
* @param hint possible values:
* - "Semantic Definition" : "Line through {@link p1} and {@link p2}"
*
* !!Not implemented yet!!
* - "Point vector"
* - "Parametric equation"
* - "Hesse normal form"
* @returns Dependent on {@link hint}
*/
show_value(hint) {
switch (hint) {
case "Point vector":
case "Parametric equation":
case "Hesse normal form":
throw new Error("Not implemented.");
break;
case "Semantic Definition":
default:
return this.representations["Semantic Definition"];
}
}
}
class LineSegment_Fact extends Line_Fact {
constructor(label, uri, p1, p2, length, _representations) {
super(label, uri, p1, p2, _representations);
this.label = label;
this.uri = uri;
this.p1 = p1;
this.p2 = p2;
this.length = length;
this.type = "LineSegment_Fact";
}
show_value() {
const show = document.createElement("mn");
show.textContent = this.length.toString();
return show;
}
}
class Ray_Fact extends Line_Fact {
constructor(label, uri, p1, p2, _representations) {
super(label, uri, p1, p2, _representations);
this.label = label;
this.uri = uri;
this.p1 = p1;
this.p2 = p2;
this.type = "Ray_Fact";
}
}
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//#endregion Facts
/**
* A Slot is an interface that can stand in for either
* - a {@link Fact}, or
* - the {@link Backend_Object} used to define the {@link Scroll} (in the backend)
*
* depending on what is needed.
*
* If all Slots of a {@link Scroll} are assigned, it can compute its {@link Scroll.acquiredFacts}.
*/
class Slot {
/**
* @param default_label The default label of the Slot. Fallback if no Fact is assigned.
* @param uri The uri of the Slot
* @param type The expected type of the assigned Fact
* @param assignedFact The Fact assigned to this Slot (may not exist yet)
*/
constructor(default_label, uri, type, assignedFact) {
this.default_label = default_label;
this.uri = uri;
this.type = type;
this.assignedFact = assignedFact;
}
/**
* The MathML element to display when this Slot is referenced.
*
* This is either the label of the {@link assignedFact}, or {@link default_label} if the former doesn't exist.
*/
get label() {
if (this.assignedFact) {
return this.assignedFact.label;
}
else {
return this.default_label;
}
}
}
/**
* A Scroll, as it is implemented in the backend.
*
* Can do fancy stuff elsewhere, here we only want display its {@link description} and (possibly) {@link depiction}.
* Both will reference the {@link slots}, and need dynamic adaption to the {@link Fact}s assigned to them.
* The {@link acquiredFacts} referenced do not change, but they are semantically important and deserve special treatment.
*/
class Scroll {
constructor(label, uri, slots, acquiredFacts, description, depiction) {
this.label = label;
this.uri = uri;
this.slots = slots;
this.acquiredFacts = acquiredFacts;
this.description = description;
this.depiction = depiction;
this.type = "Scroll";
}
}
function isScroll(s) {
return s.type === "Scroll";
}