segment.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Segment = void 0;
  4. const geometry_1 = require("../geometry");
  5. class Segment extends geometry_1.Geometry {
  6. constructor() {
  7. super(...arguments);
  8. this.isVisible = true;
  9. this.isSegment = true;
  10. this.isSubpathStart = false;
  11. }
  12. get end() {
  13. return this.endPoint;
  14. }
  15. get start() {
  16. if (this.previousSegment == null) {
  17. throw new Error('Missing previous segment. (This segment cannot be the ' +
  18. 'first segment of a path, or segment has not yet been ' +
  19. 'added to a path.)');
  20. }
  21. return this.previousSegment.end;
  22. }
  23. closestPointT(p, options) {
  24. if (this.closestPointNormalizedLength) {
  25. return this.closestPointNormalizedLength(p);
  26. }
  27. throw new Error('Neither `closestPointT` nor `closestPointNormalizedLength` method is implemented.');
  28. }
  29. // eslint-disable-next-line
  30. lengthAtT(t, options) {
  31. if (t <= 0) {
  32. return 0;
  33. }
  34. const length = this.length();
  35. if (t >= 1) {
  36. return length;
  37. }
  38. return length * t;
  39. }
  40. divideAtT(t) {
  41. if (this.divideAt) {
  42. return this.divideAt(t);
  43. }
  44. throw new Error('Neither `divideAtT` nor `divideAt` method is implemented.');
  45. }
  46. pointAtT(t) {
  47. if (this.pointAt) {
  48. return this.pointAt(t);
  49. }
  50. throw new Error('Neither `pointAtT` nor `pointAt` method is implemented.');
  51. }
  52. tangentAtT(t) {
  53. if (this.tangentAt) {
  54. return this.tangentAt(t);
  55. }
  56. throw new Error('Neither `tangentAtT` nor `tangentAt` method is implemented.');
  57. }
  58. }
  59. exports.Segment = Segment;
  60. //# sourceMappingURL=segment.js.map