@protomaze/geometry 0.0.0-stage → 0.1.0

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 (118) hide show
  1. package/GeometryDemo.d.ts +1 -0
  2. package/GeometryDemo.js +1 -0
  3. package/README.md +294 -2
  4. package/common/Colors.d.ts +47 -0
  5. package/common/Colors.js +1 -0
  6. package/common/Disposables.d.ts +7 -0
  7. package/common/Disposables.js +1 -0
  8. package/data/Geometry.d.ts +62 -0
  9. package/data/Geometry.js +1 -0
  10. package/demo/DemoControls.d.ts +68 -0
  11. package/demo/DemoControls.js +1 -0
  12. package/demo/Town.d.ts +115 -0
  13. package/demo/Town.js +1 -0
  14. package/edit/CreateController.d.ts +101 -0
  15. package/edit/CreateController.js +1 -0
  16. package/edit/EditController.d.ts +121 -0
  17. package/edit/EditController.js +1 -0
  18. package/edit/EditHistory.d.ts +46 -0
  19. package/edit/EditHistory.js +1 -0
  20. package/edit/EditShape.d.ts +45 -0
  21. package/edit/EditShape.js +1 -0
  22. package/edit/GeometryController.d.ts +83 -0
  23. package/edit/GeometryController.js +1 -0
  24. package/edit/MeasureController.d.ts +102 -0
  25. package/edit/MeasureController.js +1 -0
  26. package/edit/Sketch.d.ts +73 -0
  27. package/edit/Sketch.js +1 -0
  28. package/edit/Snapper.d.ts +67 -0
  29. package/edit/Snapper.js +1 -0
  30. package/engine/GeometryEngine.d.ts +257 -0
  31. package/engine/GeometryEngine.js +1 -0
  32. package/engine/GeometryFrame.d.ts +91 -0
  33. package/engine/GeometryFrame.js +1 -0
  34. package/engine/GeometryOptions.d.ts +79 -0
  35. package/engine/GeometryOptions.js +1 -0
  36. package/engine/GeometryView.d.ts +192 -0
  37. package/engine/GeometryView.js +1 -0
  38. package/engine/Labels.d.ts +42 -0
  39. package/engine/Labels.js +1 -0
  40. package/engine/MapCamera.d.ts +78 -0
  41. package/engine/MapCamera.js +1 -0
  42. package/event/TypedEventEmitter.d.ts +13 -0
  43. package/event/TypedEventEmitter.js +1 -0
  44. package/index.d.ts +53 -0
  45. package/index.js +1 -0
  46. package/layers/AreaLayer.d.ts +36 -0
  47. package/layers/AreaLayer.js +1 -0
  48. package/layers/GeometryLayer.d.ts +312 -0
  49. package/layers/GeometryLayer.js +1 -0
  50. package/layers/LineLayer.d.ts +48 -0
  51. package/layers/LineLayer.js +1 -0
  52. package/layers/PointLayer.d.ts +42 -0
  53. package/layers/PointLayer.js +1 -0
  54. package/layers/SphereLayer.d.ts +25 -0
  55. package/layers/SphereLayer.js +1 -0
  56. package/layers/TubeLayer.d.ts +52 -0
  57. package/layers/TubeLayer.js +1 -0
  58. package/math/Boolean.d.ts +21 -0
  59. package/math/Boolean.js +1 -0
  60. package/math/FeatureIndex.d.ts +70 -0
  61. package/math/FeatureIndex.js +1 -0
  62. package/math/Geodesy.d.ts +29 -0
  63. package/math/Geodesy.js +1 -0
  64. package/math/Lines.d.ts +115 -0
  65. package/math/Lines.js +1 -0
  66. package/math/Measure.d.ts +71 -0
  67. package/math/Measure.js +1 -0
  68. package/math/Polygons.d.ts +59 -0
  69. package/math/Polygons.js +1 -0
  70. package/math/Projection.d.ts +25 -0
  71. package/math/Projection.js +1 -0
  72. package/math/Relations.d.ts +27 -0
  73. package/math/Relations.js +1 -0
  74. package/math/SpatialIndex.d.ts +36 -0
  75. package/math/SpatialIndex.js +1 -0
  76. package/math/Transform.d.ts +36 -0
  77. package/math/Transform.js +1 -0
  78. package/math/Triangulate.d.ts +19 -0
  79. package/math/Triangulate.js +1 -0
  80. package/math/Vector.d.ts +24 -0
  81. package/math/Vector.js +1 -0
  82. package/package.json +76 -4
  83. package/react/ReactGeometry.d.ts +35 -0
  84. package/react/ReactGeometry.js +1 -0
  85. package/three/CanvasGeometryEngine.d.ts +79 -0
  86. package/three/CanvasGeometryEngine.js +1 -0
  87. package/three/DensityMap.d.ts +31 -0
  88. package/three/DensityMap.js +1 -0
  89. package/three/FeatureLook.d.ts +191 -0
  90. package/three/FeatureLook.js +1 -0
  91. package/three/Ground.d.ts +54 -0
  92. package/three/Ground.js +1 -0
  93. package/three/Halo.d.ts +26 -0
  94. package/three/Halo.js +1 -0
  95. package/three/HostedGeometryEngine.d.ts +57 -0
  96. package/three/HostedGeometryEngine.js +1 -0
  97. package/three/RiaGeometryEngine.d.ts +48 -0
  98. package/three/RiaGeometryEngine.js +1 -0
  99. package/three/Shading.d.ts +42 -0
  100. package/three/Shading.js +1 -0
  101. package/three/Sky.d.ts +27 -0
  102. package/three/Sky.js +1 -0
  103. package/three/Tsl.d.ts +47 -0
  104. package/three/Tsl.js +1 -0
  105. package/three/primitives/Body.d.ts +82 -0
  106. package/three/primitives/Body.js +1 -0
  107. package/three/primitives/GpuAreas.d.ts +72 -0
  108. package/three/primitives/GpuAreas.js +1 -0
  109. package/three/primitives/GpuIcons.d.ts +112 -0
  110. package/three/primitives/GpuIcons.js +1 -0
  111. package/three/primitives/GpuLines.d.ts +198 -0
  112. package/three/primitives/GpuLines.js +1 -0
  113. package/three/primitives/GpuSpheres.d.ts +55 -0
  114. package/three/primitives/GpuSpheres.js +1 -0
  115. package/three/primitives/GpuTubes.d.ts +125 -0
  116. package/three/primitives/GpuTubes.js +1 -0
  117. package/three/primitives/IconAtlas.d.ts +12 -0
  118. package/three/primitives/IconAtlas.js +1 -0
