@equinor/esv-intersection 3.0.3 → 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.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +11 -11
- package/dist/components/axis.d.ts +0 -47
- package/dist/components/index.d.ts +0 -1
- package/dist/control/ExtendedCurveInterpolator.d.ts +0 -58
- package/dist/control/IntersectionReferenceSystem.d.ts +0 -96
- package/dist/control/LayerManager.d.ts +0 -76
- package/dist/control/MainController.d.ts +0 -154
- package/dist/control/ZoomPanHandler.d.ts +0 -158
- package/dist/control/index.d.ts +0 -5
- package/dist/control/interfaces.d.ts +0 -37
- package/dist/control/overlay.d.ts +0 -20
- package/dist/datautils/colortable.d.ts +0 -1
- package/dist/datautils/findsample.d.ts +0 -2
- package/dist/datautils/index.d.ts +0 -6
- package/dist/datautils/interfaces.d.ts +0 -63
- package/dist/datautils/picks.d.ts +0 -74
- package/dist/datautils/schematicShapeGenerator.d.ts +0 -59
- package/dist/datautils/seismicimage.d.ts +0 -45
- package/dist/datautils/surfacedata.d.ts +0 -10
- package/dist/datautils/trajectory.d.ts +0 -14
- package/dist/layers/CalloutCanvasLayer.d.ts +0 -60
- package/dist/layers/CustomDisplayObjects/ComplexRope.d.ts +0 -22
- package/dist/layers/CustomDisplayObjects/ComplexRopeGeometry.d.ts +0 -27
- package/dist/layers/CustomDisplayObjects/FixedWidthSimpleRope.d.ts +0 -20
- package/dist/layers/CustomDisplayObjects/FixedWidthSimpleRopeGeometry.d.ts +0 -26
- package/dist/layers/CustomDisplayObjects/UniformTextureStretchRope.d.ts +0 -17
- package/dist/layers/CustomDisplayObjects/UniformTextureStretchRopeGeometry.d.ts +0 -24
- package/dist/layers/GeomodelCanvasLayer.d.ts +0 -28
- package/dist/layers/GeomodelLabelsLayer.d.ts +0 -49
- package/dist/layers/GeomodelLayerV2.d.ts +0 -12
- package/dist/layers/GridLayer.d.ts +0 -29
- package/dist/layers/ImageCanvasLayer.d.ts +0 -20
- package/dist/layers/ReferenceLineLayer.d.ts +0 -29
- package/dist/layers/SchematicLayer.d.ts +0 -113
- package/dist/layers/SeismicCanvasLayer.d.ts +0 -18
- package/dist/layers/WellborePathLayer.d.ts +0 -17
- package/dist/layers/base/CanvasLayer.d.ts +0 -19
- package/dist/layers/base/HTMLLayer.d.ts +0 -13
- package/dist/layers/base/Layer.d.ts +0 -69
- package/dist/layers/base/PixiLayer.d.ts +0 -32
- package/dist/layers/base/SVGLayer.d.ts +0 -13
- package/dist/layers/base/index.d.ts +0 -5
- package/dist/layers/index.d.ts +0 -16
- package/dist/layers/schematicInterfaces.d.ts +0 -209
- package/dist/utils/arc-length.d.ts +0 -23
- package/dist/utils/binary-search.d.ts +0 -8
- package/dist/utils/color.d.ts +0 -5
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/root-finder.d.ts +0 -34
- package/dist/utils/text.d.ts +0 -14
- package/dist/utils/vectorUtils.d.ts +0 -15
- package/dist/vendor/pixi-dashed-line/index.d.ts +0 -57
- package/src/components/axis.ts +0 -247
- package/src/components/index.ts +0 -1
- package/src/control/ExtendedCurveInterpolator.ts +0 -155
- package/src/control/IntersectionReferenceSystem.ts +0 -391
- package/src/control/LayerManager.ts +0 -294
- package/src/control/MainController.ts +0 -296
- package/src/control/ZoomPanHandler.ts +0 -436
- package/src/control/index.ts +0 -5
- package/src/control/interfaces.ts +0 -42
- package/src/control/overlay.ts +0 -118
- package/src/datautils/colortable.ts +0 -14
- package/src/datautils/findsample.ts +0 -64
- package/src/datautils/index.ts +0 -6
- package/src/datautils/interfaces.ts +0 -68
- package/src/datautils/picks.ts +0 -328
- package/src/datautils/schematicShapeGenerator.ts +0 -1008
- package/src/datautils/seismicimage.ts +0 -180
- package/src/datautils/surfacedata.ts +0 -318
- package/src/datautils/trajectory.ts +0 -206
- package/src/layers/CalloutCanvasLayer.ts +0 -338
- package/src/layers/CustomDisplayObjects/ComplexRope.ts +0 -45
- package/src/layers/CustomDisplayObjects/ComplexRopeGeometry.ts +0 -190
- package/src/layers/CustomDisplayObjects/FixedWidthSimpleRope.ts +0 -41
- package/src/layers/CustomDisplayObjects/FixedWidthSimpleRopeGeometry.ts +0 -149
- package/src/layers/CustomDisplayObjects/UniformTextureStretchRope.ts +0 -39
- package/src/layers/CustomDisplayObjects/UniformTextureStretchRopeGeometry.ts +0 -174
- package/src/layers/GeomodelCanvasLayer.ts +0 -176
- package/src/layers/GeomodelLabelsLayer.ts +0 -619
- package/src/layers/GeomodelLayerV2.ts +0 -110
- package/src/layers/GridLayer.ts +0 -145
- package/src/layers/ImageCanvasLayer.ts +0 -55
- package/src/layers/ReferenceLineLayer.ts +0 -185
- package/src/layers/SchematicLayer.ts +0 -872
- package/src/layers/SeismicCanvasLayer.ts +0 -46
- package/src/layers/WellborePathLayer.ts +0 -129
- package/src/layers/base/CanvasLayer.ts +0 -102
- package/src/layers/base/HTMLLayer.ts +0 -70
- package/src/layers/base/Layer.ts +0 -217
- package/src/layers/base/PixiLayer.ts +0 -190
- package/src/layers/base/SVGLayer.ts +0 -63
- package/src/layers/base/index.ts +0 -5
- package/src/layers/index.ts +0 -16
- package/src/layers/schematicInterfaces.ts +0 -472
- package/src/utils/arc-length.ts +0 -66
- package/src/utils/binary-search.ts +0 -26
- package/src/utils/color.ts +0 -22
- package/src/utils/index.ts +0 -1
- package/src/utils/root-finder.ts +0 -78
- package/src/utils/text.ts +0 -88
- package/src/utils/vectorUtils.ts +0 -67
- package/src/vendor/pixi-dashed-line/index.ts +0 -394
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { IPoint, MeshGeometry } from 'pixi.js';
|
|
2
|
-
|
|
3
|
-
export class FixedWidthSimpleRopeGeometry extends MeshGeometry {
|
|
4
|
-
public points: IPoint[];
|
|
5
|
-
_width: number;
|
|
6
|
-
/**
|
|
7
|
-
* @param {number} [width=200] - The width (i.e., thickness) of the rope.
|
|
8
|
-
* @param {PIXI.Point[]} [points] - An array of PIXI.Point objects to construct this rope.
|
|
9
|
-
*/
|
|
10
|
-
constructor(points: IPoint[], width = 200) {
|
|
11
|
-
// eslint-disable-next-line no-magic-numbers
|
|
12
|
-
super(new Float32Array(points.length * 4), new Float32Array(points.length * 4), new Uint16Array((points.length - 1) * 6));
|
|
13
|
-
/**
|
|
14
|
-
* An array of points that determine the rope
|
|
15
|
-
* @member {PIXI.Point[]}
|
|
16
|
-
*/
|
|
17
|
-
this.points = points;
|
|
18
|
-
/**
|
|
19
|
-
* The width (i.e., thickness) of the rope.
|
|
20
|
-
* @member {number}
|
|
21
|
-
* @readOnly
|
|
22
|
-
*/
|
|
23
|
-
this._width = width;
|
|
24
|
-
/**
|
|
25
|
-
* Rope texture scale, if zero then the rope texture is stretched.
|
|
26
|
-
* @member {number}
|
|
27
|
-
* @readOnly
|
|
28
|
-
*/
|
|
29
|
-
this.build();
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* The width (i.e., thickness) of the rope.
|
|
33
|
-
* @member {number}
|
|
34
|
-
* @readOnly
|
|
35
|
-
*/
|
|
36
|
-
get width(): number {
|
|
37
|
-
return this._width;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Refreshes Rope indices and uvs
|
|
41
|
-
* @private
|
|
42
|
-
*/
|
|
43
|
-
private build(): void {
|
|
44
|
-
const points = this.points;
|
|
45
|
-
if (!points) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const vertexBuffer = this.getBuffer('aVertexPosition');
|
|
49
|
-
const uvBuffer = this.getBuffer('aTextureCoord');
|
|
50
|
-
const indexBuffer = this.getIndex();
|
|
51
|
-
// if too little points, or texture hasn't got UVs set yet just move on.
|
|
52
|
-
if (points.length < 1) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
// if the number of points has changed we will need to recreate the arraybuffers
|
|
56
|
-
if (vertexBuffer.data.length / 4 !== points.length) {
|
|
57
|
-
vertexBuffer.data = new Float32Array(points.length * 4);
|
|
58
|
-
uvBuffer.data = new Float32Array(points.length * 4);
|
|
59
|
-
// eslint-disable-next-line no-magic-numbers
|
|
60
|
-
indexBuffer.data = new Uint16Array((points.length - 1) * 6);
|
|
61
|
-
}
|
|
62
|
-
const uvs = uvBuffer.data;
|
|
63
|
-
const indices = indexBuffer.data;
|
|
64
|
-
uvs[0] = 0;
|
|
65
|
-
uvs[1] = 0;
|
|
66
|
-
uvs[2] = 0;
|
|
67
|
-
uvs[3] = 1;
|
|
68
|
-
let amount = 0;
|
|
69
|
-
let prev = points[0];
|
|
70
|
-
const total = points.length; // - 1;
|
|
71
|
-
for (let i = 0; i < total; i++) {
|
|
72
|
-
// time to do some smart drawing!
|
|
73
|
-
const index = i * 4;
|
|
74
|
-
|
|
75
|
-
// calculate pixel distance from previous point
|
|
76
|
-
const dx = prev.x - points[i].x;
|
|
77
|
-
const dy = prev.y - points[i].y;
|
|
78
|
-
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
79
|
-
prev = points[i];
|
|
80
|
-
amount += distance / this._width;
|
|
81
|
-
|
|
82
|
-
uvs[index] = amount;
|
|
83
|
-
uvs[index + 1] = 0;
|
|
84
|
-
uvs[index + 2] = amount;
|
|
85
|
-
uvs[index + 3] = 1;
|
|
86
|
-
}
|
|
87
|
-
let indexCount = 0;
|
|
88
|
-
for (let i = 0; i < total - 1; i++) {
|
|
89
|
-
const index = i * 2;
|
|
90
|
-
indices[indexCount++] = index;
|
|
91
|
-
indices[indexCount++] = index + 1;
|
|
92
|
-
indices[indexCount++] = index + 2;
|
|
93
|
-
indices[indexCount++] = index + 2;
|
|
94
|
-
indices[indexCount++] = index + 1;
|
|
95
|
-
indices[indexCount++] = index + 3;
|
|
96
|
-
}
|
|
97
|
-
// ensure that the changes are uploaded
|
|
98
|
-
uvBuffer.update();
|
|
99
|
-
indexBuffer.update();
|
|
100
|
-
this.updateVertices();
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* refreshes vertices of Rope mesh
|
|
104
|
-
*/
|
|
105
|
-
public updateVertices(): void {
|
|
106
|
-
const points = this.points;
|
|
107
|
-
if (points.length < 1) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
let lastPoint = points[0];
|
|
111
|
-
let nextPoint;
|
|
112
|
-
let perpX = 0;
|
|
113
|
-
let perpY = 0;
|
|
114
|
-
const vertices = this.buffers[0].data;
|
|
115
|
-
const total = points.length;
|
|
116
|
-
for (let i = 0; i < total; i++) {
|
|
117
|
-
const point = points[i];
|
|
118
|
-
const index = i * 4;
|
|
119
|
-
if (i < points.length - 1) {
|
|
120
|
-
nextPoint = points[i + 1];
|
|
121
|
-
} else {
|
|
122
|
-
nextPoint = point;
|
|
123
|
-
}
|
|
124
|
-
perpY = -(nextPoint.x - lastPoint.x);
|
|
125
|
-
perpX = nextPoint.y - lastPoint.y;
|
|
126
|
-
// eslint-disable-next-line no-magic-numbers
|
|
127
|
-
let ratio = (1 - i / (total - 1)) * 10;
|
|
128
|
-
if (ratio > 1) {
|
|
129
|
-
ratio = 1;
|
|
130
|
-
}
|
|
131
|
-
const perpLength = Math.sqrt(perpX * perpX + perpY * perpY);
|
|
132
|
-
const num = this._width / 2;
|
|
133
|
-
perpX /= perpLength;
|
|
134
|
-
perpY /= perpLength;
|
|
135
|
-
perpX *= num;
|
|
136
|
-
perpY *= num;
|
|
137
|
-
vertices[index] = point.x + perpX;
|
|
138
|
-
vertices[index + 1] = point.y + perpY;
|
|
139
|
-
vertices[index + 2] = point.x - perpX;
|
|
140
|
-
vertices[index + 3] = point.y - perpY;
|
|
141
|
-
lastPoint = point;
|
|
142
|
-
}
|
|
143
|
-
this.buffers[0].update();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
public update(): void {
|
|
147
|
-
this.build();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { IPoint, Mesh, MeshMaterial, Renderer, Texture } from 'pixi.js';
|
|
2
|
-
import { UniformTextureStretchRopeGeometry } from './UniformTextureStretchRopeGeometry';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The UniformTextureStretchRope allows you to draw a texture across several points and then manipulate these points
|
|
6
|
-
*/
|
|
7
|
-
export class UniformTextureStretchRope extends Mesh {
|
|
8
|
-
/**
|
|
9
|
-
* re-calculate vertices by rope points each frame
|
|
10
|
-
* @member {boolean}
|
|
11
|
-
*/
|
|
12
|
-
public autoUpdate: boolean;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @param texture - The texture to use on the rope.
|
|
16
|
-
* @param points - An array of {@link PIXI.Point} objects to construct this rope.
|
|
17
|
-
*/
|
|
18
|
-
constructor(texture: Texture, points: IPoint[]) {
|
|
19
|
-
const ropeGeometry = new UniformTextureStretchRopeGeometry(points, texture.height);
|
|
20
|
-
const meshMaterial = new MeshMaterial(texture);
|
|
21
|
-
|
|
22
|
-
super(ropeGeometry, meshMaterial);
|
|
23
|
-
|
|
24
|
-
this.autoUpdate = true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
_render(renderer: Renderer): void {
|
|
28
|
-
const geometry: UniformTextureStretchRopeGeometry = this.geometry as UniformTextureStretchRopeGeometry;
|
|
29
|
-
|
|
30
|
-
// TODO: Possible optimiztion here
|
|
31
|
-
// Find correct check for when to update geometry
|
|
32
|
-
if (this.autoUpdate || geometry._width !== this.shader.texture.height) {
|
|
33
|
-
geometry._width = this.shader.texture.height;
|
|
34
|
-
geometry.update();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
super._render(renderer);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { MeshGeometry } from 'pixi.js';
|
|
2
|
-
import type { IPoint } from 'pixi.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* UniformTextureStretchRopeGeometry allows you to draw a geometry across several points and then manipulate these points.
|
|
6
|
-
*/
|
|
7
|
-
export class UniformTextureStretchRopeGeometry extends MeshGeometry {
|
|
8
|
-
/** An array of points that determine the rope. */
|
|
9
|
-
public points: IPoint[];
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The width (i.e., thickness) of the rope.
|
|
13
|
-
* @readonly
|
|
14
|
-
*/
|
|
15
|
-
_width: number;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @param width - The width (i.e., thickness) of the rope.
|
|
19
|
-
* @param points - An array of PIXI.Point objects to construct this rope.
|
|
20
|
-
*/
|
|
21
|
-
constructor(points: IPoint[], width = 200) {
|
|
22
|
-
// eslint-disable-next-line no-magic-numbers
|
|
23
|
-
super(new Float32Array(points.length * 4), new Float32Array(points.length * 4), new Uint16Array((points.length - 1) * 6));
|
|
24
|
-
|
|
25
|
-
this.points = points;
|
|
26
|
-
this._width = width;
|
|
27
|
-
|
|
28
|
-
this.build();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Refreshes Rope indices and uvs */
|
|
32
|
-
private build(): void {
|
|
33
|
-
const points = this.points;
|
|
34
|
-
|
|
35
|
-
if (!points) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const vertexBuffer = this.getBuffer('aVertexPosition');
|
|
40
|
-
const uvBuffer = this.getBuffer('aTextureCoord');
|
|
41
|
-
const indexBuffer = this.getIndex();
|
|
42
|
-
|
|
43
|
-
// if too few points, or texture hasn't got UVs set yet just move on.
|
|
44
|
-
if (points.length < 1) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// if the number of points has changed we will need to recreate the arraybuffers
|
|
49
|
-
if (vertexBuffer.data.length / 4 !== points.length) {
|
|
50
|
-
vertexBuffer.data = new Float32Array(points.length * 4);
|
|
51
|
-
uvBuffer.data = new Float32Array(points.length * 4);
|
|
52
|
-
indexBuffer.data = new Uint16Array((points.length - 1) * 6); // eslint-disable-line no-magic-numbers
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const total = points.length; // - 1;
|
|
56
|
-
|
|
57
|
-
let totalLength = 0;
|
|
58
|
-
let prevPoint = points[0];
|
|
59
|
-
|
|
60
|
-
for (let i = 0; i < total; i++) {
|
|
61
|
-
const dx = prevPoint.x - points[i].x;
|
|
62
|
-
const dy = prevPoint.y - points[i].y;
|
|
63
|
-
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
64
|
-
|
|
65
|
-
prevPoint = points[i];
|
|
66
|
-
totalLength += distance;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const uvs = uvBuffer.data;
|
|
70
|
-
const indices = indexBuffer.data;
|
|
71
|
-
|
|
72
|
-
uvs[0] = 0;
|
|
73
|
-
uvs[1] = 0;
|
|
74
|
-
uvs[2] = 0;
|
|
75
|
-
uvs[3] = 1;
|
|
76
|
-
|
|
77
|
-
let amount = 0;
|
|
78
|
-
let prev = points[0];
|
|
79
|
-
|
|
80
|
-
for (let i = 0; i < total; i++) {
|
|
81
|
-
// time to do some smart drawing!
|
|
82
|
-
const index = i * 4;
|
|
83
|
-
|
|
84
|
-
// calculate pixel distance from previous point
|
|
85
|
-
const dx = prev.x - points[i].x;
|
|
86
|
-
const dy = prev.y - points[i].y;
|
|
87
|
-
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
88
|
-
|
|
89
|
-
prev = points[i];
|
|
90
|
-
|
|
91
|
-
// strech texture on distance/length instead of point/points.length to get a more correct strech
|
|
92
|
-
amount += distance / totalLength;
|
|
93
|
-
|
|
94
|
-
uvs[index] = amount;
|
|
95
|
-
uvs[index + 1] = 0;
|
|
96
|
-
|
|
97
|
-
uvs[index + 2] = amount;
|
|
98
|
-
uvs[index + 3] = 1;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
let indexCount = 0;
|
|
102
|
-
|
|
103
|
-
for (let i = 0; i < total - 1; i++) {
|
|
104
|
-
const index = i * 2;
|
|
105
|
-
|
|
106
|
-
indices[indexCount++] = index;
|
|
107
|
-
indices[indexCount++] = index + 1;
|
|
108
|
-
indices[indexCount++] = index + 2;
|
|
109
|
-
|
|
110
|
-
indices[indexCount++] = index + 2;
|
|
111
|
-
indices[indexCount++] = index + 1;
|
|
112
|
-
indices[indexCount++] = index + 3;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// ensure that the changes are uploaded
|
|
116
|
-
uvBuffer.update();
|
|
117
|
-
indexBuffer.update();
|
|
118
|
-
|
|
119
|
-
this.updateVertices();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/** refreshes vertices of Rope mesh */
|
|
123
|
-
public updateVertices(): void {
|
|
124
|
-
const points = this.points;
|
|
125
|
-
|
|
126
|
-
if (points.length < 1) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
let lastPoint = points[0];
|
|
131
|
-
let nextPoint;
|
|
132
|
-
let perpX = 0;
|
|
133
|
-
let perpY = 0;
|
|
134
|
-
|
|
135
|
-
const vertices = this.buffers[0].data;
|
|
136
|
-
const total = points.length;
|
|
137
|
-
|
|
138
|
-
for (let i = 0; i < total; i++) {
|
|
139
|
-
const point = points[i];
|
|
140
|
-
const index = i * 4;
|
|
141
|
-
|
|
142
|
-
if (i < points.length - 1) {
|
|
143
|
-
nextPoint = points[i + 1];
|
|
144
|
-
} else {
|
|
145
|
-
nextPoint = point;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
perpY = -(nextPoint.x - lastPoint.x);
|
|
149
|
-
perpX = nextPoint.y - lastPoint.y;
|
|
150
|
-
|
|
151
|
-
const perpLength = Math.sqrt(perpX * perpX + perpY * perpY);
|
|
152
|
-
const num = this._width / 2;
|
|
153
|
-
|
|
154
|
-
perpX /= perpLength;
|
|
155
|
-
perpY /= perpLength;
|
|
156
|
-
|
|
157
|
-
perpX *= num;
|
|
158
|
-
perpY *= num;
|
|
159
|
-
|
|
160
|
-
vertices[index] = point.x + perpX;
|
|
161
|
-
vertices[index + 1] = point.y + perpY;
|
|
162
|
-
vertices[index + 2] = point.x - perpX;
|
|
163
|
-
vertices[index + 3] = point.y - perpY;
|
|
164
|
-
|
|
165
|
-
lastPoint = point;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
this.buffers[0].update();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
public update(): void {
|
|
172
|
-
this.updateVertices();
|
|
173
|
-
}
|
|
174
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { SurfaceArea, SurfaceData, SurfaceLine } from '../datautils';
|
|
2
|
-
import { OnUpdateEvent, OnRescaleEvent } from '../interfaces';
|
|
3
|
-
import { colorToCSSColor } from '../utils/color';
|
|
4
|
-
import { LayerOptions } from './base';
|
|
5
|
-
import { CanvasLayer } from './base/CanvasLayer';
|
|
6
|
-
|
|
7
|
-
const DEFAULT_MAX_DEPTH = 10000;
|
|
8
|
-
|
|
9
|
-
type SurfacePaths = {
|
|
10
|
-
color: string;
|
|
11
|
-
path: Path2D;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export class GeomodelCanvasLayer<T extends SurfaceData> extends CanvasLayer<T> {
|
|
15
|
-
rescaleEvent: OnRescaleEvent;
|
|
16
|
-
|
|
17
|
-
surfaceAreasPaths: SurfacePaths[] = [];
|
|
18
|
-
|
|
19
|
-
surfaceLinesPaths: SurfacePaths[] = [];
|
|
20
|
-
|
|
21
|
-
maxDepth: number = DEFAULT_MAX_DEPTH;
|
|
22
|
-
|
|
23
|
-
constructor(id?: string, options?: LayerOptions<T>) {
|
|
24
|
-
super(id, options);
|
|
25
|
-
this.render = this.render.bind(this);
|
|
26
|
-
this.generateSurfaceAreasPaths = this.generateSurfaceAreasPaths.bind(this);
|
|
27
|
-
this.generateSurfaceLinesPaths = this.generateSurfaceLinesPaths.bind(this);
|
|
28
|
-
this.drawPolygonPath = this.drawPolygonPath.bind(this);
|
|
29
|
-
this.drawLinePath = this.drawLinePath.bind(this);
|
|
30
|
-
this.updatePaths = this.updatePaths.bind(this);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
onUpdate(event: OnUpdateEvent<T>): void {
|
|
34
|
-
super.onUpdate(event);
|
|
35
|
-
this.updatePaths();
|
|
36
|
-
this.render();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
onRescale(event: OnRescaleEvent): void {
|
|
40
|
-
this.rescaleEvent = event;
|
|
41
|
-
this.setTransform(this.rescaleEvent);
|
|
42
|
-
this.render();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
updatePaths(): void {
|
|
46
|
-
if (!this.data) {
|
|
47
|
-
this.surfaceAreasPaths = [];
|
|
48
|
-
this.surfaceLinesPaths = [];
|
|
49
|
-
} else {
|
|
50
|
-
this.generateSurfaceAreasPaths();
|
|
51
|
-
this.generateSurfaceLinesPaths();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
render(): void {
|
|
56
|
-
if (!this.ctx || !this.rescaleEvent) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
requestAnimationFrame(() => {
|
|
61
|
-
this.clearCanvas();
|
|
62
|
-
this.surfaceAreasPaths.forEach((p: SurfacePaths) => this.drawPolygonPath(p.color, p.path));
|
|
63
|
-
this.surfaceLinesPaths.forEach((l: SurfacePaths) => this.drawLinePath(l.color, l.path));
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
colorToCSSColor(color: number | string): string {
|
|
68
|
-
return colorToCSSColor(color);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
generateSurfaceAreasPaths(): void {
|
|
72
|
-
this.surfaceAreasPaths = this.data.areas.reduce((acc: SurfacePaths[], s: SurfaceArea) => {
|
|
73
|
-
const polygons = this.createPolygons(s.data);
|
|
74
|
-
const mapped: SurfacePaths[] = polygons.map((polygon: number[]) => ({
|
|
75
|
-
color: this.colorToCSSColor(s.color),
|
|
76
|
-
path: this.generatePolygonPath(polygon),
|
|
77
|
-
}));
|
|
78
|
-
acc.push(...mapped);
|
|
79
|
-
return acc;
|
|
80
|
-
}, []);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
generateSurfaceLinesPaths(): void {
|
|
84
|
-
this.surfaceLinesPaths = this.data.lines.reduce((acc: SurfacePaths[], l: SurfaceLine) => {
|
|
85
|
-
const lines = this.generateLinePaths(l);
|
|
86
|
-
const mapped: SurfacePaths[] = lines.map((path: Path2D) => ({ color: this.colorToCSSColor(l.color), path }));
|
|
87
|
-
acc.push(...mapped);
|
|
88
|
-
return acc;
|
|
89
|
-
}, []);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
drawPolygonPath = (color: string, path: Path2D): void => {
|
|
93
|
-
const { ctx } = this;
|
|
94
|
-
ctx.fillStyle = color;
|
|
95
|
-
ctx.fill(path);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
drawLinePath = (color: string, path: Path2D): void => {
|
|
99
|
-
const { ctx } = this;
|
|
100
|
-
ctx.strokeStyle = color;
|
|
101
|
-
ctx.stroke(path);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
createPolygons = (data: number[][]): number[][] => {
|
|
105
|
-
const polygons: number[][] = [];
|
|
106
|
-
let polygon: number[] = null;
|
|
107
|
-
|
|
108
|
-
// Start generating polygons
|
|
109
|
-
for (let i = 0; i < data.length; i++) {
|
|
110
|
-
// Generate top of polygon as long as we have valid values
|
|
111
|
-
const topIsValid = !!data[i][1];
|
|
112
|
-
if (topIsValid) {
|
|
113
|
-
if (polygon === null) {
|
|
114
|
-
polygon = [];
|
|
115
|
-
}
|
|
116
|
-
polygon.push(data[i][0], data[i][1]);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const endIsReached = i === data.length - 1;
|
|
120
|
-
if (!topIsValid || endIsReached) {
|
|
121
|
-
if (polygon) {
|
|
122
|
-
// Generate bottom of polygon
|
|
123
|
-
for (let j: number = !topIsValid ? i - 1 : i; j >= 0; j--) {
|
|
124
|
-
if (!data[j][1]) {
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
polygon.push(data[j][0], data[j][2] || this.maxDepth);
|
|
128
|
-
}
|
|
129
|
-
polygons.push(polygon);
|
|
130
|
-
polygon = null;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return polygons;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
generatePolygonPath = (polygon: number[]): Path2D => {
|
|
139
|
-
const path = new Path2D();
|
|
140
|
-
|
|
141
|
-
path.moveTo(polygon[0], polygon[1]);
|
|
142
|
-
for (let i = 2; i < polygon.length; i += 2) {
|
|
143
|
-
path.lineTo(polygon[i], polygon[i + 1]);
|
|
144
|
-
}
|
|
145
|
-
path.closePath();
|
|
146
|
-
|
|
147
|
-
return path;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
generateLinePaths = (s: SurfaceLine): Path2D[] => {
|
|
151
|
-
const paths: Path2D[] = [];
|
|
152
|
-
const { data: d } = s;
|
|
153
|
-
|
|
154
|
-
let penDown = false;
|
|
155
|
-
let path = null;
|
|
156
|
-
for (let i = 0; i < d.length; i++) {
|
|
157
|
-
if (d[i][1]) {
|
|
158
|
-
if (penDown) {
|
|
159
|
-
path.lineTo(d[i][0], d[i][1]);
|
|
160
|
-
} else {
|
|
161
|
-
path = new Path2D();
|
|
162
|
-
path.moveTo(d[i][0], d[i][1]);
|
|
163
|
-
penDown = true;
|
|
164
|
-
}
|
|
165
|
-
} else if (penDown) {
|
|
166
|
-
paths.push(path);
|
|
167
|
-
penDown = false;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (penDown) {
|
|
171
|
-
paths.push(path);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return paths;
|
|
175
|
-
};
|
|
176
|
-
}
|