jsxgraph 1.9.1 → 1.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/distrib/docs.zip +0 -0
  3. package/distrib/geogebra.min.js +2 -2
  4. package/distrib/geonext.min.js +2 -2
  5. package/distrib/intergeo.min.js +2 -2
  6. package/distrib/jsxgraph.css +1 -1
  7. package/distrib/jsxgraph.zip +0 -0
  8. package/distrib/jsxgraphcore.js +3 -3
  9. package/distrib/jsxgraphcore.mjs +3 -3
  10. package/distrib/jsxgraphcore.mjs.map +1 -1
  11. package/distrib/jsxgraphsrc.js +2328 -1508
  12. package/distrib/jsxgraphsrc.mjs +2328 -1508
  13. package/distrib/jsxgraphsrc.mjs.map +1 -1
  14. package/distrib/sketch.min.js +3 -3
  15. package/package.json +4 -4
  16. package/src/3d/box3d.js +4 -1
  17. package/src/3d/circle3d.js +10 -9
  18. package/src/3d/curve3d.js +2 -0
  19. package/src/3d/linspace3d.js +18 -55
  20. package/src/3d/point3d.js +6 -0
  21. package/src/3d/polygon3d.js +1 -0
  22. package/src/3d/sphere3d.js +47 -43
  23. package/src/3d/surface3d.js +1 -0
  24. package/src/3d/view3d.js +1504 -1067
  25. package/src/base/board.js +176 -55
  26. package/src/base/circle.js +3 -1
  27. package/src/base/constants.js +1 -1
  28. package/src/base/curve.js +1 -0
  29. package/src/base/element.js +38 -30
  30. package/src/base/line.js +93 -105
  31. package/src/base/polygon.js +1 -1
  32. package/src/base/text.js +5 -1
  33. package/src/element/button.js +62 -12
  34. package/src/element/checkbox.js +6 -2
  35. package/src/element/grid.js +6 -6
  36. package/src/element/input.js +9 -6
  37. package/src/element/slider.js +42 -39
  38. package/src/jsxgraph.js +5 -3
  39. package/src/math/geometry.js +86 -64
  40. package/src/math/math.js +47 -5
  41. package/src/options.js +45 -0
  42. package/src/options3d.js +82 -5
  43. package/src/parser/jessiecode.js +2 -1
  44. package/src/parser/prefix.js +8 -1
  45. package/src/reader/sketch.js +106 -0
  46. package/src/renderer/svg.js +16 -6
  47. package/src/utils/env.js +2 -2
  48. package/src/utils/type.js +27 -15
