segment.js 1.7 KB

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