flowGraphInteger.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { RegisterClass } from "../Misc/typeStore.js";
  2. /**
  3. * @experimental
  4. * Class that represents an integer value.
  5. */
  6. export class FlowGraphInteger {
  7. constructor(value) {
  8. this.value = this._toInt(value);
  9. }
  10. /**
  11. * Converts a float to an integer.
  12. * @param n the float to convert
  13. * @returns the result of n | 0 - converting it to a int
  14. */
  15. _toInt(n) {
  16. return n | 0;
  17. }
  18. /**
  19. * Adds two integers together.
  20. * @param other the other integer to add
  21. * @returns a FlowGraphInteger with the result of the addition
  22. */
  23. add(other) {
  24. return new FlowGraphInteger(this.value + other.value);
  25. }
  26. /**
  27. * Subtracts two integers.
  28. * @param other the other integer to subtract
  29. * @returns a FlowGraphInteger with the result of the subtraction
  30. */
  31. subtract(other) {
  32. return new FlowGraphInteger(this.value - other.value);
  33. }
  34. /**
  35. * Multiplies two integers.
  36. * @param other the other integer to multiply
  37. * @returns a FlowGraphInteger with the result of the multiplication
  38. */
  39. multiply(other) {
  40. return new FlowGraphInteger(Math.imul(this.value, other.value));
  41. }
  42. /**
  43. * Divides two integers.
  44. * @param other the other integer to divide
  45. * @returns a FlowGraphInteger with the result of the division
  46. */
  47. divide(other) {
  48. return new FlowGraphInteger(this.value / other.value);
  49. }
  50. /**
  51. * The class name of this type.
  52. * @returns
  53. */
  54. getClassName() {
  55. return FlowGraphInteger.ClassName;
  56. }
  57. /**
  58. * Compares two integers for equality.
  59. * @param other the other integer to compare
  60. * @returns
  61. */
  62. equals(other) {
  63. return this.value === other.value;
  64. }
  65. /**
  66. * Parses a FlowGraphInteger from a serialization object.
  67. * @param serializationObject
  68. * @returns
  69. */
  70. static Parse(serializationObject) {
  71. return new FlowGraphInteger(serializationObject.value);
  72. }
  73. }
  74. FlowGraphInteger.ClassName = "FlowGraphInteger";
  75. RegisterClass("FlowGraphInteger", FlowGraphInteger);
  76. //# sourceMappingURL=flowGraphInteger.js.map