@@ -209,54 +209,54 @@ JXG.extend(
209
209
  // `focusFn(1)`, that evaluate to the projections of the front and back
210
210
  // points of the sphere, respectively.
211
211
  focusFn: function (sgn) {
212
- const that = this;
212
+ var that = this;
213
213
 
214
214
  return function () {
215
- const camDir = that.view.cameraTransform[3],
216
- r = that.Radius();
215
+ var camDir = that.view.boxToCam[3],
216
+ r = that.Radius();
217
217
 
218
218
  return that.view.project3DTo2D([
219
- that.center.X() + sgn*r*camDir[1],
220
- that.center.Y() + sgn*r*camDir[2],
221
- that.center.Z() + sgn*r*camDir[3]
219
+ that.center.X() + sgn * r * camDir[1],
220
+ that.center.Y() + sgn * r * camDir[2],
221
+ that.center.Z() + sgn * r * camDir[3]
222
222
  ]).slice(1, 3);
223
223
  };
224
224
  },
225
225
 
226
226
  innerVertexFn: function () {
227
- const that = this;
228
-
229
- return function() {
230
- const view = that.view,
231
- p = view.worldToView(that.center.coords, false),
232
- distOffAxis = Math.sqrt(p[0]*p[0] + p[1]*p[1]),
233
- cam = view.cameraTransform,
234
- inward = [
235
- -(p[0]*cam[1][1] + p[1]*cam[2][1]) / distOffAxis,
236
- -(p[0]*cam[1][2] + p[1]*cam[2][2]) / distOffAxis,
237
- -(p[0]*cam[1][3] + p[1]*cam[2][3]) / distOffAxis
238
- ],
239
- r = that.Radius(),
240
- angleOffAxis = Math.atan(-distOffAxis / p[2]),
241
- steepness = Math.acos(r / Mat.norm(p)),
242
- lean = angleOffAxis + steepness,
243
- cos_lean = Math.cos(lean),
244
- sin_lean = Math.sin(lean);
227
+ var that = this;
228
+
229
+ return function () {
230
+ var view = that.view,
231
+ p = view.worldToFocal(that.center.coords, false),
232
+ distOffAxis = Mat.hypot(p[0], p[1]),
233
+ cam = view.boxToCam,
234
+ inward = [
235
+ -(p[0] * cam[1][1] + p[1] * cam[2][1]) / distOffAxis,
236
+ -(p[0] * cam[1][2] + p[1] * cam[2][2]) / distOffAxis,
237
+ -(p[0] * cam[1][3] + p[1] * cam[2][3]) / distOffAxis
238
+ ],
239
+ r = that.Radius(),
240
+ angleOffAxis = Math.atan(-distOffAxis / p[2]),
241
+ steepness = Math.acos(r / Mat.norm(p)),
242
+ lean = angleOffAxis + steepness,
243
+ cos_lean = Math.cos(lean),
244
+ sin_lean = Math.sin(lean);
245
245
 
246
246
  return view.project3DTo2D([
247
- that.center.X() + r * (sin_lean*inward[0] + cos_lean*cam[3][1]),
248
- that.center.Y() + r * (sin_lean*inward[1] + cos_lean*cam[3][2]),
249
- that.center.Z() + r * (sin_lean*inward[2] + cos_lean*cam[3][3])
247
+ that.center.X() + r * (sin_lean * inward[0] + cos_lean * cam[3][1]),
248
+ that.center.Y() + r * (sin_lean * inward[1] + cos_lean * cam[3][2]),
249
+ that.center.Z() + r * (sin_lean * inward[2] + cos_lean * cam[3][3])
250
250
  ]);
251
251
  };
252
252
  },
253
253
 
254
254
  buildCentralProjection: function () {
255
- const view = this.view,
256
- auxStyle = {visible: false, withLabel: false},
257
- frontFocus = view.create('point', this.focusFn(-1), auxStyle),
258
- backFocus = view.create('point', this.focusFn(1), auxStyle),
259
- innerVertex = view.create('point', this.innerVertexFn(view), auxStyle);
255
+ var view = this.view,
256
+ auxStyle = { visible: false, withLabel: false },
257
+ frontFocus = view.create('point', this.focusFn(-1), auxStyle),
258
+ backFocus = view.create('point', this.focusFn(1), auxStyle),
259
+ innerVertex = view.create('point', this.innerVertexFn(view), auxStyle);
260
260
 
261
261
  this.aux2D = [frontFocus, backFocus, innerVertex];
262
262
  this.element2D = view.create('ellipse', this.aux2D, this.visProp);
@@ -264,14 +264,13 @@ JXG.extend(
264
264
 
265
265
  buildParallelProjection: function () {
266
266
  // The parallel projection of a sphere is a circle
267
- const
268
- that = this,
267
+ var that = this,
269
268
  center2d = function () {
270
- const c3d = [1, that.center.X(), that.center.Y(), that.center.Z()];
269
+ var c3d = [1, that.center.X(), that.center.Y(), that.center.Z()];
271
270
  return that.view.project3DTo2D(c3d);
272
271
  },
273
272
  radius2d = function () {
274
- const boxSize = that.view.bbox3D[0][1] - that.view.bbox3D[0][0];
273
+ var boxSize = that.view.bbox3D[0][1] - that.view.bbox3D[0][0];
275
274
  return that.Radius() * that.view.size[0] / boxSize;
276
275
  };
277
276
 
@@ -286,11 +285,15 @@ JXG.extend(
286
285
  // replace our 2D representation with a new one that's consistent with
287
286
  // the view's current projection type
288
287
  rebuildProjection: function () {
288
+ var i;
289
+
289
290
  // remove the old 2D representation from the scene tree
290
291
  if (this.element2D) {
291
292
  this.view.board.removeObject(this.element2D);
292
- for (let i in this.aux2D) {
293
- this.view.board.removeObject(this.aux2D[i]);
293
+ for (i in this.aux2D) {
294
+ if (this.aux2D.hasOwnProperty(i)) {
295
+ this.view.board.removeObject(this.aux2D[i]);
296
+ }
294
297
  }
295
298
  }
296
299
 
@@ -307,6 +310,7 @@ JXG.extend(
307
310
  // attach the new 2D representation to the scene tree
308
311
  this.addChild(this.element2D);
309
312
  this.inherits.push(this.element2D);
313
+ this.element2D.view = this.view;
310
314
  }
311
315
  }
312
316
  );
@@ -463,11 +467,11 @@ JXG.createSphere3D = function (board, parents, attributes) {
463
467
  } else {
464
468
  throw new Error(
465
469
  "JSXGraph: Can't create sphere3d with parent types '" +
466
- typeof parents[1] +
467
- "' and '" +
468
- typeof parents[2] +
469
- "'." +
470
- "\nPossible parent types: [point,point], [point,number], [point,function]"
470
+ typeof parents[1] +
471
+ "' and '" +
472
+ typeof parents[2] +
473
+ "'." +
474
+ "\nPossible parent types: [point,point], [point,number], [point,function]"
471
475
  );
472
476
  }
473
477
 
@@ -257,6 +257,7 @@ JXG.createParametricSurface3D = function (board, parents, attributes) {
257
257
 
258
258
  attr = el.setAttr2D(attr);
259
259
  el.element2D = view.create("curve", [[], []], attr);
260
+ el.element2D.view = view;
260
261
 
261
262
  /**
262
263
  * @class