@equinor/esv-intersection 3.0.1 → 3.0.4

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 (109) hide show
  1. package/dist/index.cjs +2 -2
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.mjs +2241 -1938
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/index.umd.js +2 -2
  6. package/dist/index.umd.js.map +1 -1
  7. package/package.json +21 -22
  8. package/dist/components/axis.d.ts +0 -47
  9. package/dist/components/index.d.ts +0 -1
  10. package/dist/control/ExtendedCurveInterpolator.d.ts +0 -58
  11. package/dist/control/IntersectionReferenceSystem.d.ts +0 -96
  12. package/dist/control/LayerManager.d.ts +0 -76
  13. package/dist/control/MainController.d.ts +0 -154
  14. package/dist/control/ZoomPanHandler.d.ts +0 -158
  15. package/dist/control/index.d.ts +0 -5
  16. package/dist/control/interfaces.d.ts +0 -37
  17. package/dist/control/overlay.d.ts +0 -20
  18. package/dist/datautils/colortable.d.ts +0 -1
  19. package/dist/datautils/findsample.d.ts +0 -2
  20. package/dist/datautils/index.d.ts +0 -6
  21. package/dist/datautils/interfaces.d.ts +0 -63
  22. package/dist/datautils/picks.d.ts +0 -74
  23. package/dist/datautils/schematicShapeGenerator.d.ts +0 -59
  24. package/dist/datautils/seismicimage.d.ts +0 -45
  25. package/dist/datautils/surfacedata.d.ts +0 -10
  26. package/dist/datautils/trajectory.d.ts +0 -14
  27. package/dist/layers/CalloutCanvasLayer.d.ts +0 -60
  28. package/dist/layers/CustomDisplayObjects/ComplexRope.d.ts +0 -22
  29. package/dist/layers/CustomDisplayObjects/ComplexRopeGeometry.d.ts +0 -27
  30. package/dist/layers/CustomDisplayObjects/FixedWidthSimpleRope.d.ts +0 -20
  31. package/dist/layers/CustomDisplayObjects/FixedWidthSimpleRopeGeometry.d.ts +0 -26
  32. package/dist/layers/CustomDisplayObjects/UniformTextureStretchRope.d.ts +0 -17
  33. package/dist/layers/CustomDisplayObjects/UniformTextureStretchRopeGeometry.d.ts +0 -24
  34. package/dist/layers/GeomodelCanvasLayer.d.ts +0 -28
  35. package/dist/layers/GeomodelLabelsLayer.d.ts +0 -49
  36. package/dist/layers/GeomodelLayerV2.d.ts +0 -12
  37. package/dist/layers/GridLayer.d.ts +0 -29
  38. package/dist/layers/ImageCanvasLayer.d.ts +0 -20
  39. package/dist/layers/ReferenceLineLayer.d.ts +0 -29
  40. package/dist/layers/SchematicLayer.d.ts +0 -113
  41. package/dist/layers/SeismicCanvasLayer.d.ts +0 -18
  42. package/dist/layers/WellborePathLayer.d.ts +0 -17
  43. package/dist/layers/base/CanvasLayer.d.ts +0 -19
  44. package/dist/layers/base/HTMLLayer.d.ts +0 -13
  45. package/dist/layers/base/Layer.d.ts +0 -69
  46. package/dist/layers/base/PixiLayer.d.ts +0 -32
  47. package/dist/layers/base/SVGLayer.d.ts +0 -13
  48. package/dist/layers/base/index.d.ts +0 -5
  49. package/dist/layers/index.d.ts +0 -16
  50. package/dist/layers/schematicInterfaces.d.ts +0 -208
  51. package/dist/utils/arc-length.d.ts +0 -23
  52. package/dist/utils/binary-search.d.ts +0 -8
  53. package/dist/utils/color.d.ts +0 -5
  54. package/dist/utils/index.d.ts +0 -1
  55. package/dist/utils/root-finder.d.ts +0 -34
  56. package/dist/utils/text.d.ts +0 -14
  57. package/dist/utils/vectorUtils.d.ts +0 -15
  58. package/dist/vendor/pixi-dashed-line/index.d.ts +0 -57
  59. package/src/components/axis.ts +0 -247
  60. package/src/components/index.ts +0 -1
  61. package/src/control/ExtendedCurveInterpolator.ts +0 -155
  62. package/src/control/IntersectionReferenceSystem.ts +0 -391
  63. package/src/control/LayerManager.ts +0 -294
  64. package/src/control/MainController.ts +0 -296
  65. package/src/control/ZoomPanHandler.ts +0 -436
  66. package/src/control/index.ts +0 -5
  67. package/src/control/interfaces.ts +0 -42
  68. package/src/control/overlay.ts +0 -118
  69. package/src/datautils/colortable.ts +0 -14
  70. package/src/datautils/findsample.ts +0 -64
  71. package/src/datautils/index.ts +0 -6
  72. package/src/datautils/interfaces.ts +0 -68
  73. package/src/datautils/picks.ts +0 -328
  74. package/src/datautils/schematicShapeGenerator.ts +0 -1007
  75. package/src/datautils/seismicimage.ts +0 -180
  76. package/src/datautils/surfacedata.ts +0 -318
  77. package/src/datautils/trajectory.ts +0 -206
  78. package/src/layers/CalloutCanvasLayer.ts +0 -338
  79. package/src/layers/CustomDisplayObjects/ComplexRope.ts +0 -45
  80. package/src/layers/CustomDisplayObjects/ComplexRopeGeometry.ts +0 -190
  81. package/src/layers/CustomDisplayObjects/FixedWidthSimpleRope.ts +0 -41
  82. package/src/layers/CustomDisplayObjects/FixedWidthSimpleRopeGeometry.ts +0 -149
  83. package/src/layers/CustomDisplayObjects/UniformTextureStretchRope.ts +0 -39
  84. package/src/layers/CustomDisplayObjects/UniformTextureStretchRopeGeometry.ts +0 -174
  85. package/src/layers/GeomodelCanvasLayer.ts +0 -176
  86. package/src/layers/GeomodelLabelsLayer.ts +0 -619
  87. package/src/layers/GeomodelLayerV2.ts +0 -110
  88. package/src/layers/GridLayer.ts +0 -145
  89. package/src/layers/ImageCanvasLayer.ts +0 -55
  90. package/src/layers/ReferenceLineLayer.ts +0 -185
  91. package/src/layers/SchematicLayer.ts +0 -871
  92. package/src/layers/SeismicCanvasLayer.ts +0 -46
  93. package/src/layers/WellborePathLayer.ts +0 -129
  94. package/src/layers/base/CanvasLayer.ts +0 -102
  95. package/src/layers/base/HTMLLayer.ts +0 -70
  96. package/src/layers/base/Layer.ts +0 -217
  97. package/src/layers/base/PixiLayer.ts +0 -190
  98. package/src/layers/base/SVGLayer.ts +0 -63
  99. package/src/layers/base/index.ts +0 -5
  100. package/src/layers/index.ts +0 -16
  101. package/src/layers/schematicInterfaces.ts +0 -470
  102. package/src/utils/arc-length.ts +0 -66
  103. package/src/utils/binary-search.ts +0 -26
  104. package/src/utils/color.ts +0 -22
  105. package/src/utils/index.ts +0 -1
  106. package/src/utils/root-finder.ts +0 -78
  107. package/src/utils/text.ts +0 -88
  108. package/src/utils/vectorUtils.ts +0 -67
  109. package/src/vendor/pixi-dashed-line/index.ts +0 -394
