@vived/app 2.14.0 → 2.15.3

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 (62) hide show
  1. package/lib/Entities/Babylon.js +1 -1
  2. package/lib/Entities/FocusCamera.js +9 -9
  3. package/lib/Entities/MemoizedBoolean.d.ts +1 -0
  4. package/lib/Entities/MemoizedBoolean.js +3 -0
  5. package/lib/Entities/MemoizedNumber.d.ts +1 -0
  6. package/lib/Entities/MemoizedNumber.js +3 -0
  7. package/lib/Entities/MemoizedString.d.ts +1 -0
  8. package/lib/Entities/MemoizedString.js +3 -0
  9. package/lib/Entities/MemoizedVector2.d.ts +1 -0
  10. package/lib/Entities/MemoizedVector2.js +4 -1
  11. package/lib/Entities/MemoizedVector3.d.ts +1 -0
  12. package/lib/Entities/MemoizedVector3.js +4 -1
  13. package/lib/Entities/QuestionChallenge.d.ts +21 -0
  14. package/lib/Entities/QuestionChallenge.js +103 -0
  15. package/lib/Entities/QuestionChallengeAnswer.d.ts +32 -0
  16. package/lib/Entities/QuestionChallengeAnswer.js +51 -0
  17. package/lib/Entities/index.d.ts +2 -0
  18. package/lib/Entities/index.js +2 -0
  19. package/lib/PresentationManagers/QuestionChallenge/AuthorQuestionChallengeAnswerPM.d.ts +24 -0
  20. package/lib/PresentationManagers/QuestionChallenge/AuthorQuestionChallengeAnswerPM.js +65 -0
  21. package/lib/PresentationManagers/QuestionChallenge/AuthorQuestionChallengePM.d.ts +17 -0
  22. package/lib/PresentationManagers/QuestionChallenge/AuthorQuestionChallengePM.js +46 -0
  23. package/lib/PresentationManagers/QuestionChallenge/QuestionChallengeAnswerPM.d.ts +17 -0
  24. package/lib/PresentationManagers/QuestionChallenge/QuestionChallengeAnswerPM.js +51 -0
  25. package/lib/PresentationManagers/QuestionChallenge/QuestionChallengePM.d.ts +15 -0
  26. package/lib/PresentationManagers/QuestionChallenge/QuestionChallengePM.js +34 -0
  27. package/lib/PresentationManagers/QuestionChallenge/index.d.ts +4 -0
  28. package/lib/PresentationManagers/QuestionChallenge/index.js +16 -0
  29. package/lib/PresentationManagers/index.d.ts +1 -0
  30. package/lib/PresentationManagers/index.js +1 -0
  31. package/lib/UseCases/FocusCamera/BumpDollyFocusCamera.js +3 -3
  32. package/lib/UseCases/FocusCamera/PinchDollyFocusCamera.js +3 -3
  33. package/lib/UseCases/FocusCamera/PixelDollyFocusCamera.js +3 -3
  34. package/lib/UseCases/FocusCamera/PixelOrbitFocusCamera.js +1 -1
  35. package/lib/UseCases/FocusCamera/PixelPlanePanFocusCamera.js +1 -1
  36. package/lib/UseCases/QuestionChallenge/SerializeQuestionChallenge.d.ts +25 -0
  37. package/lib/UseCases/QuestionChallenge/SerializeQuestionChallenge.js +70 -0
  38. package/lib/UseCases/QuestionChallenge/index.d.ts +4 -0
  39. package/lib/UseCases/QuestionChallenge/index.js +16 -0
  40. package/lib/UseCases/QuestionChallenge/setQuesionChallengeAnswerFeedback.d.ts +2 -0
  41. package/lib/UseCases/QuestionChallenge/setQuesionChallengeAnswerFeedback.js +16 -0
  42. package/lib/UseCases/QuestionChallenge/setQuesionChallengeAnswerText.d.ts +2 -0
  43. package/lib/UseCases/QuestionChallenge/setQuesionChallengeAnswerText.js +16 -0
  44. package/lib/UseCases/QuestionChallenge/toggleQuesionChallengeAnswerIsCorrect.d.ts +2 -0
  45. package/lib/UseCases/QuestionChallenge/toggleQuesionChallengeAnswerIsCorrect.js +16 -0
  46. package/lib/UseCases/index.d.ts +1 -0
  47. package/lib/UseCases/index.js +1 -0
  48. package/lib/ValueObjects/Angle.d.ts +2 -2
  49. package/lib/ValueObjects/Angle.js +2 -2
  50. package/lib/ValueObjects/Color.d.ts +4 -8
  51. package/lib/ValueObjects/Color.js +9 -21
  52. package/lib/ValueObjects/LineSegment2D.d.ts +5 -6
  53. package/lib/ValueObjects/LineSegment2D.js +46 -30
  54. package/lib/ValueObjects/ParametricLine.d.ts +1 -1
  55. package/lib/ValueObjects/ParametricLine.js +8 -8
  56. package/lib/ValueObjects/ParametricPlane.d.ts +1 -1
  57. package/lib/ValueObjects/ParametricPlane.js +10 -10
  58. package/lib/ValueObjects/Vector2.d.ts +11 -11
  59. package/lib/ValueObjects/Vector2.js +14 -14
  60. package/lib/ValueObjects/Vector3.d.ts +16 -16
  61. package/lib/ValueObjects/Vector3.js +18 -18
  62. package/package.json +1 -1
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QuestionChallengePM = exports.defaultQuestionChallengeVM = void 0;
4
+ exports.defaultQuestionChallengeVM = {
5
+ text: "",
6
+ answers: [],
7
+ gotItRight: false,
8
+ tries: 0,
9
+ };
10
+ class QuestionChallengePM {
11
+ constructor(questionChallengeEntity, updateView) {
12
+ this.questionChallengeEntity = questionChallengeEntity;
13
+ this.updateView = updateView;
14
+ this.dispose = () => {
15
+ this.questionChallengeEntity.removeObserver(this.doUpdateView);
16
+ };
17
+ this.doUpdateView = () => {
18
+ const { tries, text } = this.questionChallengeEntity;
19
+ const answers = this.questionChallengeEntity
20
+ .getAllAnswers()
21
+ .map((ans) => ans.id);
22
+ const vm = {
23
+ text,
24
+ tries,
25
+ gotItRight: this.questionChallengeEntity.gotItRight,
26
+ answers,
27
+ };
28
+ this.updateView(vm);
29
+ };
30
+ this.doUpdateView();
31
+ this.questionChallengeEntity.addObserver(this.doUpdateView);
32
+ }
33
+ }
34
+ exports.QuestionChallengePM = QuestionChallengePM;
@@ -0,0 +1,4 @@
1
+ export * from "./QuestionChallengePM";
2
+ export * from "./QuestionChallengeAnswerPM";
3
+ export * from "./AuthorQuestionChallengeAnswerPM";
4
+ export * from "./AuthorQuestionChallengePM";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./QuestionChallengePM"), exports);
14
+ __exportStar(require("./QuestionChallengeAnswerPM"), exports);
15
+ __exportStar(require("./AuthorQuestionChallengeAnswerPM"), exports);
16
+ __exportStar(require("./AuthorQuestionChallengePM"), exports);
@@ -4,3 +4,4 @@ export * from "./ShowBabylonInspectorPM";
4
4
  export * from "./HasRedoPM";