@@ -0,0 +1,312 @@
1
+ import { ColorLike, ColorRamp, Rgba } from '../common/Colors';
2
+ import { GeometryFeature, GeometryId, Bounds3 } from '../data/Geometry';
3
+ import { GeometryEngine } from '../engine/GeometryEngine';
4
+ import { GeometryPrimitive, PickOptions } from '../engine/GeometryFrame';
5
+ import { TypedEventEmitter } from '../event/TypedEventEmitter';
6
+ import { FeatureLook, FeatureLookStyle, FeatureState } from '../three/FeatureLook';
7
+ import { Lighting } from '../three/Shading';
8
+ /** How what is lit - selected, pointed at - is set off. */
9
+ export interface ResolvedHighlight {
10
+ /** A glow round it (bloomed, or drawn in the line shader), or an outline. */
11
+ look: 'glow' | 'outline';
12
+ /** Where the glow comes from: the bloom pass (soft, over everything) or the line shader (cheap). */
13
+ glow: 'bloom' | 'shader';
14
+ outlineColor: Rgba;
15
+ /** View pixels. */
16
+ outlineWidth: number;
17
+ /** Whether pointing at something shades the rest, and how much is left of their brightness. */
18
+ hoverFades: boolean;
19
+ othersShade: number;
20
+ /** What the rest is shaded towards: 0 black (a dark map), 1 white (a light one). */
21
+ othersToward: number;
22
+ /** Whether pointing at a feature lights it as the selection is. */
23
+ hoverLights: boolean;
24
+ }
25
+ /** What a layer needs of the view it is in. */
26
+ export interface LayerHost {
27
+ readonly engine: GeometryEngine;
28
+ readonly mode: '2d' | '3d';
29
+ /** The ground's up at the origin. */
30
+ readonly up: [number, number, number];
31
+ readonly highlight: ResolvedHighlight;
32
+ /** Shared light for the bodies of every layer. */
33
+ readonly lighting: Lighting;
34
+ /** Whether anything at all is pointed at, in any layer: the rest is shaded then. */
35
+ readonly anyHovered: boolean;
36
+ /** How many of the volumes' windows are lit: a dark theme's night, a light one's day. */
37
+ readonly windowsLit?: number;
38
+ /** Where a layer stands among the host's, 0 the lowest: what lies over what where they meet. */
39
+ rankOf?(layer: GeometryLayer<any, any>): number;
40
+ requestRepaint(): void;
41
+ setAnimating(key: string, animating: boolean): void;
42
+ }
43
+ export type CategoryModeName = 'hidden' | 'faded' | 'shown' | 'lit';
44
+ /**
45
+ * The GPU's category filter and colouring: every feature's category, numbered in the order `keys`
46
+ * lists them, or in the order first seen.
47
+ */
48
+ export interface CategorySpec<F> {
49
+ of: (feature: F) => string | number | null | undefined;
50
+ keys?: readonly (string | number)[];
51
+ /** How each category is drawn; one left out is shown. */
52
+ modes?: Record<string, CategoryModeName>;
53
+ /** Each category's colour, for `colorBy({ by: 'category' })`; a palette by default. */
54
+ colors?: Record<string, ColorLike> | readonly ColorLike[];
55
+ }
56
+ /** The GPU's range filter: every feature's value, and the range it is held against. */
57
+ export interface RangeSpec<F> {
58
+ value: (feature: F) => number;
59
+ low: number;
60
+ high: number;
61
+ /** What falls out of it: hidden, or faded. */
62
+ outside?: 'hide' | 'fade';
63
+ }
64
+ /** What the features are coloured by on the GPU: their style, their category, or a value on a ramp. */
65
+ export type ColorBySpec<F> = {
66
+ by: 'style';
67
+ } | {
68
+ by: 'category';
69
+ } | {
70
+ value: (feature: F) => number;
71
+ ramp: ColorRamp;
72
+ domain: [number, number];
73
+ };
74
+ /** What a pick or hover found in a layer. */
75
+ export interface LayerHit<F = GeometryFeature> {
76
+ layer: GeometryLayer<any, any>;
77
+ feature: F;
78
+ id: GeometryId;
79
+ index: number;
80
+ }
81
+ export type SelectMode = 'replace' | 'add' | 'toggle' | 'remove';
82
+ export interface GeometryLayerEvents {
83
+ change: {
84
+ what: 'features' | 'style' | 'selection' | 'filter' | 'visibility';
85
+ };
86
+ /** A build: afresh, or `refresh` - features changed in place, the shaders kept. */
87
+ build: {
88
+ ms: number;
89
+ features: number;
90
+ instances: number;
91
+ refresh?: boolean;
92
+ };
93
+ }
94
+ /** A state forced on features whatever their style and the filters say: what an editor sets off. */
95
+ export type FeatureStateOverride = 'faded' | 'hidden' | 'selected';
96
+ /** What every layer takes. */
97
+ export interface GeometryLayerOptions<F, S> {
98
+ id?: string;
99
+ features?: F[];
100
+ /** How each feature looks: one style for all, or one per feature. */
101
+ style?: S | ((feature: F, index: number) => S);
102
+ visible?: boolean;
103
+ pickable?: boolean;
104
+ /** The whole layer's opacity. */
105
+ opacity?: number;
106
+ /** A name for a legend. */
107
+ title?: string;
108
+ }
109
+ /** What every style has. */
110
+ export interface BaseStyle {
111
+ color?: ColorLike;
112
+ /** Times the colour's alpha. */
113
+ opacity?: number;
114
+ /** Drawn faded, or not at all, whatever the filters say. */
115
+ state?: 'default' | 'faded' | 'hidden';
116
+ /** What it adds to the heatmap (1). */
117
+ weight?: number;
118
+ }
119
+ /** A primitive's look, and what of a feature's style it is written from. */
120
+ export interface LookRole<F, S> {
121
+ look: FeatureLook;
122
+ write(feature: F, index: number, style: S, state: FeatureState, out: FeatureLookStyle): void;
123
+ }
124
+ /**
125
+ * A layer of the view: features, their style, and everything that changes how they are drawn
126
+ * without rebuilding them.
127
+ *
128
+ * - **Style** (`setStyle`, `restyle`): asked of the application per feature, written into the
129
+ * feature look's textures at the next frame - one upload for any number of features.
130
+ * - **Filter** (`setFilter`): a predicate, on the CPU; what fails is hidden or faded.
131
+ * - **Range** (`setRange`, `setRangeBounds`): every feature's value written once, the range held
132
+ * on the GPU; dragging it is two uniforms a frame.
133
+ * - **Categories** (`setCategories`, `setCategoryMode`): a category per feature, its mode on the
134
+ * GPU; switching one is one texel.
135
+ * - **Colour by** (`colorBy`): style, category, or a value through a ramp, on the GPU.
136
+ * - **Selection** (`select`), **emphasis** (`emphasize`) and **hover** (`setHovered`, one uniform).
137
+ * - **Density** (`setDensity`): the same geometry adding its weight into the heatmap instead.
138
+ */
139
+ export declare abstract class GeometryLayer<F extends GeometryFeature = GeometryFeature, S extends BaseStyle = BaseStyle> extends TypedEventEmitter<GeometryLayerEvents> {
140
+ readonly id: string;
141
+ title?: string;
142
+ protected features: F[];
143
+ protected readonly indexOf: Map<GeometryId, number>;
144
+ protected host: LayerHost | null;
145
+ protected primitives: GeometryPrimitive[];
146
+ protected roles: LookRole<F, S>[];
147
+ protected pick: PickOptions | null;
148
+ private style;
149
+ private visible;
150
+ private pickable;
151
+ private opacity;
152
+ private density;
153
+ private filter;
154
+ private filterOutside;
155
+ private range;
156
+ private categories;
157
+ private categoryIndex;
158
+ private categoryModes;
159
+ private coloring;
160
+ private readonly selected;
161
+ private readonly emphasized;
162
+ private hovered;
163
+ private needsBuild;
164
+ /** The features changed since the last build: their geometry again, the shaders kept. */
165
+ private needsRefresh;
166
+ private builtOrigin;
167
+ private readonly overrides;
168
+ private allDirty;
169
+ private readonly dirty;
170
+ private removePickSource;
171
+ private builtFor;
172
+ private builds;
173
+ private boundsCache;
174
+ constructor(options?: GeometryLayerOptions<F, S>);
175
+ /**
176
+ * All the features at once. Drawn already, the layer keeps its compiled shaders and builds
177
+ * only the new geometry - as for `addFeatures`, `updateFeatures` and `removeFeatures`.
178
+ */
179
+ setFeatures(features: F[]): void;
180
+ /** Adds features after the others. */
181
+ addFeatures(features: readonly F[]): void;
182
+ /** Replaces features by their ids: a moved vertex, a new shape. Ids not in the layer are added. */
183
+ updateFeatures(features: readonly F[]): void;
184
+ /** Removes features by their ids, and from the selection. */
185
+ removeFeatures(ids: Iterable<GeometryId>): void;
186
+ private featuresChanged;
187
+ /** The geometry again at the next frame: drawn already, into the same shaders; else a build. */
188
+ protected invalidateGeometry(): void;
189
+ getFeatures(): readonly F[];
190
+ getFeature(id: GeometryId): F | undefined;
191
+ featureAt(index: number): F | undefined;
192
+ get size(): number;
193
+ /** Where the layer's features are, in world units. */
194
+ bounds(): Bounds3;
195
+ setStyle(style: S | ((feature: F, index: number) => S)): void;
196
+ /** Asks the style again for these features, or for all. */
197
+ restyle(ids?: Iterable<GeometryId>): void;
198
+ styleOf(feature: F, index: number): S;
199
+ setVisible(visible: boolean): void;
200
+ isVisible(): boolean;
201
+ setPickable(pickable: boolean): void;
202
+ isPickable(): boolean;
203
+ setOpacity(opacity: number): void;
204
+ /** Draws the layer as its weights in the heatmap, rather than itself. */
205
+ setDensity(density: boolean): void;
206
+ get drawsDensity(): boolean;
207
+ /** A predicate on the CPU: what fails it is hidden, or faded. Null shows all. */
208
+ setFilter(filter: ((feature: F) => boolean) | null, outside?: 'hide' | 'fade'): void;
209
+ /** A range on the GPU; null for none. Every feature's value is written once, at the next frame. */
210
+ setRange(range: RangeSpec<F> | null): void;
211
+ /** Moves the range: two uniforms, nothing per feature. */
212
+ setRangeBounds(low: number, high: number): void;
213
+ getRange(): RangeSpec<F> | null;
214
+ /** Categories on the GPU; null for none. */
215
+ setCategories(categories: CategorySpec<F> | null): void;
216
+ /** One category's mode: one texel. */
217
+ setCategoryMode(key: string | number, mode: CategoryModeName): void;
218
+ getCategoryMode(key: string | number): CategoryModeName;
219
+ /** The categories seen so far, in their order. */
220
+ categoryKeys(): string[];
221
+ /** The colour category `key` is drawn in when colouring by category. */
222
+ categoryColor(key: string | number): Rgba;
223
+ /** What the features are coloured by, on the GPU. */
224
+ colorBy(spec: ColorBySpec<F> | null): void;
225
+ select(ids: Iterable<GeometryId>, mode?: SelectMode): void;
226
+ clearSelection(): void;
227
+ selection(): GeometryId[];
228
+ isSelected(id: GeometryId): boolean;
229
+ /** Lights these features as the selection is, without selecting them: what is pointed at elsewhere. */
230
+ emphasize(ids: Iterable<GeometryId> | null): void;
231
+ /**
232
+ * Forces a state on features whatever their style and filters say - faded, hidden or lit as
233
+ * selected - or, with null, lets them be again. What an editor sets off while it works on them.
234
+ */
235
+ setOverride(ids: Iterable<GeometryId>, state: FeatureStateOverride | null): void;
236
+ /** Lets every forced state go. */
237
+ clearOverrides(): void;
238
+ /** The feature pointed at, lit by one uniform; null for none. */
239
+ setHovered(id: GeometryId | null): void;
240
+ getHovered(): GeometryId | null;
241
+ /** Whether anything in the layer is lit: selected, emphasized, pointed at or a lit category. */
242
+ get lit(): boolean;
243
+ /** What the pick pass's index means in this layer. */
244
+ hitAt(index: number): LayerHit<F> | null;
245
+ attach(host: LayerHost): void;
246
+ detach(): void;
247
+ dispose(): void;
248
+ /** Whether the next frame would build: geometry to make, shaders to compile. */
249
+ get wantsBuild(): boolean;
250
+ /**
251
+ * Builds what has to be built, writes what changed: once per frame, from the view. `mayBuild`
252
+ * false leaves a fresh build for a later frame - the view builds one layer a frame, so a page
253
+ * of them shows up layer by layer rather than after one long wait for every shader.
254
+ */
255
+ beforeRender(mayBuild?: boolean): void;
256
+ /** What the built geometry depends on besides the features: a rebuild when it changes. */
257
+ protected buildKey(host: LayerHost): string;
258
+ /** The primitives for the features, with their looks registered (`addRole`). */
259
+ protected abstract createPrimitives(host: LayerHost, origin: [number, number, number]): GeometryPrimitive[];
260
+ /** A new look the primitives share, written from each feature's style by `write`. */
261
+ protected addRole(write: LookRole<F, S>['write'], options?: {
262
+ failLooks?: boolean;
263
+ }): FeatureLook;
264
+ protected invalidateBuild(): void;
265
+ private overlay;
266
+ private overlayOrder;
267
+ /**
268
+ * Drawn over everything else, whatever is in front of it, after the overlays added before:
269
+ * what `GeometryView.addOverlay` sets for an editor's handles, a sketch, a measurement.
270
+ */
271
+ setOverlay(overlay: boolean, order?: number): void;
272
+ /** Whether the features as they are now can be drawn by the primitives built before them. */
273
+ protected canRefresh(): boolean;
274
+ /**
275
+ * New geometry for the primitives drawn now, from the features as they are: each built again
276
+ * and adopted by its predecessor (`GeometryPrimitive.adopt`), whose compiled shaders and
277
+ * looks stay. A build afresh where that cannot be: more features than the looks hold, a
278
+ * primitive that cannot adopt, a different set of them.
279
+ */
280
+ private refresh;
281
+ protected invalidateAll(): void;
282
+ protected repaint(): void;
283
+ private build;
284
+ /** How many instances the layer draws: segments, icons, triangles. */
285
+ instanceCount(): number;
286
+ /** Takes what is drawn out of the engine and keeps it under the key it was built for. */
287
+ private stash;
288
+ /** Disposes what was put away for other keys. */
289
+ private dropStashed;
290
+ /** Disposes what is drawn and everything kept. */
291
+ private dropPrimitives;
292
+ /** The feature's state, from its style, the filter and the selection. */
293
+ protected stateOf(feature: F, style: S): FeatureState;
294
+ /**
295
+ * A style's colour as drawn: its alpha times its opacity and, faded by the CPU's filter, faded
296
+ * as the GPU's filters fade - so the two read the same.
297
+ */
298
+ protected colorOf(color: ColorLike | undefined, opacity: number | undefined, state: FeatureState, fallback: ColorLike): Rgba;
299
+ /** Whether any feature was drawn see-through at the last write: the volumes' blended pass draws only then. */
300
+ private translucent;
301
+ private updateLooks;
302
+ private readonly scratch;
303
+ private writeFeature;
304
+ private categoryOf;
305
+ private paletteColor;
306
+ /** The range, the category table and the colouring, onto every look's uniforms and tables. */
307
+ private applyGpuState;
308
+ /** Which meshes show this frame: the layer's, its density's, its glow's or its outline's. */
309
+ private updateMeshes;
310
+ }
311
+ /** A position relative to the origin. */
312
+ export declare function relative(p: readonly number[], origin: readonly number[]): [number, number, number];
@@ -0,0 +1 @@
1
+ import{Mesh as e}from"three/webgpu";import{CATEGORY_COLORS as t,desaturate as i,parseColor as s}from"../common/Colors.js";import{boundsOf as r}from"../data/Geometry.js";import{TypedEventEmitter as h}from"../event/TypedEventEmitter.js";import{CategoryMode as o,FeatureLook as a,FeatureState as n,MAX_CATEGORIES as l,NO_VALUE as d}from"../three/FeatureLook.js";const c={hidden:o.Hidden,faded:o.Faded,shown:o.Shown,lit:o.Lit};let u=0;export class GeometryLayer extends h{constructor(e={}){super(),this.features=[],this.indexOf=new Map,this.host=null,this.primitives=[],this.roles=[],this.pick=null,this.density=!1,this.filter=null,this.filterOutside="hide",this.range=null,this.categories=null,this.categoryIndex=new Map,this.categoryModes=new Map,this.coloring={by:"style"},this.selected=new Set,this.emphasized=new Set,this.hovered=null,this.needsBuild=!0,this.needsRefresh=!1,this.builtOrigin=null,this.overrides=new Map,this.allDirty=!0,this.dirty=new Set,this.removePickSource=null,this.builtFor="",this.builds=new Map,this.boundsCache=null,this.overlay=!1,this.overlayOrder=0,this.translucent=!1,this.scratch={},this.id=e.id??"layer-"+ ++u,this.title=e.title,this.style=e.style,this.visible=e.visible??!0,this.pickable=e.pickable??!0,this.opacity=e.opacity??1,e.features&&this.setFeatures(e.features)}setFeatures(e){this.features=e,this.categoryIndex.clear(),this.featuresChanged()}addFeatures(e){0!==e.length&&(this.features=[...this.features,...e],this.featuresChanged())}updateFeatures(e){if(0===e.length)return;const t=[...this.features];for(const i of e){const e=this.indexOf.get(i.id);void 0===e?t.push(i):t[e]=i}this.features=t,this.featuresChanged()}removeFeatures(e){const t=new Set(e);0!==t.size&&(this.features=this.features.filter(e=>!t.has(e.id)),t.forEach(e=>{this.selected.delete(e),this.emphasized.delete(e),this.overrides.delete(e)}),null!==this.hovered&&t.has(this.hovered)&&this.setHovered(null),this.featuresChanged())}featuresChanged(){this.indexOf.clear(),this.features.forEach((e,t)=>this.indexOf.set(e.id,t)),this.boundsCache=null,this.invalidateGeometry(),this.allDirty=!0,this.emit("change",{what:"features"})}invalidateGeometry(){this.primitives.length>0&&!this.needsBuild?this.needsRefresh=!0:this.needsBuild=!0,this.repaint()}getFeatures(){return this.features}getFeature(e){const t=this.indexOf.get(e);return void 0===t?void 0:this.features[t]}featureAt(e){return this.features[e]}get size(){return this.features.length}bounds(){return this.boundsCache??(this.boundsCache=r(this.features)),this.boundsCache}setStyle(e){this.style=e,this.invalidateAll(),this.emit("change",{what:"style"})}restyle(e){if(e){for(const t of e){const e=this.indexOf.get(t);void 0!==e&&this.dirty.add(e)}this.repaint()}else this.invalidateAll()}styleOf(e,t){const i=this.style;return"function"==typeof i?i(e,t)??{}:i??{}}setVisible(e){e!==this.visible&&(this.visible=e,this.repaint(),this.emit("change",{what:"visibility"}))}isVisible(){return this.visible}setPickable(e){this.pickable=e,this.repaint()}isPickable(){return this.pickable&&this.visible}setOpacity(e){this.opacity=e,this.repaint()}setDensity(e){e!==this.density&&(this.density=e,this.repaint())}get drawsDensity(){return this.density}setFilter(e,t="hide"){this.filter=e,this.filterOutside=t,this.invalidateAll(),this.emit("change",{what:"filter"})}setRange(e){const t=!e||!this.range||e.value!==this.range.value;this.range=e,t&&this.invalidateAll(),this.applyGpuState(),this.emit("change",{what:"filter"})}setRangeBounds(e,t){this.range&&(this.range={...this.range,low:e,high:t},this.applyGpuState(),this.emit("change",{what:"filter"}))}getRange(){return this.range}setCategories(e){this.categories=e,this.categoryIndex.clear(),this.categoryModes.clear(),e?.keys?.forEach((e,t)=>this.categoryIndex.set(String(e),t)),e?.modes&&Object.entries(e.modes).forEach(([e,t])=>this.categoryModes.set(this.categoryOf(e),c[t])),this.invalidateAll(),this.applyGpuState(),this.emit("change",{what:"filter"})}setCategoryMode(e,t){const i=this.categoryOf(String(e));this.categoryModes.set(i,c[t]),this.roles.forEach(e=>e.look.setCategoryMode(i,c[t])),this.repaint(),this.emit("change",{what:"filter"})}getCategoryMode(e){const t=this.categoryIndex.get(String(e)),i=void 0===t?o.Shown:this.categoryModes.get(t)??o.Shown;return Object.keys(c).find(e=>c[e]===i)??"shown"}categoryKeys(){return[...this.categoryIndex.keys()]}categoryColor(e){const t=this.categoryOf(String(e));return s(this.paletteColor(String(e),t))}colorBy(e){const t=this.coloring;this.coloring=e??{by:"style"};"value"in this.coloring&&(!("value"in t)||t.value!==this.coloring.value)&&this.invalidateAll(),this.applyGpuState(),this.emit("change",{what:"style"})}select(e,t="replace"){const i=new Set,s=[...e];"replace"===t&&(this.selected.forEach(e=>i.add(e)),this.selected.clear()),s.forEach(e=>{if(!this.indexOf.has(e))return;const s=this.selected.has(e);"remove"!==t&&("toggle"!==t||!s)?this.selected.add(e):this.selected.delete(e),i.add(e)}),0!==i.size&&(this.restyle(i),this.emit("change",{what:"selection"}))}clearSelection(){0!==this.selected.size&&this.select([],"replace")}selection(){return[...this.selected]}isSelected(e){return this.selected.has(e)}emphasize(e){const t=new Set(e??[]),i=new Set;this.emphasized.forEach(e=>{t.has(e)||i.add(e)}),t.forEach(e=>{this.emphasized.has(e)||i.add(e)}),this.emphasized.clear(),t.forEach(e=>this.emphasized.add(e)),i.size>0&&this.restyle(i)}setOverride(e,t){const i=[],s="hidden"===t?n.Hidden:"faded"===t?n.Faded:n.Selected;for(const r of e)(null===t?this.overrides.delete(r):this.overrides.get(r)!==s)&&i.push(r),null!==t&&this.overrides.set(r,s);i.length>0&&this.restyle(i)}clearOverrides(){const e=[...this.overrides.keys()];this.overrides.clear(),e.length>0&&this.restyle(e)}setHovered(e){if(e===this.hovered)return;this.hovered=e;const t=null===e?-1:this.indexOf.get(e)??-1;this.roles.forEach(e=>{e.look.hoverIndex.value=t}),this.repaint()}getHovered(){return this.hovered}get lit(){return this.selected.size>0||this.emphasized.size>0||null!==this.hovered||[...this.categoryModes.values()].some(e=>e===o.Lit)}hitAt(e){const t=this.features[e];return t&&this.isPickable()?{layer:this,feature:t,id:t.id,index:e}:null}attach(e){this.host=e;const t=e.engine.addPickSource(e=>this.hitAt(e));this.pick={pass:e.engine.pickPass,source:t.id},this.removePickSource=t.remove,this.invalidateBuild()}detach(){this.dropPrimitives(),this.removePickSource?.(),this.removePickSource=null,this.pick=null,this.host=null}dispose(){this.detach()}get wantsBuild(){const e=this.host;if(!e)return!1;const t=this.buildKey(e);return(this.needsBuild||t!==this.builtFor)&&!(this.builds.has(t)&&!this.needsBuild)}beforeRender(e=!0){const t=this.host;if(!t)return;const i=this.buildKey(t);if(this.needsBuild||i!==this.builtFor){if(!e&&this.wantsBuild)return;this.build(t,i)}else this.needsRefresh&&this.refresh(t,i);this.updateLooks(),this.updateMeshes(t)}buildKey(e){return e.mode}addRole(e,t){const i=new a(Math.max(1,this.features.length),t);return this.roles.push({look:i,write:e}),i}invalidateBuild(){this.needsBuild=!0,this.needsRefresh=!1,this.repaint()}setOverlay(e,t=0){e===this.overlay&&t===this.overlayOrder||(this.overlay=e,this.overlayOrder=t,this.invalidateBuild())}canRefresh(){return!0}refresh(e,t){this.needsRefresh=!1,this.dropStashed();const i=this.builtOrigin,s=this.roles.every(e=>e.look.capacity>=Math.max(1,this.features.length));if(!i||0===this.primitives.length||!s||!this.canRefresh())return this.needsBuild=!0,void this.build(e,t);const r=performance.now(),h=this.roles;this.roles=[];let o=[],a=[];try{o=this.createPrimitives(e,i)}finally{a=this.roles,this.roles=h}let n=o.length===this.primitives.length;for(let e=0;n&&e<o.length;e++)n=this.primitives[e].adopt?.(o[e])??!1;if(o.forEach(e=>e.dispose()),a.forEach(e=>e.look.dispose()),!n)return this.needsBuild=!0,void this.build(e,t);this.allDirty=!0,this.applyGpuState();const l=null===this.hovered?-1:this.indexOf.get(this.hovered)??-1;this.roles.forEach(e=>{e.look.hoverIndex.value=l}),this.emit("build",{ms:performance.now()-r,features:this.features.length,instances:this.instanceCount(),refresh:!0})}invalidateAll(){this.allDirty=!0,this.repaint()}repaint(){this.host?.requestRepaint()}build(e,t){const i=performance.now();this.stash(),this.needsBuild&&this.dropPrimitives(),this.needsBuild=!1,this.needsRefresh=!1,this.builtFor=t;const s=this.builds.get(t);if(s){this.builds.delete(t),this.primitives=s.primitives,this.roles=s.roles,this.primitives.forEach(t=>e.engine.attach(t)),this.allDirty=!0,this.applyGpuState();const i=null===this.hovered?-1:this.indexOf.get(this.hovered)??-1;return void this.roles.forEach(e=>{e.look.hoverIndex.value=i})}if(0===this.features.length)return;const r=e.engine.originFor(function(e){for(const t of e){const e=t.geometry;if(e)switch(e.type){case"Point":return e.coordinates;case"MultiPoint":case"LineString":if(e.coordinates.length)return e.coordinates[0];break;case"MultiLineString":case"Polygon":if(e.coordinates[0]?.length)return e.coordinates[0][0];break;case"MultiPolygon":if(e.coordinates[0]?.[0]?.length)return e.coordinates[0][0][0]}}return null}(this.features)??[0,0,0]);this.builtOrigin=r,this.primitives=this.createPrimitives(e,r),this.overlay&&this.primitives.forEach(e=>function(e,t){const i=e.passes();for(const e of[...i.scene??[],...i.underlay??[]]){if(!e)continue;const i=e.material;i.depthTest=!1,i.depthWrite=!1,e.renderOrder=1e5+100*t+e.renderOrder}}(e,this.overlayOrder)),this.primitives.forEach(t=>e.engine.attach(t)),this.allDirty=!0,this.applyGpuState();const h=null===this.hovered?-1:this.indexOf.get(this.hovered)??-1;this.roles.forEach(e=>{e.look.hoverIndex.value=h}),this.emit("build",{ms:performance.now()-i,features:this.features.length,instances:this.instanceCount()})}instanceCount(){return this.primitives.reduce((e,t)=>e+(t.segments??t.count??t.triangles??0),0)}stash(){if(0===this.primitives.length)return;const e=this.host?.engine;this.primitives.forEach(t=>e?.detach(t)),this.builds.set(this.builtFor,{primitives:this.primitives,roles:this.roles}),this.primitives=[],this.roles=[]}dropStashed(){this.builds.forEach(({primitives:e,roles:t})=>{e.forEach(e=>e.dispose()),t.forEach(e=>e.look.dispose())}),this.builds.clear()}dropPrimitives(){const e=this.host?.engine;[{primitives:this.primitives,roles:this.roles},...this.builds.values()].forEach(({primitives:t,roles:i})=>{t.forEach(t=>{e?.detach(t),t.dispose()}),i.forEach(e=>e.look.dispose())}),this.builds.clear(),this.primitives=[],this.roles=[]}stateOf(e,t){if("hidden"===t.state)return n.Hidden;let i="faded"===t.state?n.Faded:n.Default;if(this.filter&&!this.filter(e)){if("hide"===this.filterOutside)return n.Hidden;i=n.Faded}const s=this.overrides.get(e.id);return void 0!==s?s:this.selected.has(e.id)||this.emphasized.has(e.id)?n.Selected:i}colorOf(e,t,r,h){const o=s(e??h),a=o[3]*(t??1);if(r===n.Faded){const e=i(o,.7);return[e[0],e[1],e[2],.25*a]}return[o[0],o[1],o[2],a]}updateLooks(){if(0!==this.roles.length){if(this.allDirty){this.translucent=!1;for(let e=0;e<this.features.length;e++)this.writeFeature(e)}else this.dirty.forEach(e=>this.writeFeature(e));this.allDirty=!1,this.dirty.clear(),this.roles.forEach(e=>e.look.commit())}}writeFeature(e){const t=this.features[e];if(!t)return;const i=this.styleOf(t,e),s=this.stateOf(t,i),r=this.categories?this.categoryOf(this.categories.of(t)):-1,h=this.range?this.range.value(t):d,o="value"in this.coloring?this.coloring.value(t):d;for(const a of this.roles){const n=this.scratch;for(const e in n)delete n[e];a.write(t,e,i,s,n),n.state=n.state??s,n.category=r,n.colorValue=o,a.look.set(e,n),a.look.setValue(e,h);const l=n.color;l&&l[3]>.004&&l[3]<.99&&(this.translucent=!0)}}categoryOf(e){if(null==e)return-1;const t=String(e);let i=this.categoryIndex.get(t);if(void 0===i){if(i=this.categoryIndex.size,i>=l)return-1;this.categoryIndex.set(t,i),this.roles.forEach(e=>{e.look.setCategoryColor(i,this.paletteColor(t,i)),e.look.setCategoryMode(i,this.categoryModes.get(i)??o.Shown)})}return i}paletteColor(e,i){const s=this.categories?.colors;return Array.isArray(s)?s[i%s.length]:s&&s[e]?s[e]:t[i%t.length]}applyGpuState(){for(const{look:e}of this.roles){const t=this.range;e.rangeActive.value=t?1:0,e.rangeLow.value=t?.low??0,e.rangeHigh.value=t?.high??0,e.rangeOutside.value="fade"===t?.outside?2:1,e.categoryActive.value=this.categories?1:0,this.categoryIndex.forEach((t,i)=>{e.setCategoryColor(t,this.paletteColor(i,t)),e.setCategoryMode(t,this.categoryModes.get(t)??o.Shown)});const i=this.coloring;e.colorMode.value="value"in i?2:"category"===i.by?1:0,"value"in i&&e.setRamp(i.ramp,i.domain[0],i.domain[1])}this.repaint()}updateMeshes(t){const i=t.highlight,s=this.visible,r=this.density,h=this.lit,o="outline"===i.look,a=!o&&"bloom"===i.glow,[n,l,d]=i.outlineColor;for(const{look:e}of this.roles)e.opacity.value=this.opacity,e.othersShade.value=i.hoverFades&&t.anyHovered?i.othersShade:1,e.othersToward.value=i.othersToward,e.hoverLights.value=i.hoverLights?1:0;for(const c of this.primitives){const u=c,f=c.passes(),g=(e,t)=>f[e]?.forEach(e=>{e&&(e.visible=t)});g("scene",s&&!r),g("halo",s&&!r),g("pick",s&&this.pickable),g("density",s&&r),g("bloom",s&&!r&&h&&a),u.casingMesh instanceof e&&(u.casingMesh.visible=s&&!r&&h&&o),u.ghostMesh instanceof e&&(u.ghostMesh.visible=s&&!r&&this.translucent),u.glowMode&&(u.glowMode.value=o?2:"shader"===i.glow?1:0),u.outlineRgb&&u.outlineRgb.value.set(n,l,d),u.outlineWidth&&(u.outlineWidth.value=i.outlineWidth),u.outlineMode&&(u.outlineMode.value=o?1:0),u.rimRgb&&u.rimRgb.value.set(n,l,d),u.windowsLit&&void 0!==t.windowsLit&&(u.windowsLit.value=t.windowsLit),u.uniforms?.outlineRgb&&(u.uniforms.outlineRgb.value.set(n,l,d),u.uniforms.outlineWidth.value=i.outlineWidth)}}}export function relative(e,t){return[e[0]-t[0],e[1]-t[1],(e[2]??0)-t[2]]}
@@ -0,0 +1,48 @@
1
+ import { GeometryFeature } from '../data/Geometry';
2
+ import { GeometryPrimitive } from '../engine/GeometryFrame';
3
+ import { GpuLines } from '../three/primitives/GpuLines';
4
+ import { BaseStyle, GeometryLayer, GeometryLayerOptions, LayerHost } from './GeometryLayer';
5
+ export interface LineStyle extends BaseStyle {
6
+ /** In view pixels, or world units with `widthUnit: 'm'`. 2 px by default. */
7
+ width?: number;
8
+ widthUnit?: 'px' | 'm';
9
+ /** The line's real width in world units: drawn at least that wide when close. */
10
+ realWidth?: number;
11
+ dashed?: boolean;
12
+ /** Pulses of light running along it, start to end. */
13
+ flow?: boolean;
14
+ /** The flow arrow at its middle, where the layer draws arrows. */
15
+ arrow?: boolean;
16
+ }
17
+ export type LineMode = 'auto' | 'screen' | 'ground' | 'space';
18
+ export interface LineLayerOptions<F> extends GeometryLayerOptions<F, LineStyle> {
19
+ /**
20
+ * How the lines lie: across the screen (a 2D map), flat on the ground in perspective (roads,
21
+ * routes on a 3D map) or in space at their own depth (trajectories, flights, cables). `auto`:
22
+ * the screen in 2D; in 3D, space where a line has heights, else the ground.
23
+ */
24
+ mode?: LineMode;
25
+ /** Flow arrows at the lines' middles, where long enough. */
26
+ arrows?: boolean;
27
+ /** How far each line stops short of its start and end, in world units: what stands there. */
28
+ ends?: (feature: F) => [number, number] | null | undefined;
29
+ }
30
+ /**
31
+ * Lines - networks, routes, trajectories, outlines - as `GpuLines`: one instanced draw, every
32
+ * segment a quad widened and anti-aliased in its shaders, round joints, flat ends, flow arrows,
33
+ * dashes and flowing light, glow or outline when lit.
34
+ */
35
+ export declare class LineLayer<F extends GeometryFeature = GeometryFeature> extends GeometryLayer<F, LineStyle> {
36
+ private readonly options;
37
+ constructor(options?: LineLayerOptions<F>);
38
+ /** How the lines lie now. */
39
+ resolvedMode(host: LayerHost): 'screen' | 'ground' | 'space';
40
+ protected buildKey(host: LayerHost): string;
41
+ protected createPrimitives(host: LayerHost, origin: [number, number, number]): GeometryPrimitive[];
42
+ beforeRender(): void;
43
+ private flowing;
44
+ private flows;
45
+ protected invalidateAll(): void;
46
+ /** The primitive drawing the lines, for what the layer does not offer. */
47
+ get primitive(): GpuLines | null;
48
+ }
@@ -0,0 +1 @@
1
+ import{linesOf as e}from"../data/Geometry.js";import{FeatureState as t,LookFlag as i}from"../three/FeatureLook.js";import{GpuLines as s}from"../three/primitives/GpuLines.js";import{GeometryLayer as o}from"./GeometryLayer.js";export class LineLayer extends o{constructor(e={}){super(e),this.options=e,this.flowing=null}resolvedMode(e){const t=this.options.mode??"auto";if("2d"===e.mode)return"screen";if("auto"!==t&&"screen"!==t)return t;if("screen"===t)return"space";const i=this.bounds();return Math.abs(i.max[2]-i.min[2])>1e-6||Math.abs(i.max[2])>1e-6?"space":"ground"}buildKey(e){return`${e.mode}|${this.resolvedMode(e)}`}createPrimitives(o,r){const n=this.resolvedMode(o),a=this.features.map(t=>e(t.geometry).filter(e=>e.length>1).map(e=>e.map(e=>({x:e[0]-r[0],y:e[1]-r[1],z:(e[2]??0)-r[2]}))));let l;this.options.ends&&(l=new Float32Array(2*this.features.length),this.features.forEach((e,t)=>{const i=this.options.ends(e);i&&l.set(i,2*t)}));const h=this.addRole((e,s,o,r,n)=>{const a=this.colorOf(o.color,o.opacity,r,"#4cc9f0");n.color=a,n.width=o.width??2,n.meters="m"===o.widthUnit,n.realWidth=o.realWidth??0,n.flags=(o.dashed?i.Dashed:0)|(o.flow?i.Flow:0)|(!1===o.arrow?i.NoArrow:0),n.weight=o.weight??1,n.fadedWeight=.3*(o.weight??1),n.state=r,r===t.Selected&&"faded"===o.state&&(n.color=this.colorOf(o.color,o.opacity,t.Default,"#4cc9f0"))});return[new s(a,{look:h,pick:this.pick??void 0,arrows:!!this.options.arrows,ground:"ground"===n?{up:o.up}:void 0,space:"space"===n,ends:l})]}beforeRender(){super.beforeRender();const e=this.host;e&&this.primitive&&e.setAnimating(`flow:${this.id}`,this.isVisible()&&this.flows())}flows(){return null===this.flowing&&(this.flowing=this.features.some((e,t)=>this.styleOf(e,t).flow)),this.flowing}invalidateAll(){this.flowing=null,super.invalidateAll()}get primitive(){return this.primitives.find(e=>e instanceof s)??null}}
@@ -0,0 +1,42 @@
1
+ import { GeometryFeature } from '../data/Geometry';
2
+ import { GeometryPrimitive } from '../engine/GeometryFrame';
3
+ import { GpuIcons, IconShapeName } from '../three/primitives/GpuIcons';
4
+ import { IconSource } from '../three/primitives/IconAtlas';
5
+ import { BaseStyle, GeometryLayer, GeometryLayerOptions, LayerHost } from './GeometryLayer';
6
+ export interface PointStyle extends BaseStyle {
7
+ /** Across, in view pixels or world units (`sizeUnit`); 12 px by default. */
8
+ size?: number;
9
+ sizeUnit?: 'px' | 'm';
10
+ /** A shape drawn in the shader; a circle by default. */
11
+ shape?: IconShapeName;
12
+ /** An icon from an image (a url, an SVG's data url) or a drawing: tinted by the colour. */
13
+ icon?: IconSource;
14
+ }
15
+ export interface PointLayerOptions<F> extends GeometryLayerOptions<F, PointStyle> {
16
+ /** Facing the screen (the default), or lying on the ground at their real size. */
17
+ orientation?: 'screen' | 'ground';
18
+ /** In 3D, hidden behind what is in front of them. On by default. */
19
+ depthTest?: boolean;
20
+ /** Where the point is on the icon, in half sizes from its middle: [0, -1] its foot. */
21
+ anchor?: [number, number];
22
+ /** A shape's dark border, in view pixels. */
23
+ border?: number;
24
+ /** Never smaller than this many view pixels across. */
25
+ minPixels?: number;
26
+ }
27
+ /**
28
+ * Points as icons and markers (`GpuIcons`): shapes drawn in the shader or images from an atlas,
29
+ * in pixels or world units, facing the screen or lying on the ground, at any depth.
30
+ */
31
+ export declare class PointLayer<F extends GeometryFeature = GeometryFeature> extends GeometryLayer<F, PointStyle> {
32
+ private readonly options;
33
+ private cells;
34
+ constructor(options?: PointLayerOptions<F>);
35
+ protected createPrimitives(host: LayerHost, origin: [number, number, number]): GeometryPrimitive[];
36
+ private atlas;
37
+ /** Features changed in place keep the built icons while they use the same pictures. */
38
+ protected canRefresh(): boolean;
39
+ /** A style that changes the shape or icon needs the geometry again: its shaders stay. */
40
+ restyle(ids?: Iterable<string | number>): void;
41
+ get primitive(): GpuIcons | null;
42
+ }
@@ -0,0 +1 @@
1
+ import{pointsOf as t}from"../data/Geometry.js";import{GpuIcons as e,iconShapeOf as s}from"../three/primitives/GpuIcons.js";import{iconAtlas as i}from"../three/primitives/IconAtlas.js";import{GeometryLayer as o}from"./GeometryLayer.js";export class PointLayer extends o{constructor(t={}){super(t),this.options=t,this.cells=[],this.atlas=null}createPrimitives(o,n){const l=[],h=[];this.cells=[],this.features.forEach((e,i)=>{const o=this.styleOf(e,i);let r;o.icon?(r=h.indexOf(o.icon),r<0&&(r=h.push(o.icon)-1)):r=s(o.shape??"circle"),this.cells[i]=r;for(const s of t(e.geometry))l.push({x:s[0]-n[0],y:s[1]-n[1],z:(s[2]??0)-n[2],cell:r,index:i})});const c=this.addRole((t,e,s,i,o)=>{o.color=this.colorOf(s.color,s.opacity,i,"#ffd166"),o.width=s.size??12,o.meters="m"===s.sizeUnit,o.weight=s.weight??1,o.fadedWeight=.3*(s.weight??1)});r(this.atlas?.sources??[],h)||(this.atlas=h.length>0?{sources:h,texture:i(h,()=>o.requestRepaint())}:null);const a=this.atlas?.texture??null;return[new e(l,a,12,{look:c,pick:this.pick??void 0,sizeUnit:"pixels",orientation:this.options.orientation,up:o.up,depth:"3d"===o.mode&&!1!==this.options.depthTest,anchor:this.options.anchor,border:this.options.border,minPixels:this.options.minPixels})]}canRefresh(){const t=[];return this.features.forEach((e,s)=>{const i=this.styleOf(e,s).icon;i&&!t.includes(i)&&t.push(i)}),r(this.atlas?.sources??[],t)}restyle(t){if(this.cells.length>0){const e=t?[...t].map(t=>this.indexOf.get(t)).filter(t=>void 0!==t):this.features.map((t,e)=>e);for(const t of e){const e=this.styleOf(this.features[t],t),i=e.icon?null:s(e.shape??"circle");if(null!==i&&i!==this.cells[t]){this.invalidateGeometry();break}}}super.restyle(t)}get primitive(){return this.primitives.find(t=>t instanceof e)??null}}function r(t,e){return t.length===e.length&&t.every((t,s)=>t===e[s])}
@@ -0,0 +1,25 @@
1
+ import { GeometryFeature } from '../data/Geometry';
2
+ import { GeometryPrimitive } from '../engine/GeometryFrame';
3
+ import { BaseStyle, GeometryLayer, GeometryLayerOptions, LayerHost } from './GeometryLayer';
4
+ export interface SphereStyle extends BaseStyle {
5
+ material?: string | number;
6
+ /** Never smaller on screen than this many view pixels across. 4 by default. */
7
+ width?: number;
8
+ }
9
+ export interface SphereLayerOptions<F> extends GeometryLayerOptions<F, SphereStyle> {
10
+ /** Each point's radius, in world units; 0.25 by default. */
11
+ radius?: (feature: F) => number;
12
+ /** Drawn only within this distance of the camera; 0 for always. */
13
+ reach?: (feature: F) => number;
14
+ /** Ghosted where the scene's surface is in front of them, with a halo. On by default. */
15
+ ghost?: boolean;
16
+ }
17
+ /**
18
+ * Points in 3D as lit spheres (`GpuSpheres`) - connections, sensors, nodes - at their real size
19
+ * and depth; on a 2D map, discs of the same look.
20
+ */
21
+ export declare class SphereLayer<F extends GeometryFeature = GeometryFeature> extends GeometryLayer<F, SphereStyle> {
22
+ private readonly options;
23
+ constructor(options?: SphereLayerOptions<F>);
24
+ protected createPrimitives(host: LayerHost, origin: [number, number, number]): GeometryPrimitive[];
25
+ }
@@ -0,0 +1 @@
1
+ import{pointsOf as e}from"../data/Geometry.js";import{GpuIcons as t,IconShape as i}from"../three/primitives/GpuIcons.js";import{GpuSpheres as o}from"../three/primitives/GpuSpheres.js";import{materialCode as r}from"../three/Shading.js";import{GeometryLayer as s}from"./GeometryLayer.js";export class SphereLayer extends s{constructor(e={}){super(e),this.options=e}createPrimitives(s,h){const n="2d"===s.mode,p=this.addRole((e,t,i,o,s)=>{s.color=this.colorOf(i.color,i.opacity,o,"#f72585"),s.material=r(i.material),s.width=n?2*(this.options.radius?.(e)??.25):i.width??4,s.meters=n,s.weight=i.weight??1,s.fadedWeight=.3*(i.weight??1)});if(n){const o=this.features.flatMap((t,o)=>e(t.geometry).map(e=>({x:e[0]-h[0],y:e[1]-h[1],z:0,cell:i.Circle,index:o})));return[new t(o,null,1,{look:p,pick:this.pick??void 0,minPixels:4,border:.6})]}const c=[];this.features.forEach((t,i)=>{const o=this.options.radius?.(t)??.25,r=this.options.reach?.(t)??0;for(const s of e(t.geometry))c.push({x:s[0]-h[0],y:s[1]-h[1],z:(s[2]??0)-h[2],index:i,radius:o,reach:r})});const a=!1!==this.options.ghost;return a&&s.engine.depthTexture(),[new o(c,{look:p,lighting:s.lighting,pick:this.pick??void 0,sceneDepth:a?s.engine.sceneDepth:null})]}}
@@ -0,0 +1,52 @@
1
+ import { GeometryFeature } from '../data/Geometry';
2
+ import { GeometryPrimitive } from '../engine/GeometryFrame';
3
+ import { GpuTubes, Profile } from '../three/primitives/GpuTubes';
4
+ import { BaseStyle, GeometryLayer, GeometryLayerOptions, LayerHost } from './GeometryLayer';
5
+ export interface TubeStyle extends BaseStyle {
6
+ /** The finish it is painted in: a material's name or abbreviation, or its index (`MATERIALS`). */
7
+ material?: string | number;
8
+ /** Never thinner on screen than this, in view pixels: its line's width on a 2D map. 2.5 by default. */
9
+ width?: number;
10
+ /** On a 2D map, light running along its line, in the direction of its points. */
11
+ flow?: boolean;
12
+ }
13
+ /** A standing tube for a point feature: a shaft, a pole, a well. */
14
+ export interface TubeStand {
15
+ /** Heights of its foot and its top, in world units. */
16
+ bottom: number;
17
+ top: number;
18
+ radius: number;
19
+ /** A shaft, its top open for the cover lying there (the default), or closed. */
20
+ open?: boolean;
21
+ }
22
+ export interface TubeLayerOptions<F> extends GeometryLayerOptions<F, TubeStyle> {
23
+ /** A line feature's cross-section: a radius, or a profile. Round, 0.15 by default. */
24
+ profile?: (feature: F) => number | Profile;
25
+ /** A point feature's standing tube; a point without one is not drawn. */
26
+ stand?: (feature: F) => TubeStand | null | undefined;
27
+ /** Drawn only within this distance of the camera; 0 for always. */
28
+ reach?: (feature: F) => number;
29
+ /** Flow arrows on the tubes, laid out in pixels. */
30
+ arrows?: boolean;
31
+ /**
32
+ * Tubes ending in a shaft are cut back to its wall, and two ending on its axis, or at the same
33
+ * point, meet in a mitre. On by default.
34
+ */
35
+ join?: boolean;
36
+ /** Ghosted where the scene's surface is in front of them, with a halo. On by default. */
37
+ ghost?: boolean;
38
+ /** Covers lying on the open shafts' tops, as a 2D map draws manholes. On by default. */
39
+ covers?: boolean;
40
+ }
41
+ /**
42
+ * Pipes, cables, ducts and their shafts as tubes in 3D (`GpuTubes`): real sizes and cross-
43
+ * sections, mitred bends, joints cut to the shafts' walls, materials, ghosted under the ground.
44
+ * On a 2D map the same features are lines and covers - one look, so a selection, a filter or a
45
+ * colour carries over between the two.
46
+ */
47
+ export declare class TubeLayer<F extends GeometryFeature = GeometryFeature> extends GeometryLayer<F, TubeStyle> {
48
+ private readonly options;
49
+ constructor(options?: TubeLayerOptions<F>);
50
+ protected createPrimitives(host: LayerHost, origin: [number, number, number]): GeometryPrimitive[];
51
+ get primitive(): GpuTubes | null;
52
+ }
@@ -0,0 +1 @@
1
+ import{linesOf as t,pointsOf as e}from"../data/Geometry.js";import{LookFlag as o}from"../three/FeatureLook.js";import{GpuIcons as r,IconShape as i}from"../three/primitives/GpuIcons.js";import{GpuLines as n}from"../three/primitives/GpuLines.js";import{GpuTubes as s,joinTubeEnds as p,roundProfile as h}from"../three/primitives/GpuTubes.js";import{materialCode as a}from"../three/Shading.js";import{GeometryLayer as c}from"./GeometryLayer.js";export class TubeLayer extends c{constructor(t={}){super(t),this.options=t}createPrimitives(c,d){const m=this.options,f=new Map,g=(t,e)=>`${Math.round(100*t)},${Math.round(100*e)}`,w=this.features.map(t=>{const o=e(t.geometry)[0],r=o&&m.stand?.(t);return o&&r&&!1!==r.open&&f.set(g(o[0],o[1]),r.radius),o&&r?{point:o,stand:r}:null}),v=this.addRole((t,e,r,i,n)=>{const s=w[e];n.color=this.colorOf(r.color,r.opacity,i,"#4cc9f0"),n.material=a(r.material),n.weight=r.weight??1,n.fadedWeight=.3*(r.weight??1),n.flags=r.flow?o.Flow:0,s?(n.width=2*s.stand.radius,n.meters=!0):(n.width=r.width??2.5,n.meters=!1,n.realWidth=2*l(m.profile?.(t))[0])}),k=[],y=[];if(w.forEach((t,e)=>{t&&!1!==t.stand.open&&!1!==m.covers&&y.push({x:t.point[0]-d[0],y:t.point[1]-d[1],z:t.stand.top-d[2]+.01,cell:i.Cover,index:e})}),"2d"===c.mode){const e=[],o=new Float32Array(2*this.features.length);return this.features.forEach((r,i)=>{e.push(t(r.geometry).filter(t=>t.length>1).map(t=>{const e=t[0],r=t[t.length-1];return o[2*i]=f.get(g(e[0],e[1]))??0,o[2*i+1]=f.get(g(r[0],r[1]))??0,t.map(t=>({x:t[0]-d[0],y:t[1]-d[1],z:0}))}))}),k.push(new n(e,{look:v,pick:this.pick??void 0,arrows:!!m.arrows,ends:o})),y.length>0&&k.push(new r(y.map(t=>({...t,z:0})),null,1,{look:v,pick:this.pick??void 0,minPixels:7})),k}const x=[],j=!1!==m.join;this.features.forEach((e,o)=>{const r=m.reach?.(e)??0,i=w[o];if(i){const{point:t,stand:e}=i;return void x.push({points:[[t[0]-d[0],t[1]-d[1],e.bottom-d[2]],[t[0]-d[0],t[1]-d[1],e.top-d[2]]],index:o,profile:h(e.radius),reach:r,kind:!1===e.open?"column":"shaft"})}const n=l(m.profile?.(e));for(const i of t(e.geometry)){if(i.length<2)continue;let t=i.map(t=>[t[0]-d[0],t[1]-d[1],(t[2]??0)-d[2]]);const e=[0,0];if(j){const o=f.get(g(i[0][0],i[0][1])),r=f.get(g(i[i.length-1][0],i[i.length-1][1]));o&&o>n[0]&&(e[0]=Math.sqrt(o*o-n[0]*n[0]),t=u(t,e[0])),r&&r>n[0]&&(e[1]=Math.sqrt(r*r-n[0]*n[0]),t=u(t.reverse(),e[1]).reverse())}t.length<2||x.push({points:t,index:o,profile:n,reach:r,cuts:e})}}),j&&p(x,.01);const M=!1!==m.ghost;M&&c.engine.depthTexture();const G=new s(x,{look:v,lighting:c.lighting,up:c.up,pick:this.pick??void 0,arrows:!!m.arrows,sceneDepth:M?c.engine.sceneDepth:null});return k.push(G),y.length>0&&k.push(new r(y,null,1,{look:v,pick:this.pick??void 0,orientation:"ground",up:c.up,depth:!0})),k}get primitive(){return this.primitives.find(t=>t instanceof s)??null}}function l(t){return void 0===t?h(.15):"number"==typeof t?h(t):t}function u(t,e){let o=e;for(let e=0;e<t.length-1;e++){const[r,i]=[t[e],t[e+1]],n=Math.hypot(i[0]-r[0],i[1]-r[1],i[2]-r[2]);if(n>o+.001){const s=o/n;return[[r[0]+(i[0]-r[0])*s,r[1]+(i[1]-r[1])*s,r[2]+(i[2]-r[2])*s],...t.slice(e+1)]}o-=n}return t}
@@ -0,0 +1,21 @@
1
+ import type { Geometry, MultiPolygonGeometry, PolygonGeometry } from '../data/Geometry';
2
+ /** Everything any of the polygons covers, as one. Null if they cover nothing. */
3
+ export declare function union(...geometries: (Geometry | null | undefined)[]): PolygonGeometry | MultiPolygonGeometry | null;
4
+ /** What all the polygons cover together. Null where they do not overlap. */
5
+ export declare function intersection(...geometries: (Geometry | null | undefined)[]): PolygonGeometry | MultiPolygonGeometry | null;
6
+ /** What the first covers that none of the rest does. */
7
+ export declare function difference(subject: Geometry | null | undefined, ...clips: (Geometry | null | undefined)[]): PolygonGeometry | MultiPolygonGeometry | null;
8
+ /** What an odd number of them covers: one but not the other, for two. */
9
+ export declare function xor(...geometries: (Geometry | null | undefined)[]): PolygonGeometry | MultiPolygonGeometry | null;
10
+ export interface BufferOptions {
11
+ /** Sides of a full circle at round ends and corners: more is rounder. 32 by default. */
12
+ segments?: number;
13
+ /** A line's ends: round, or cut flat at its end points. Round by default. */
14
+ cap?: 'round' | 'flat';
15
+ }
16
+ /**
17
+ * Everything within `distance` of a geometry, across the map: a disc round a point, a corridor
18
+ * round a line (a pipe's protection strip, a route's catchment), a polygon grown by it - or, for
19
+ * a polygon and a negative distance, shrunk by it. Null where nothing is left.
20
+ */
21
+ export declare function buffer(geometry: Geometry | null | undefined, distance: number, options?: BufferOptions): PolygonGeometry | MultiPolygonGeometry | null;
@@ -0,0 +1 @@
1
+ import n from"polygon-clipping";import{linesOf as t,pointsOf as e,polygonsOf as o}from"../data/Geometry.js";import{closeLine as r}from"./Lines.js";import{circle as l}from"./Polygons.js";import{openLength as i}from"./Triangulate.js";const c=n.default??n;function f(n){return o(n).map(n=>n.filter(n=>i(n)>=3).map(n=>r(n).map(n=>[n[0],n[1]]))).filter(n=>n.length>0)}function u(n){const t=n.filter(n=>n.length>0&&n[0].length>=4);return 0===t.length?null:1===t.length?{type:"Polygon",coordinates:t[0]}:{type:"MultiPolygon",coordinates:t}}export function union(...n){const t=n.map(f).filter(n=>n.length>0);return 0===t.length?null:u(c.union(t[0],...t.slice(1)))}export function intersection(...n){const t=n.map(f);return 0===t.length||t.some(n=>0===n.length)?null:u(c.intersection(t[0],...t.slice(1)))}export function difference(n,...t){const e=f(n);if(0===e.length)return null;const o=t.map(f).filter(n=>n.length>0);return 0===o.length?u(e):u(c.difference(e,...o))}export function xor(...n){const t=n.map(f).filter(n=>n.length>0);return 0===t.length?null:u(c.xor(t[0],...t.slice(1)))}export function buffer(n,o,r={}){if(!n)return null;const i=Math.max(8,r.segments??32),h=Math.abs(o),s=[],a=f(n);if(0===h)return a.length>0?u(a):null;const p=n=>l([n[0],n[1]],h,i).coordinates,g=(n,t)=>{for(let t=1;t<n.length;t++){const e=n[t-1],o=n[t],r=o[0]-e[0],l=o[1]-e[1],i=Math.hypot(r,l);if(0===i)continue;const c=-l/i*h,f=r/i*h;s.push([[[e[0]+c,e[1]+f],[e[0]-c,e[1]-f],[o[0]-c,o[1]-f],[o[0]+c,o[1]+f],[e[0]+c,e[1]+f]]])}n.forEach((e,o)=>{(0===o||o===n.length-1)&&!t||s.push(p(e))})};return o<0?0===a.length?null:(a.forEach(n=>n.forEach(n=>g(n,!0))),0===s.length?u(a):u(c.difference(a,c.union(s[0],...s.slice(1))))):(e(n).forEach(n=>s.push(p(n))),t(n).forEach(n=>{1===n.length?s.push(p(n[0])):g(n,"flat"!==r.cap)}),a.forEach(n=>{s.push(n),n.forEach(n=>g(n,!0))}),0===s.length?null:u(c.union(s[0],...s.slice(1))))}
@@ -0,0 +1,70 @@
1
+ import { GeometryFeature, Position } from '../data/Geometry';
2
+ import { Vec3 } from './Vector';
3
+ /** What part of a feature: a point, a segment of a line, or a segment of a polygon's ring. */
4
+ export type FeaturePartKind = 'point' | 'line' | 'ring';
5
+ /** A place on a feature, found by the index: the feature, the point, and where on it. */
6
+ export interface FeaturePlace<F> {
7
+ feature: F;
8
+ /** The feature's index in the features indexed. */
9
+ featureIndex: number;
10
+ /** The point found, its height interpolated along a segment. */
11
+ point: Vec3;
12
+ /** How far from the query point, across the map. */
13
+ distance: number;
14
+ kind: FeaturePartKind;
15
+ /**
16
+ * Which line or ring: lines numbered first in the feature's own order (a multi-line's parts),
17
+ * then its polygons' rings in order (outer ring, holes, next polygon); for points, which point.
18
+ */
19
+ part: number;
20
+ /** The vertex: the segment's first point's index in its line or ring; for points, 0. */
21
+ vertex: number;
22
+ /** On a segment, how far along it, 0 at `vertex` to 1 at the next. */
23
+ t: number;
24
+ }
25
+ /**
26
+ * Features indexed for finding by place, across the map: the nearest vertex or edge to a point -
27
+ * snapping, the pipe nearest a house - what lies in a box, what is at a point. Every point and
28
+ * segment goes into one `SpatialIndex`; build it again when the features change.
29
+ */
30
+ export declare class FeatureIndex<F extends GeometryFeature<any> = GeometryFeature> {
31
+ readonly features: readonly F[];
32
+ private readonly index;
33
+ private readonly boxes;
34
+ /** Per item: [ax, ay, az, bx, by, bz]. */
35
+ private readonly segments;
36
+ private readonly featureOf;
37
+ private readonly partOf;
38
+ private readonly vertexOf;
39
+ private readonly kindOf;
40
+ constructor(features: readonly F[]);
41
+ /**
42
+ * The vertex nearest `p` across the map - a point, a line's or a ring's corner - within
43
+ * `maxDistance`. `filter` may pass over features.
44
+ */
45
+ nearestVertex(p: Position, maxDistance?: number, filter?: (feature: F, index: number) => boolean): FeaturePlace<F> | null;
46
+ /** The nearest point on any feature's edge, line or point to `p` across the map, within `maxDistance`. */
47
+ nearestEdge(p: Position, maxDistance?: number, filter?: (feature: F, index: number) => boolean): FeaturePlace<F> | null;
48
+ /**
49
+ * The feature at `p`: a polygon it is inside (distance 0), or the nearest line or point within
50
+ * `tolerance`. Polygons win over what is merely near.
51
+ */
52
+ featureAt(p: Position, tolerance?: number, filter?: (feature: F, index: number) => boolean): FeaturePlace<F> | null;
53
+ /** Every feature with a part in the box, each once, in index order. */
54
+ inBox(minX: number, minY: number, maxX: number, maxY: number): F[];
55
+ /** The features nearest `p`, each once, nearest first: up to `k`, no further than `maxDistance`. */
56
+ nearestFeatures(p: Position, k?: number, maxDistance?: number): FeaturePlace<F>[];
57
+ /** The items - points and segments - whose boxes touch a box across the map, by index: for `item`. */
58
+ itemsIn(minX: number, minY: number, maxX: number, maxY: number): number[];
59
+ /** An item's two ends (the same for a point), its feature and where on it. */
60
+ item(i: number): {
61
+ a: Vec3;
62
+ b: Vec3;
63
+ feature: F;
64
+ featureIndex: number;
65
+ kind: FeaturePartKind;
66
+ part: number;
67
+ vertex: number;
68
+ };
69
+ private place;
70
+ }