package/src/utils/text.ts DELETED
@@ -1,88 +0,0 @@
1
- import { clamp } from '@equinor/videx-math';
2
-
3
- import { BoundingBox } from '../interfaces';
4
- import { ScaleLinear } from 'd3-scale';
5
-
6
- const DEFAULT_HORIZONTAL_PADDING = 4;
7
- const DEFAULT_VERTICAL_PADDING = 2;
8
-
9
- export function pixelsPerUnit(x: ScaleLinear<number, number>): number {
10
- const [min] = x.domain();
11
- return Math.abs(x(min + 1));
12
- }
13
-
14
- export function calcSize(factor: number, min: number, max: number, x: ScaleLinear<number, number>): number {
15
- return clamp(pixelsPerUnit(x) * factor, min, max);
16
- }
17
-
18
- export function isOverlappingHorizontally(r1: BoundingBox, r2: BoundingBox): boolean {
19
- const r1x2 = r1.x + r1.width;
20
- const r2x2 = r2.x + r2.width;
21
-
22
- if (r2.x > r1x2 || r2x2 < r1.x) {
23
- return false;
24
- }
25
- return true;
26
- }
27
-
28
- export function isOverlapping(
29
- r1: BoundingBox,
30
- r2: BoundingBox,
31
- horizontalPadding: number = DEFAULT_HORIZONTAL_PADDING,
32
- verticalPadding: number = DEFAULT_VERTICAL_PADDING,
33
- ): boolean {
34
- const r1x2 = r1.x + r1.width + horizontalPadding;
35
- const r2x2 = r2.x + r2.width + horizontalPadding;
36
- const r1y2 = r1.y + r1.height + verticalPadding;
37
- const r2y2 = r2.y + r2.height + verticalPadding;
38
-
39
- if (r2.x - horizontalPadding > r1x2 || r2.y - verticalPadding > r1y2 || r2x2 + horizontalPadding < r1.x || r2y2 + verticalPadding < r1.y) {
40
- return false;
41
- }
42
- return true;
43
- }
44
-
45
- export function getOverlap(r1: BoundingBox, r2: BoundingBox): { dx: number; dy: number } {
46
- const r1x2 = r1.x + r1.width;
47
- const r2x2 = r2.x + r2.width;
48
- const r1y2 = r1.y + r1.height;
49
- const r2y2 = r2.y + r2.height;
50
-
51
- if (r2.x > r1x2 || r2.y > r1y2 || r2x2 < r1.x || r2y2 < r1.y) {
52
- return null;
53
- }
54
-
55
- const dx = Math.max(0, Math.min(r1.x + r1.width, r2.x + r2.width) - Math.max(r1.x, r2.x));
56
- const dy = Math.max(0, Math.min(r1.y + r1.height, r2.y + r2.height) - Math.max(r1.y, r2.y));
57
-
58
- const newPoints = {
59
- dx,
60
- dy,
61
- };
62
- return newPoints;
63
- }
64
-
65
- export function getOverlapOffset(
66
- r1: BoundingBox,
67
- r2: BoundingBox,
68
- horizontalPadding = DEFAULT_HORIZONTAL_PADDING,
69
- verticalPadding = DEFAULT_VERTICAL_PADDING,
70
- ): { dx: number; dy: number } {
71
- const r1x2 = r1.x + r1.width;
72
- const r2x2 = r2.x + r2.width;
73
- const r1y2 = r1.y + r1.height;
74
- const r2y2 = r2.y + r2.height;
75
-
76
- if (r2.x - horizontalPadding > r1x2 || r2.y - verticalPadding > r1y2 || r2x2 + horizontalPadding < r1.x || r2y2 + verticalPadding < r1.y) {
77
- return null;
78
- }
79
-
80
- const dx = r1.x + r1.width - r2.x + horizontalPadding;
81
- const dy = r1.y + r1.height - r2.y + verticalPadding;
82
-
83
- const newPoints = {
84
- dx,
85
- dy,
86
- };
87
- return newPoints;
88
- }
@@ -1,67 +0,0 @@
1
- import { IPoint, Point } from 'pixi.js';
2
- import Vector2 from '@equinor/videx-vector2';
3
-
4
- export const pointToVector = (p: IPoint): Vector2 => new Vector2(p.x, p.y);
5
- export const pointToArray = (p: IPoint): [number, number] => [p.x, p.y];
6
- export const vectorToPoint = (v: Vector2): Point => new Point(v[0], v[1]);
7
- export const vectorToArray = (v: Vector2): [number, number] => [v[0], v[1]];
8
- export const arrayToPoint = (a: number[]): Point => new Point(a[0], a[1]);
9
- export const arrayToVector = (a: number[]): Vector2 => new Vector2(a[0], a[1]);
10
-
11
- export const calcDist = (prev: [number, number], point: [number, number]): number => {
12
- return arrayToVector(point).sub(prev).magnitude;
13
- };
14
-
15
- export const calcDistPoint = (prev: Point, point: Point): number => {
16
- return pointToVector(point).sub(prev.x, prev.y).magnitude;
17
- };
18
-
19
- export const calcNormal = (p1: Point, p2: Point): Point => {
20
- const d = pointToVector(p2).sub(p1.x, p1.y);
21
- d.x = d.y === 0 ? 1 : d.x;
22
- d.y = d.x === 0 ? 1 : d.y;
23
- return vectorToPoint(d.rotate90()); //TODO: normalize
24
- };
25
-
26
- export const convertToUnitVector = (p: Point): Point => {
27
- return vectorToPoint(pointToVector(p).normalize());
28
- };
29
-
30
- export const createNormals = (points: IPoint[]): Vector2[] => {
31
- if (points.length < 2) {
32
- return [new Vector2(0)];
33
- }
34
-
35
- let n: Vector2;
36
-
37
- return points.map((_coord, i, list) => {
38
- if (i < list.length - 1) {
39
- const p = pointToVector(list[i]);
40
- const q = pointToVector(list[i + 1]);
41
- const np = q.sub(p);
42
- const rotate = np.rotate90();
43
- n = rotate.normalized();
44
- return n;
45
- }
46
-
47
- // reuse previous normal for last coord
48
- return n;
49
- });
50
- };
51
-
52
- // TODO check if this can be simplified and return Vector/number[]
53
- export const offsetPoint = (point: IPoint, vector: Vector2, offset: number): Point => {
54
- const p = pointToVector(point);
55
- return vectorToPoint(p.add(vector.scale(offset)));
56
- };
57
-
58
- export const offsetPoints = (points: IPoint[], vectors: Vector2[], offset: number): Point[] => {
59
- if (points.length !== vectors.length) {
60
- throw new Error('Number of vectors does not match number of points');
61
- }
62
-
63
- return points.map((point, index) => {
64
- const vector = vectors[index];
65
- return offsetPoint(point, vector, offset);
66
- });
67
- };
@@ -1,394 +0,0 @@
1
- // https://github.com/davidfig/pixi-dashed-line
2
- //
3
- // Copyright 2021 David Figatner
4
- //
5
- // Permission is hereby granted, free of charge, to any person obtaining a copy of this software
6
- // and associated documentation files (the "Software"), to deal in the Software without restriction,
7
- // including without limitation the rights to use, copy, modify, merge, publish, distribute,
8
- // sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
9
- // is furnished to do so, subject to the following conditions:
10
- //
11
- // The above copyright notice and this permission notice shall be included in all copies or
12
- // substantial portions of the Software.
13
- //
14
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
15
- // BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
-
20
- import * as PIXI from 'pixi.js';
21
-
22
- /** Define the dash: [dash length, gap size, dash size, gap size, ...] */
23
- export type Dashes = number[];
24
-
25
- export interface DashLineOptions {
26
- dash?: Dashes;
27
- width?: number;
28
- color?: number;
29
- alpha?: number;
30
- scale?: number;
31
- useTexture?: boolean;
32
- useDots?: boolean;
33
- cap?: PIXI.LINE_CAP;
34
- join?: PIXI.LINE_JOIN;
35
- alignment?: number;
36
- }
37
-
38
- const dashLineOptionsDefault: Partial<DashLineOptions> = {
39
- dash: [10, 5], // eslint-disable-line no-magic-numbers
40
- width: 1,
41
- color: 0xffffff,
42
- alpha: 1,
43
- scale: 1,
44
- useTexture: false,
45
- alignment: 0.5,
46
- };
47
-
48
- export class DashLine {
49
- graphics: PIXI.Graphics;
50
-
51
- /** current length of the line */
52
- lineLength: number;
53
-
54
- /** cursor location */
55
- cursor = new PIXI.Point();
56
-
57
- /** desired scale of line */
58
- scale = 1;
59
-
60
- // sanity check to ensure the lineStyle is still in use
61
- private activeTexture: PIXI.Texture;
62
-
63
- private start: PIXI.Point;
64
-
65
- private dashSize: number;
66
- private dash: number[];
67
-
68
- private useTexture: boolean;
69
- private options: DashLineOptions;
70
-
71
- // cache of PIXI.Textures for dashed lines
72
- static dashTextureCache: Record<string, PIXI.Texture> = {};
73
-
74
- /**
75
- * Create a DashLine
76
- * @param graphics
77
- * @param [options]
78
- * @param [options.useTexture=false] - use the texture based render (useful for very large or very small dashed lines)
79
- * @param [options.dashes=[10,5] - an array holding the dash and gap (eg, [10, 5, 20, 5, ...])
80
- * @param [options.width=1] - width of the dashed line
81
- * @param [options.alpha=1] - alpha of the dashed line
82
- * @param [options.color=0xffffff] - color of the dashed line
83
- * @param [options.cap] - add a PIXI.LINE_CAP style to dashed lines (only works for useTexture: false)
84
- * @param [options.join] - add a PIXI.LINE_JOIN style to the dashed lines (only works for useTexture: false)
85
- * @param [options.alignment] - The alignment of any lines drawn (0.5 = middle, 1 = outer, 0 = inner)
86
- */
87
- constructor(graphics: PIXI.Graphics, options: DashLineOptions = {}) {
88
- this.graphics = graphics;
89
- options = { ...dashLineOptionsDefault, ...options };
90
- this.dash = options.dash;
91
- this.dashSize = this.dash.reduce((a, b) => a + b);
92
- this.useTexture = options.useTexture;
93
- this.options = options;
94
- this.setLineStyle();
95
- }
96
-
97
- /** resets line style to enable dashed line (useful if lineStyle was changed on graphics element) */
98
- setLineStyle() {
99
- const options = this.options;
100
- if (this.useTexture) {
101
- const texture = DashLine.getTexture(options, this.dashSize);
102
- this.graphics.lineTextureStyle({
103
- width: options.width * options.scale,
104
- color: options.color,
105
- alpha: options.alpha,
106
- texture,
107
- alignment: options.alignment,
108
- });
109
- this.activeTexture = texture;
110
- } else {
111
- this.graphics.lineStyle({
112
- width: options.width * options.scale,
113
- color: options.color,
114
- alpha: options.alpha,
115
- cap: options.cap,
116
- join: options.join,
117
- alignment: options.alignment,
118
- });
119
- }
120
- this.scale = options.scale;
121
- }
122
-
123
- private static distance(x1: number, y1: number, x2: number, y2: number): number {
124
- return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
125
- }
126
-
127
- moveTo(x: number, y: number): this {
128
- this.lineLength = 0;
129
- this.cursor.set(x, y);
130
- this.start = new PIXI.Point(x, y);
131
- this.graphics.moveTo(this.cursor.x, this.cursor.y);
132
- return this;
133
- }
134
-
135
- lineTo(x: number, y: number, closePath?: boolean): this {
136
- if (typeof this.lineLength === undefined) {
137
- this.moveTo(0, 0);
138
- }
139
- const length = DashLine.distance(this.cursor.x, this.cursor.y, x, y);
140
- const angle = Math.atan2(y - this.cursor.y, x - this.cursor.x);
141
- const closed = closePath && x === this.start.x && y === this.start.y;
142
- if (this.useTexture) {
143
- this.graphics.moveTo(this.cursor.x, this.cursor.y);
144
- this.adjustLineStyle(angle);
145
- if (closed && this.dash.length % 2 === 0) {
146
- const gap = Math.min(this.dash[this.dash.length - 1], length);
147
- this.graphics.lineTo(x - Math.cos(angle) * gap, y - Math.sin(angle) * gap);
148
- this.graphics.closePath();
149
- } else {
150
- this.graphics.lineTo(x, y);
151
- }
152
- } else {
153
- const cos = Math.cos(angle);
154
- const sin = Math.sin(angle);
155
- let x0 = this.cursor.x;
156
- let y0 = this.cursor.y;
157
-
158
- // find the first part of the dash for this line
159
- const place = this.lineLength % (this.dashSize * this.scale);
160
- let dashIndex: number = 0,
161
- dashStart: number = 0;
162
- let dashX = 0;
163
- for (let i = 0; i < this.dash.length; i++) {
164
- const dashSize = this.dash[i] * this.scale;
165
- if (place < dashX + dashSize) {
166
- dashIndex = i;
167
- dashStart = place - dashX;
168
- break;
169
- } else {
170
- dashX += dashSize;
171
- }
172
- }
173
-
174
- let remaining = length;
175
- // let count = 0
176
- while (remaining > 0) {
177
- // && count++ < 1000) {
178
- const dashSize = this.dash[dashIndex] * this.scale - dashStart;
179
- const dist = remaining > dashSize ? dashSize : remaining;
180
- if (closed) {
181
- const remainingDistance = DashLine.distance(x0 + cos * dist, y0 + sin * dist, this.start.x, this.start.y);
182
- if (remainingDistance <= dist) {
183
- if (dashIndex % 2 === 0) {
184
- const lastDash = DashLine.distance(x0, y0, this.start.x, this.start.y) - this.dash[this.dash.length - 1] * this.scale;
185
- x0 += cos * lastDash;
186
- y0 += sin * lastDash;
187
- this.graphics.lineTo(x0, y0);
188
- }
189
- break;
190
- }
191
- }
192
-
193
- x0 += cos * dist;
194
- y0 += sin * dist;
195
- if (dashIndex % 2) {
196
- this.graphics.moveTo(x0, y0);
197
- } else {
198
- this.graphics.lineTo(x0, y0);
199
- }
200
- remaining -= dist;
201
-
202
- dashIndex++;
203
- dashIndex = dashIndex === this.dash.length ? 0 : dashIndex;
204
- dashStart = 0;
205
- }
206
- // if (count >= 1000) console.log('failure', this.scale)
207
- }
208
- this.lineLength += length;
209
- this.cursor.set(x, y);
210
- return this;
211
- }
212
-
213
- closePath() {
214
- this.lineTo(this.start.x, this.start.y, true);
215
- }
216
-
217
- drawCircle(x: number, y: number, radius: number, points = 80, matrix?: PIXI.Matrix): this {
218
- const interval = (Math.PI * 2) / points;
219
- let angle = 0,
220
- first: PIXI.Point;
221
- if (matrix) {
222
- first = new PIXI.Point(x + Math.cos(angle) * radius, y + Math.sin(angle) * radius);
223
- matrix.apply(first, first);
224
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
225
- // @ts-ignore
226
- this.moveTo(first[0], first[1]);
227
- } else {
228
- first = new PIXI.Point(x + Math.cos(angle) * radius, y + Math.sin(angle) * radius);
229
- this.moveTo(first.x, first.y);
230
- }
231
- angle += interval;
232
- for (let i = 1; i < points + 1; i++) {
233
- const next = i === points ? first : [x + Math.cos(angle) * radius, y + Math.sin(angle) * radius];
234
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
235
- // @ts-ignore
236
- this.lineTo(next[0], next[1]);
237
- angle += interval;
238
- }
239
- return this;
240
- }
241
-
242
- drawEllipse(x: number, y: number, radiusX: number, radiusY: number, points = 80, matrix?: PIXI.Matrix): this {
243
- const interval = (Math.PI * 2) / points;
244
- let first: { x: number; y: number };
245
- const point = new PIXI.Point();
246
- for (let i = 0; i < Math.PI * 2; i += interval) {
247
- let x0 = x - radiusX * Math.sin(i);
248
- let y0 = y - radiusY * Math.cos(i);
249
- if (matrix) {
250
- point.set(x0, y0);
251
- matrix.apply(point, point);
252
- x0 = point.x;
253
- y0 = point.y;
254
- }
255
- if (i === 0) {
256
- this.moveTo(x0, y0);
257
- first = { x: x0, y: y0 };
258
- } else {
259
- this.lineTo(x0, y0);
260
- }
261
- }
262
- this.lineTo(first.x, first.y, true);
263
- return this;
264
- }
265
-
266
- drawPolygon(points: PIXI.Point[] | number[], matrix?: PIXI.Matrix): this {
267
- const p = new PIXI.Point();
268
- if (typeof points[0] === 'number') {
269
- if (matrix) {
270
- p.set(points[0] as number, points[1] as number);
271
- matrix.apply(p, p);
272
- this.moveTo(p.x, p.y);
273
- for (let i = 2; i < points.length; i += 2) {
274
- p.set(points[i] as number, points[i + 1] as number);
275
- matrix.apply(p, p);
276
- this.lineTo(p.x, p.y, i === points.length - 2);
277
- }
278
- } else {
279
- this.moveTo(points[0] as number, points[1] as number);
280
- for (let i = 2; i < points.length; i += 2) {
281
- this.lineTo(points[i] as number, points[i + 1] as number, i === points.length - 2);
282
- }
283
- }
284
- } else {
285
- if (matrix) {
286
- const point = points[0] as PIXI.Point;
287
- p.copyFrom(point);
288
- matrix.apply(p, p);
289
- this.moveTo(p.x, p.y);
290
- for (let i = 1; i < points.length; i++) {
291
- const point = points[i] as PIXI.Point;
292
- p.copyFrom(point);
293
- matrix.apply(p, p);
294
- this.lineTo(p.x, p.y, i === points.length - 1);
295
- }
296
- } else {
297
- const point = points[0] as PIXI.Point;
298
- this.moveTo(point.x, point.y);
299
- for (let i = 1; i < points.length; i++) {
300
- const point = points[i] as PIXI.Point;
301
- this.lineTo(point.x, point.y, i === points.length - 1);
302
- }
303
- }
304
- }
305
- return this;
306
- }
307
-
308
- drawRect(x: number, y: number, width: number, height: number, matrix?: PIXI.Matrix): this {
309
- if (matrix) {
310
- const p = new PIXI.Point();
311
-
312
- // moveTo(x, y)
313
- p.set(x, y);
314
- matrix.apply(p, p);
315
- this.moveTo(p.x, p.y);
316
-
317
- // lineTo(x + width, y)
318
- p.set(x + width, y);
319
- matrix.apply(p, p);
320
- this.lineTo(p.x, p.y);
321
-
322
- // lineTo(x + width, y + height)
323
- p.set(x + width, y + height);
324
- matrix.apply(p, p);
325
- this.lineTo(p.x, p.y);
326
-
327
- // lineto(x, y + height)
328
- p.set(x, y + height);
329
- matrix.apply(p, p);
330
- this.lineTo(p.x, p.y);
331
-
332
- // lineTo(x, y, true)
333
- p.set(x, y);
334
- matrix.apply(p, p);
335
- this.lineTo(p.x, p.y, true);
336
- } else {
337
- this.moveTo(x, y)
338
- .lineTo(x + width, y)
339
- .lineTo(x + width, y + height)
340
- .lineTo(x, y + height)
341
- .lineTo(x, y, true);
342
- }
343
- return this;
344
- }
345
-
346
- // adjust the matrix for the dashed texture
347
- private adjustLineStyle(angle: number) {
348
- const lineStyle = this.graphics.line;
349
- lineStyle.matrix = new PIXI.Matrix();
350
- if (angle) {
351
- lineStyle.matrix.rotate(angle);
352
- }
353
- if (this.scale !== 1) {
354
- lineStyle.matrix.scale(this.scale, this.scale);
355
- }
356
- const textureStart = -this.lineLength;
357
- lineStyle.matrix.translate(this.cursor.x + textureStart * Math.cos(angle), this.cursor.y + textureStart * Math.sin(angle));
358
- this.graphics.lineStyle(lineStyle);
359
- }
360
-
361
- // creates or uses cached texture
362
- private static getTexture(options: DashLineOptions, dashSize: number): PIXI.Texture {
363
- const key = options.dash.toString();
364
- if (DashLine.dashTextureCache[key]) {
365
- return DashLine.dashTextureCache[key];
366
- }
367
- const canvas = document.createElement('canvas');
368
- canvas.width = dashSize;
369
- canvas.height = Math.ceil(options.width);
370
- const context = canvas.getContext('2d');
371
- if (!context) {
372
- console.warn('Did not get context from canvas');
373
- return;
374
- }
375
- context.strokeStyle = 'white';
376
- context.globalAlpha = options.alpha;
377
- context.lineWidth = options.width;
378
- let x = 0;
379
- const y = options.width / 2;
380
- context.moveTo(x, y);
381
- for (let i = 0; i < options.dash.length; i += 2) {
382
- x += options.dash[i];
383
- context.lineTo(x, y);
384
- if (options.dash.length !== i + 1) {
385
- x += options.dash[i + 1];
386
- context.moveTo(x, y);
387
- }
388
- }
389
- context.stroke();
390
- const texture = (DashLine.dashTextureCache[key] = PIXI.Texture.from(canvas));
391
- texture.baseTexture.scaleMode = PIXI.SCALE_MODES.NEAREST;
392
- return texture;
393
- }
394
- }