5
5
  export * from "./HasUndoPM";
6
6
  export * from "./FocusCameraPM";
7
+ export * from "./QuestionChallenge";
@@ -16,3 +16,4 @@ __exportStar(require("./ShowBabylonInspectorPM"), exports);
16
16
  __exportStar(require("./HasRedoPM"), exports);
17
17
  __exportStar(require("./HasUndoPM"), exports);
18
18
  __exportStar(require("./FocusCameraPM"), exports);
19
+ __exportStar(require("./QuestionChallenge"), exports);
@@ -26,10 +26,10 @@ class BumpDollyFocusCamera {
26
26
  this.focusCamera.radius = this.initialRadius + range * percent;
27
27
  if (this.pickPoint !== undefined) {
28
28
  const percentChange = this.focusCamera.radius / currentRadius;
29
- let pickToTarget = ValueObjects_1.Vector3.subtract(this.focusCamera.target, this.pickPoint);
29
+ let pickToTarget = ValueObjects_1.Vector3.Subtract(this.focusCamera.target, this.pickPoint);
30
30
  const newLength = pickToTarget.magnitued * percentChange;
31
- pickToTarget = ValueObjects_1.Vector3.newVectorOfLength(pickToTarget, newLength);
32
- const newTargetPos = ValueObjects_1.Vector3.add(this.pickPoint, pickToTarget);
31
+ pickToTarget = ValueObjects_1.Vector3.NewVectorOfLength(pickToTarget, newLength);
32
+ const newTargetPos = ValueObjects_1.Vector3.Add(this.pickPoint, pickToTarget);
33
33
  this.focusCamera.target = newTargetPos;
34
34
  }
35
35
  if (nomralizedTime >= 1 && this.interval) {
@@ -14,10 +14,10 @@ class PinchDollyFocusCamera {
14
14
  this.focusCamera.radius = currentRadius - deltaRadius;
15
15
  if (this.pickPoint !== undefined) {
16
16
  const percentChange = this.focusCamera.radius / currentRadius;
17
- let pickToTarget = ValueObjects_1.Vector3.subtract(this.focusCamera.target, this.pickPoint);
17
+ let pickToTarget = ValueObjects_1.Vector3.Subtract(this.focusCamera.target, this.pickPoint);
18
18
  const newLength = pickToTarget.magnitued * percentChange;
19
- pickToTarget = ValueObjects_1.Vector3.newVectorOfLength(pickToTarget, newLength);
20
- const newTargetPos = ValueObjects_1.Vector3.add(this.pickPoint, pickToTarget);
19
+ pickToTarget = ValueObjects_1.Vector3.NewVectorOfLength(pickToTarget, newLength);
20
+ const newTargetPos = ValueObjects_1.Vector3.Add(this.pickPoint, pickToTarget);
21
21
  this.focusCamera.target = newTargetPos;
22
22
  }
23
23
  this.previousDistanceBetweenTouches = distanceBetweenTouches;
@@ -14,10 +14,10 @@ class PixelDollyFocusCamera {
14
14
  this.focusCamera.radius = currentRadius - deltaRadius;
15
15
  if (this.pickPoint !== undefined) {
16
16
  const percentChange = this.focusCamera.radius / currentRadius;
17
- let pickToTarget = ValueObjects_1.Vector3.subtract(this.focusCamera.target, this.pickPoint);
17
+ let pickToTarget = ValueObjects_1.Vector3.Subtract(this.focusCamera.target, this.pickPoint);
18
18
  const newLength = pickToTarget.magnitued * percentChange;
19
- pickToTarget = ValueObjects_1.Vector3.newVectorOfLength(pickToTarget, newLength);
20
- const newTargetPos = ValueObjects_1.Vector3.add(this.pickPoint, pickToTarget);
19
+ pickToTarget = ValueObjects_1.Vector3.NewVectorOfLength(pickToTarget, newLength);
20
+ const newTargetPos = ValueObjects_1.Vector3.Add(this.pickPoint, pickToTarget);
21
21
  this.focusCamera.target = newTargetPos;
22
22
  }
23
23
  this.previousPixelPosition = pixelPosition;
@@ -10,7 +10,7 @@ class PixelOrbitFocusCamera {
10
10
  if (!this.previousPixelPos) {
11
11
  throw new Error("[PixelOrbitFocusCamera] You must initialize first!");
12
12
  }
13
- const pixelChange = ValueObjects_1.Vector2.subtract(pixelPosition, this.previousPixelPos);
13
+ const pixelChange = ValueObjects_1.Vector2.Subtract(pixelPosition, this.previousPixelPos);
14
14
  this.focusCamera.alpha += pixelChange.x * this.sensitivity;
15
15
  this.focusCamera.beta += pixelChange.y * this.sensitivity;
16
16
  this.previousPixelPos = pixelPosition;
@@ -16,7 +16,7 @@ class PixelPlanePanFocusCamera {
16
16
  const p2 = this.plane.intersectLine(finalRay);
17
17
  if (!p1 || !p2)
18
18
  return;
19
- const delta = ValueObjects_1.Vector3.subtract(p2, p1);
19
+ const delta = ValueObjects_1.Vector3.Subtract(p2, p1);
20
20
  const currentTarget = this.focusCamera.target;
21
21
  const newTarget = new ValueObjects_1.Vector3(currentTarget.x - delta.x, currentTarget.y - delta.y, currentTarget.z - delta.z);
22
22
  this.focusCamera.target = new ValueObjects_1.Vector3(newTarget.x, newTarget.y, newTarget.z);
@@ -0,0 +1,25 @@
1
+ import { QuestionChallenge, SerializedSystem, StateMachine } from "../../Entities";
2
+ export declare class SerializeQuestionChallenge implements SerializedSystem {
3
+ private questionChallenge;
4
+ name: string;
5
+ seriliziationVersion: number;
6
+ getSystemState(): object;
7
+ applySystemState(state: object, version: number): void;
8
+ applyDefaultState(): void;
9
+ private applyDataV1;
10
+ private applyDataV2;
11
+ constructor(questionChallenge: QuestionChallenge, stateMachine: StateMachine);
12
+ }
13
+ export interface ChallengeDataV2 {
14
+ questionText: string;
15
+ answers: AnswerDataV1[];
16
+ }
17
+ export interface ChallengeDataV1 {
18
+ answers: AnswerDataV1[];
19
+ }
20
+ export interface AnswerDataV1 {
21
+ id: string;
22
+ text: string;
23
+ feedback: string;
24
+ isCorrect: boolean;
25
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SerializeQuestionChallenge = void 0;
4
+ const Entities_1 = require("../../Entities");
5
+ class SerializeQuestionChallenge {
6
+ constructor(questionChallenge, stateMachine) {
7
+ this.questionChallenge = questionChallenge;
8
+ this.name = "question";
9
+ this.seriliziationVersion = 2;
10
+ stateMachine.registerSerializedSystem(this);
11
+ }
12
+ getSystemState() {
13
+ const answers = this.questionChallenge
14
+ .getAllAnswers()
15
+ .map((answer) => {
16
+ return {
17
+ id: answer.id,
18
+ feedback: answer.feedbackText,
19
+ isCorrect: answer.isCorrect,
20
+ text: answer.text,
21
+ };
22
+ });
23
+ const state = {
24
+ questionText: this.questionChallenge.text,
25
+ answers,
26
+ };
27
+ return state;
28
+ }
29
+ applySystemState(state, version) {
30
+ if (state && version === 1) {
31
+ const castState = state;
32
+ this.applyDataV1(castState);
33
+ }
34
+ else if (state && version === 2) {
35
+ const castState = state;
36
+ this.applyDataV2(castState);
37
+ }
38
+ else {
39
+ // Unsupported version
40
+ console.warn(`Unsupported data version ${version} for serialized system ${this.name}. Reverting to default state`);
41
+ this.applyDefaultState();
42
+ }
43
+ }
44
+ applyDefaultState() {
45
+ this.questionChallenge.setDefaultState();
46
+ }
47
+ applyDataV1(data) {
48
+ this.questionChallenge.removeAllAnswers();
49
+ this.questionChallenge.text = "";
50
+ data.answers.forEach((answerData) => {
51
+ const answer = Entities_1.makeQuestionChallengeAnswer(answerData.id);
52
+ answer.text = answerData.text;
53
+ answer.isCorrect = answerData.isCorrect;
54
+ answer.feedbackText = answerData.feedback;
55
+ this.questionChallenge.addAnswer(answer);
56
+ });
57
+ }
58
+ applyDataV2(data) {
59
+ this.questionChallenge.removeAllAnswers();
60
+ this.questionChallenge.text = data.questionText;
61
+ data.answers.forEach((answerData) => {
62
+ const answer = Entities_1.makeQuestionChallengeAnswer(answerData.id);
63
+ answer.text = answerData.text;
64
+ answer.isCorrect = answerData.isCorrect;
65
+ answer.feedbackText = answerData.feedback;
66
+ this.questionChallenge.addAnswer(answer);
67
+ });
68
+ }
69
+ }
70
+ exports.SerializeQuestionChallenge = SerializeQuestionChallenge;
@@ -0,0 +1,4 @@
1
+ export * from "./SerializeQuestionChallenge";
2
+ export * from "./setQuesionChallengeAnswerFeedback";
3
+ export * from "./setQuesionChallengeAnswerText";
4
+ export * from "./toggleQuesionChallengeAnswerIsCorrect";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./SerializeQuestionChallenge"), exports);
14
+ __exportStar(require("./setQuesionChallengeAnswerFeedback"), exports);
15
+ __exportStar(require("./setQuesionChallengeAnswerText"), exports);
16
+ __exportStar(require("./toggleQuesionChallengeAnswerIsCorrect"), exports);
@@ -0,0 +1,2 @@
1
+ import { QuestionChallenge } from "../../Entities";
2
+ export declare function makeSetQuestionChallengeAnswerFeedback(answerID: string, questionChallenge: QuestionChallenge): (feedback: string) => void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeSetQuestionChallengeAnswerFeedback = void 0;
4
+ function makeSetQuestionChallengeAnswerFeedback(answerID, questionChallenge) {
5
+ return function setQuestionChallengeAnswerFeedback(feedback) {
6
+ const answer = questionChallenge.getAnswer(answerID);
7
+ if (answer) {
8
+ answer.feedbackText = feedback;
9
+ }
10
+ else {
11
+ console.warn("[setQuestionChallengeAnswerFeedback] Unable to find question by id " +
12
+ answerID);
13
+ }
14
+ };
15
+ }
16
+ exports.makeSetQuestionChallengeAnswerFeedback = makeSetQuestionChallengeAnswerFeedback;
@@ -0,0 +1,2 @@
1
+ import { QuestionChallenge } from "../../Entities";
2
+ export declare function makeSetQuestionChallengeAnswerText(answerID: string, questionChallenge: QuestionChallenge): (text: string) => void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeSetQuestionChallengeAnswerText = void 0;
4
+ function makeSetQuestionChallengeAnswerText(answerID, questionChallenge) {
5
+ return function setQuestionChallengeAnswerText(text) {
6
+ const answer = questionChallenge.getAnswer(answerID);
7
+ if (answer) {
8
+ answer.text = text;
9
+ }
10
+ else {
11
+ console.warn("[setQuestionChallengeAnswerText] Unable to find question by id " +
12
+ answerID);
13
+ }
14
+ };
15
+ }
16
+ exports.makeSetQuestionChallengeAnswerText = makeSetQuestionChallengeAnswerText;
@@ -0,0 +1,2 @@
1
+ import { QuestionChallenge } from "../../Entities";
2
+ export declare function makeToggleQuesionChallengeAnswerIsCorrect(answerID: string, questionChallenge: QuestionChallenge): () => void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeToggleQuesionChallengeAnswerIsCorrect = void 0;
4
+ function makeToggleQuesionChallengeAnswerIsCorrect(answerID, questionChallenge) {
5
+ return function toggleQuesionChallengeAnswerIsCorrect() {
6
+ const answer = questionChallenge.getAnswer(answerID);
7
+ if (answer) {
8
+ answer.isCorrect = !answer.isCorrect;
9
+ }
10
+ else {
11
+ console.warn("[toggleQuesionChallengeAnswerIsCorrect] Unable to find question by id " +
12
+ answerID);
13
+ }
14
+ };
15
+ }
16
+ exports.makeToggleQuesionChallengeAnswerIsCorrect = makeToggleQuesionChallengeAnswerIsCorrect;
@@ -1,2 +1,3 @@
1
1
  export * from "./setDevicePreview";
2
2
  export * from "./FocusCamera";
3
+ export * from "./QuestionChallenge";
@@ -12,3 +12,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./setDevicePreview"), exports);
14
14
  __exportStar(require("./FocusCamera"), exports);
15
+ __exportStar(require("./QuestionChallenge"), exports);
@@ -1,6 +1,6 @@
1
1
  export declare class Angle {
2
- static fromDegrees(degrees: number): Angle;
3
- static fromRadians(radians: number): Angle;
2
+ static FromDegrees(degrees: number): Angle;
3
+ static FromRadians(radians: number): Angle;
4
4
  private _degrees;
5
5
  get degrees(): number;
6
6
  get radians(): number;
@@ -6,10 +6,10 @@ class Angle {
6
6
  this._degrees = 0;
7
7
  this._degrees = degrees;
8
8
  }
9
- static fromDegrees(degrees) {
9
+ static FromDegrees(degrees) {
10
10
  return new Angle(degrees);
11
11
  }
12
- static fromRadians(radians) {
12
+ static FromRadians(radians) {
13
13
  return new Angle(radians * 180 / Math.PI);
14
14
  }
15
15
  get degrees() {
@@ -5,14 +5,10 @@ export declare class Color {
5
5
  static Hex(hex: string): Color;
6
6
  static X11(name: string): Color;
7
7
  static Equal(a: Color, b: Color): boolean;
8
- private _r;
9
- private _g;
10
- private _b;
11
- private _a;
12
- get r(): number;
13
- get g(): number;
14
- get b(): number;
15
- get a(): number;
8
+ readonly r: number;
9
+ readonly g: number;
10
+ readonly b: number;
11
+ readonly a: number;
16
12
  get rPercent(): number;
17
13
  get gPercent(): number;
18
14
  get bPercent(): number;
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Color = void 0;
4
4
  class Color {
5
5
  constructor(r, g, b, a) {
6
- this._r = this.clampVal(r);
7
- this._g = this.clampVal(g);
8
- this._b = this.clampVal(b);
9
- this._a = this.clampVal(a);
6
+ this.r = this.clampVal(r);
7
+ this.g = this.clampVal(g);
8
+ this.b = this.clampVal(b);
9
+ this.a = this.clampVal(a);
10
10
  }
11
11
  static RGBA(r, g, b, a) {
12
12
  return new Color(r, g, b, a);
@@ -51,32 +51,20 @@ class Color {
51
51
  return false;
52
52
  return true;
53
53
  }
54
- get r() {
55
- return this._r;
56
- }
57
- get g() {
58
- return this._g;
59
- }
60
- get b() {
61
- return this._b;
62
- }
63
- get a() {
64
- return this._a;
65
- }
66
54
  get rPercent() {
67
- return this._r / 255;
55
+ return this.r / 255;
68
56
  }
69
57
  get gPercent() {
70
- return this._g / 255;
58
+ return this.g / 255;
71
59
  }
72
60
  get bPercent() {
73
- return this._b / 255;
61
+ return this.b / 255;
74
62
  }
75
63
  get aPercent() {
76
- return this._a / 255;
64
+ return this.a / 255;
77
65
  }
78
66
  get array() {
79
- return [this._r, this._g, this._b, this._a];
67
+ return [this.r, this.g, this.b, this.a];
80
68
  }
81
69
  clampVal(val) {
82
70
  if (val > 255)
@@ -1,12 +1,11 @@
1
1
  import { Vector2 } from "./Vector2";
2
2
  export declare class LineSegment2D {
3
- private _start;
4
- get start(): Vector2;
5
- private _end;
6
- get end(): Vector2;
3
+ static GetPositionAtPercent(line: LineSegment2D, percent: number): Vector2;
4
+ static Intersect(a: LineSegment2D, b: LineSegment2D, tolerance?: number): Vector2 | undefined;
5
+ static ClosestPointOnLine(line: LineSegment2D, point: Vector2): Vector2;
6
+ readonly start: Vector2;
7
+ readonly end: Vector2;
7
8
  get length(): number;
8
9
  get direction(): Vector2;
9
- getPositionAtPercent(percent: number): Vector2;
10
- intersect(otherLine: LineSegment2D): Vector2 | undefined;
11
10
  constructor(start: Vector2, end: Vector2);
12
11
  }
@@ -4,52 +4,68 @@ exports.LineSegment2D = void 0;
4
4
  const Vector2_1 = require("./Vector2");
5
5
  class LineSegment2D {
6
6
  constructor(start, end) {
7
- this._start = start;
8
- this._end = end;
7
+ this.start = start;
8
+ this.end = end;
9
9
  }
10
- get start() {
11
- return this._start;
10
+ static GetPositionAtPercent(line, percent) {
11
+ const dir = line.direction;
12
+ const length = percent * line.length;
13
+ const localPos = Vector2_1.Vector2.NewVectorOfLength(dir, length);
14
+ return Vector2_1.Vector2.Add(line.start, localPos);
12
15
  }
13
- get end() {
14
- return this._end;
15
- }
16
- get length() {
17
- return Vector2_1.Vector2.subtract(this._start, this._end).magnitued;
18
- }
19
- get direction() {
20
- return Vector2_1.Vector2.subtract(this._end, this._start).unit;
21
- }
22
- getPositionAtPercent(percent) {
23
- const dir = this.direction;
24
- const length = percent * this.length;
25
- const localPos = Vector2_1.Vector2.newVectorOfLength(dir, length);
26
- return Vector2_1.Vector2.add(this._start, localPos);
27
- }
28
- intersect(otherLine) {
16
+ static Intersect(a, b, tolerance = 0) {
29
17
  // See https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
30
- const x1 = this._start.x;
31
- const y1 = this._start.y;
32
- const x2 = this._end.x;
33
- const y2 = this._end.y;
34
- const x3 = otherLine._start.x;
35
- const y3 = otherLine._start.y;
36
- const x4 = otherLine._end.x;
37
- const y4 = otherLine._end.y;
18
+ const x1 = a.start.x;
19
+ const y1 = a.start.y;
20
+ const x2 = a.end.x;
21
+ const y2 = a.end.y;
22
+ const x3 = b.start.x;
23
+ const y3 = b.start.y;
24
+ const x4 = b.end.x;
25
+ const y4 = b.end.y;
38
26
  const denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
39
27
  if (denominator === 0) {
40
28
  return undefined;
41
29
  }
42
30
  const tNumerator = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4);
43
31
  const t = tNumerator / denominator;
44
- if (t < 0 || t > 1)
32
+ const tTolearnce = tolerance / a.length;
33
+ if (t < -tTolearnce || t > 1 + tTolearnce) {
45
34
  return undefined;
35
+ }
46
36
  const uNumerator = (x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3);
47
37
  const u = uNumerator / denominator;
48
- if (u < 0 || u > 1)
38
+ const uTolearnce = tolerance / b.length;
39
+ if (u < -uTolearnce || u > 1 + uTolearnce)
49
40
  return undefined;
50
41
  const px = x1 + t * (x2 - x1);
51
42
  const py = y1 + t * (y2 - y1);
52
43
  return new Vector2_1.Vector2(px, py);
53
44
  }
45
+ static ClosestPointOnLine(line, point) {
46
+ // see https://monkeyproofsolutions.nl/wordpress/how-to-calculate-the-shortest-distance-between-a-point-and-a-line/
47
+ let direction = Vector2_1.Vector2.Subtract(line.end, line.start);
48
+ const pointToStart = Vector2_1.Vector2.Subtract(point, line.start);
49
+ const tNumerator = Vector2_1.Vector2.Dot(direction, pointToStart);
50
+ const tDenominator = Vector2_1.Vector2.Dot(direction, direction);
51
+ const t = tNumerator / tDenominator;
52
+ if (t < 0) {
53
+ return line.start;
54
+ }
55
+ else if (t > 1) {
56
+ return line.end;
57
+ }
58
+ else {
59
+ const length = t * direction.magnitued;
60
+ direction = Vector2_1.Vector2.NewVectorOfLength(direction, length);
61
+ return Vector2_1.Vector2.Add(line.start, direction);
62
+ }
63
+ }
64
+ get length() {
65
+ return Vector2_1.Vector2.Subtract(this.start, this.end).magnitued;
66
+ }
67
+ get direction() {
68
+ return Vector2_1.Vector2.Subtract(this.end, this.start).unit;
69
+ }
54
70
  }
55
71
  exports.LineSegment2D = LineSegment2D;
@@ -16,7 +16,7 @@ export declare class ParametricLine {
16
16
  static Down(): ParametricLine;
17
17
  static Left(): ParametricLine;
18
18
  static Right(): ParametricLine;
19
- static getPointAtDistance(line: ParametricLine, distance: number): Vector3;
19
+ static GetPointAtDistance(line: ParametricLine, distance: number): Vector3;
20
20
  readonly x0: number;
21
21
  readonly y0: number;
22
22
  readonly z0: number;
@@ -13,7 +13,7 @@ class ParametricLine {
13
13
  }
14
14
  // See https://planetcalc.com/8253/
15
15
  static FromTwoPoint(p1, p2) {
16
- const dir = Vector3_1.Vector3.subtract(p2, p1).unit;
16
+ const dir = Vector3_1.Vector3.Subtract(p2, p1).unit;
17
17
  return this.FromPointDirection(p1, dir);
18
18
  }
19
19
  static FromPointDirection(point, direction) {
@@ -27,36 +27,36 @@ class ParametricLine {
27
27
  });
28
28
  }
29
29
  static Forward() {
30
- const p = Vector3_1.Vector3.zero();
30
+ const p = Vector3_1.Vector3.Zero();
31
31
  const d = new Vector3_1.Vector3(0, 0, 1);
32
32
  return this.FromPointDirection(p, d);
33
33
  }
34
34
  static Backward() {
35
- const p = Vector3_1.Vector3.zero();
35
+ const p = Vector3_1.Vector3.Zero();
36
36
  const d = new Vector3_1.Vector3(0, 0, -1);
37
37
  return this.FromPointDirection(p, d);
38
38
  }
39
39
  static Up() {
40
- const p = Vector3_1.Vector3.zero();
40
+ const p = Vector3_1.Vector3.Zero();
41
41
  const d = new Vector3_1.Vector3(0, 1, 0);
42
42
  return this.FromPointDirection(p, d);
43
43
  }
44
44
  static Down() {
45
- const p = Vector3_1.Vector3.zero();
45
+ const p = Vector3_1.Vector3.Zero();
46
46
  const d = new Vector3_1.Vector3(0, -1, 0);
47
47
  return this.FromPointDirection(p, d);
48
48
  }
49
49
  static Left() {
50
- const p = Vector3_1.Vector3.zero();
50
+ const p = Vector3_1.Vector3.Zero();
51
51
  const d = new Vector3_1.Vector3(-1, 0, 0);
52
52
  return this.FromPointDirection(p, d);
53
53
  }
54
54
  static Right() {
55
- const p = Vector3_1.Vector3.zero();
55
+ const p = Vector3_1.Vector3.Zero();
56
56
  const d = new Vector3_1.Vector3(1, 0, 0);
57
57
  return this.FromPointDirection(p, d);
58
58
  }
59
- static getPointAtDistance(line, distance) {
59
+ static GetPointAtDistance(line, distance) {
60
60
  const x = line.x0 + line.a * distance;
61
61
  const y = line.y0 + line.b * distance;
62
62
  const z = line.z0 + line.c * distance;
@@ -14,7 +14,7 @@ export declare class ParametricPlane {
14
14
  static XY(): ParametricPlane;
15
15
  static ZX(): ParametricPlane;
16
16
  static YZ(): ParametricPlane;
17
- getParameters(): PlaneParameters;
17
+ GetParameters(): PlaneParameters;
18
18
  intersectLine(line: ParametricLine): Vector3 | undefined;
19
19
  constructor(point: Vector3, normal: Vector3);
20
20
  }