@mapwhit/tilerenderer 1.0.0 → 1.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.
- package/build/min/package.json +2 -1
- package/build/min/src/shaders/_prelude.fragment.glsl.js +1 -1
- package/build/min/src/shaders/_prelude.vertex.glsl.js +1 -1
- package/build/min/src/shaders/background.fragment.glsl.js +1 -1
- package/build/min/src/shaders/background.vertex.glsl.js +1 -1
- package/build/min/src/shaders/background_pattern.fragment.glsl.js +1 -1
- package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -1
- package/build/min/src/shaders/circle.fragment.glsl.js +1 -1
- package/build/min/src/shaders/circle.vertex.glsl.js +1 -1
- package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -1
- package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -1
- package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -1
- package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -1
- package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -1
- package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -1
- package/build/min/src/shaders/debug.fragment.glsl.js +1 -1
- package/build/min/src/shaders/debug.vertex.glsl.js +1 -1
- package/build/min/src/shaders/fill.fragment.glsl.js +1 -1
- package/build/min/src/shaders/fill.vertex.glsl.js +1 -1
- package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +1 -1
- package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +1 -1
- package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +1 -1
- package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +1 -1
- package/build/min/src/shaders/fill_outline.fragment.glsl.js +1 -1
- package/build/min/src/shaders/fill_outline.vertex.glsl.js +1 -1
- package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +1 -1
- package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +1 -1
- package/build/min/src/shaders/fill_pattern.fragment.glsl.js +1 -1
- package/build/min/src/shaders/fill_pattern.vertex.glsl.js +1 -1
- package/build/min/src/shaders/heatmap.fragment.glsl.js +1 -1
- package/build/min/src/shaders/heatmap.vertex.glsl.js +1 -1
- package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +1 -1
- package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -1
- package/build/min/src/shaders/hillshade.fragment.glsl.js +1 -1
- package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -1
- package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +1 -1
- package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -1
- package/build/min/src/shaders/line.fragment.glsl.js +1 -1
- package/build/min/src/shaders/line.vertex.glsl.js +1 -1
- package/build/min/src/shaders/line_gradient.fragment.glsl.js +1 -1
- package/build/min/src/shaders/line_gradient.vertex.glsl.js +1 -1
- package/build/min/src/shaders/line_pattern.fragment.glsl.js +1 -1
- package/build/min/src/shaders/line_pattern.vertex.glsl.js +1 -1
- package/build/min/src/shaders/line_sdf.fragment.glsl.js +1 -1
- package/build/min/src/shaders/line_sdf.vertex.glsl.js +1 -1
- package/build/min/src/shaders/raster.fragment.glsl.js +1 -1
- package/build/min/src/shaders/raster.vertex.glsl.js +1 -1
- package/build/min/src/shaders/symbol_icon.fragment.glsl.js +1 -1
- package/build/min/src/shaders/symbol_icon.vertex.glsl.js +1 -1
- package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +1 -1
- package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +1 -1
- package/package.json +3 -2
- package/src/data/array_types.js +54 -81
- package/src/data/bucket/circle_attributes.js +2 -4
- package/src/data/bucket/circle_bucket.js +19 -13
- package/src/data/bucket/fill_attributes.js +2 -4
- package/src/data/bucket/fill_bucket.js +38 -24
- package/src/data/bucket/fill_extrusion_attributes.js +2 -4
- package/src/data/bucket/fill_extrusion_bucket.js +56 -34
- package/src/data/bucket/heatmap_bucket.js +2 -7
- package/src/data/bucket/line_attributes.js +2 -4
- package/src/data/bucket/line_bucket.js +207 -159
- package/src/data/bucket/pattern_attributes.js +2 -4
- package/src/data/bucket/pattern_bucket_features.js +5 -7
- package/src/data/bucket/symbol_attributes.js +12 -26
- package/src/data/bucket/symbol_bucket.js +111 -221
- package/src/data/bucket/symbol_buffers.js +62 -0
- package/src/data/bucket/symbol_collision_buffers.js +33 -0
- package/src/data/bucket.js +2 -6
- package/src/data/dem_data.js +11 -7
- package/src/data/extent.js +1 -1
- package/src/data/feature_index.js +35 -20
- package/src/data/index_array_type.js +1 -6
- package/src/data/load_geometry.js +6 -9
- package/src/data/pos_attributes.js +2 -3
- package/src/data/program_configuration.js +44 -26
- package/src/data/raster_bounds_attributes.js +2 -2
- package/src/data/segment.js +4 -3
- package/src/geo/coordinate.js +1 -1
- package/src/geo/lng_lat.js +3 -3
- package/src/geo/lng_lat_bounds.js +8 -4
- package/src/geo/transform.js +69 -30
- package/src/gl/color_mode.js +2 -2
- package/src/gl/context.js +28 -29
- package/src/gl/cull_face_mode.js +1 -1
- package/src/gl/depth_mode.js +1 -1
- package/src/gl/framebuffer.js +8 -4
- package/src/gl/index_buffer.js +2 -2
- package/src/gl/stencil_mode.js +1 -1
- package/src/gl/value.js +33 -68
- package/src/gl/vertex_buffer.js +2 -2
- package/src/index.js +49 -25
- package/src/render/draw_background.js +14 -9
- package/src/render/draw_circle.js +11 -8
- package/src/render/draw_collision_debug.js +11 -8
- package/src/render/draw_debug.js +16 -14
- package/src/render/draw_fill.js +19 -12
- package/src/render/draw_fill_extrusion.js +12 -9
- package/src/render/draw_heatmap.js +17 -12
- package/src/render/draw_hillshade.js +12 -9
- package/src/render/draw_line.js +30 -16
- package/src/render/draw_raster.js +17 -13
- package/src/render/draw_symbol.js +22 -17
- package/src/render/glyph_atlas.js +9 -5
- package/src/render/glyph_manager.js +1 -1
- package/src/render/image_atlas.js +4 -7
- package/src/render/image_manager.js +6 -9
- package/src/render/line_atlas.js +2 -2
- package/src/render/painter.js +65 -47
- package/src/render/program/background_program.js +6 -13
- package/src/render/program/circle_program.js +4 -6
- package/src/render/program/clipping_mask_program.js +3 -5
- package/src/render/program/collision_program.js +4 -6
- package/src/render/program/debug_program.js +3 -5
- package/src/render/program/fill_extrusion_program.js +8 -14
- package/src/render/program/fill_program.js +10 -21
- package/src/render/program/heatmap_program.js +8 -14
- package/src/render/program/hillshade_program.js +10 -16
- package/src/render/program/line_program.js +11 -22
- package/src/render/program/pattern.js +5 -7
- package/src/render/program/program_uniforms.js +13 -20
- package/src/render/program/raster_program.js +3 -5
- package/src/render/program/symbol_program.js +5 -7
- package/src/render/program.js +5 -6
- package/src/render/texture.js +1 -1
- package/src/render/tile_mask.js +6 -4
- package/src/render/uniform_binding.js +9 -20
- package/src/render/vertex_array_object.js +5 -3
- package/src/shaders/encode_attribute.js +2 -6
- package/src/shaders/index.js +103 -51
- package/src/source/geojson_source.js +11 -7
- package/src/source/geojson_worker_source.js +7 -7
- package/src/source/geojson_wrapper.js +4 -4
- package/src/source/image_source.js +11 -12
- package/src/source/load_tilejson.js +3 -3
- package/src/source/pixels_to_tile_units.js +3 -3
- package/src/source/query_features.js +13 -10
- package/src/source/raster_dem_tile_source.js +12 -10
- package/src/source/raster_tile_source.js +13 -9
- package/src/source/resources/glyphs.js +2 -3
- package/src/source/resources/index.js +2 -4
- package/src/source/rtl_text_plugin.js +8 -8
- package/src/source/source.js +9 -15
- package/src/source/source_cache.js +105 -47
- package/src/source/source_state.js +37 -14
- package/src/source/tile.js +38 -23
- package/src/source/tile_bounds.js +15 -8
- package/src/source/tile_cache.js +2 -2
- package/src/source/tile_id.js +30 -23
- package/src/source/vector_tile_source.js +10 -8
- package/src/source/vector_tile_worker_source.js +4 -4
- package/src/source/worker_tile.js +24 -22
- package/src/style/create_style_layer.js +11 -11
- package/src/style/evaluation_parameters.js +4 -6
- package/src/style/light.js +5 -5
- package/src/style/load_sprite.js +6 -6
- package/src/style/parse_glyph_pbf.js +21 -17
- package/src/style/pauseable_placement.js +3 -4
- package/src/style/properties.js +21 -44
- package/src/style/query_utils.js +4 -10
- package/src/style/style.js +58 -33
- package/src/style/style_layer/background_style_layer.js +3 -4
- package/src/style/style_layer/background_style_layer_properties.js +2 -2
- package/src/style/style_layer/circle_style_layer.js +12 -9
- package/src/style/style_layer/circle_style_layer_properties.js +2 -2
- package/src/style/style_layer/fill_extrusion_style_layer.js +16 -13
- package/src/style/style_layer/fill_extrusion_style_layer_properties.js +2 -2
- package/src/style/style_layer/fill_style_layer.js +6 -7
- package/src/style/style_layer/fill_style_layer_properties.js +2 -2
- package/src/style/style_layer/heatmap_style_layer.js +5 -6
- package/src/style/style_layer/heatmap_style_layer_properties.js +2 -2
- package/src/style/style_layer/hillshade_style_layer.js +3 -4
- package/src/style/style_layer/hillshade_style_layer_properties.js +2 -2
- package/src/style/style_layer/line_style_layer.js +10 -11
- package/src/style/style_layer/line_style_layer_properties.js +5 -5
- package/src/style/style_layer/raster_style_layer.js +3 -4
- package/src/style/style_layer/raster_style_layer_properties.js +2 -2
- package/src/style/style_layer/symbol_style_layer.js +7 -8
- package/src/style/style_layer/symbol_style_layer_properties.js +2 -2
- package/src/style/style_layer.js +21 -20
- package/src/style/style_layer_index.js +2 -2
- package/src/style/zoom_history.js +1 -1
- package/src/style-spec/error/parsing_error.js +1 -1
- package/src/style-spec/error/validation_error.js +5 -3
- package/src/style-spec/feature_filter/convert.js +17 -9
- package/src/style-spec/feature_filter/index.js +13 -9
- package/src/style-spec/util/eval_support.js +2 -2
- package/src/style-spec/util/ref_properties.js +1 -1
- package/src/symbol/anchor.js +2 -2
- package/src/symbol/check_max_angle.js +13 -5
- package/src/symbol/clip_line.js +2 -3
- package/src/symbol/collision_feature.js +8 -4
- package/src/symbol/collision_index.js +5 -7
- package/src/symbol/cross_tile_symbol_index.js +5 -5
- package/src/symbol/get_anchors.js +15 -8
- package/src/symbol/grid_index.js +5 -3
- package/src/symbol/mergelines.js +2 -2
- package/src/symbol/opacity_state.js +1 -1
- package/src/symbol/placement.js +25 -20
- package/src/symbol/projection.js +29 -28
- package/src/symbol/quads.js +10 -12
- package/src/symbol/shaping.js +27 -19
- package/src/symbol/symbol_layout.js +17 -21
- package/src/symbol/symbol_size.js +13 -12
- package/src/symbol/transform_text.js +3 -3
- package/src/ui/camera.js +34 -18
- package/src/ui/map.js +53 -33
- package/src/util/async.js +11 -5
- package/src/util/browser.js +1 -1
- package/src/util/callback.js +3 -9
- package/src/util/classify_rings.js +13 -8
- package/src/util/color_ramp.js +3 -3
- package/src/util/config.js +4 -4
- package/src/util/dictionary_coder.js +2 -3
- package/src/util/dom.js +7 -3
- package/src/util/find_pole_of_inaccessibility.js +29 -14
- package/src/util/group_layers.js +1 -1
- package/src/util/image.js +3 -8
- package/src/util/interpolate.js +1 -1
- package/src/util/intersection_tests.js +80 -42
- package/src/util/is_char_in_unicode_block.js +1 -1
- package/src/util/key.js +7 -3
- package/src/util/loader/image.js +1 -1
- package/src/util/object.js +25 -23
- package/src/util/script_detection.js +212 -91
- package/src/util/struct_array.js +8 -40
- package/src/util/task_queue.js +11 -7
- package/src/util/throttle.js +2 -2
- package/src/util/tile_cover.js +8 -5
- package/src/util/token.js +1 -1
- package/src/util/unique_id.js +2 -2
- package/src/util/util.js +21 -29
- package/src/util/vectortile_to_geojson.js +4 -2
- package/src/util/verticalize_punctuation.js +3 -7
- package/src/util/warn.js +4 -4
- package/src/util/web_worker.js +3 -3
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
polygonIntersectsBufferedPoint,
|
|
6
|
-
polygonIntersectsMultiPolygon,
|
|
7
|
-
polygonIntersectsBufferedMultiLine,
|
|
8
|
-
polygonIntersectsPolygon,
|
|
9
|
-
distToSegmentSquared,
|
|
10
|
-
polygonIntersectsBox
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
function polygonIntersectsPolygon(polygonA, polygonB) {
|
|
1
|
+
import Point from '@mapbox/point-geometry';
|
|
2
|
+
import { isCounterClockwise } from './util.js';
|
|
3
|
+
|
|
4
|
+
export function polygonIntersectsPolygon(polygonA, polygonB) {
|
|
14
5
|
for (let i = 0; i < polygonA.length; i++) {
|
|
15
|
-
if (polygonContainsPoint(polygonB, polygonA[i]))
|
|
6
|
+
if (polygonContainsPoint(polygonB, polygonA[i])) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
16
9
|
}
|
|
17
10
|
|
|
18
11
|
for (let i = 0; i < polygonB.length; i++) {
|
|
19
|
-
if (polygonContainsPoint(polygonA, polygonB[i]))
|
|
12
|
+
if (polygonContainsPoint(polygonA, polygonB[i])) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
20
15
|
}
|
|
21
16
|
|
|
22
|
-
if (lineIntersectsLine(polygonA, polygonB))
|
|
17
|
+
if (lineIntersectsLine(polygonA, polygonB)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
23
20
|
|
|
24
21
|
return false;
|
|
25
22
|
}
|
|
26
23
|
|
|
27
|
-
function polygonIntersectsBufferedPoint(polygon, point, radius) {
|
|
28
|
-
if (polygonContainsPoint(polygon, point))
|
|
29
|
-
|
|
24
|
+
export function polygonIntersectsBufferedPoint(polygon, point, radius) {
|
|
25
|
+
if (polygonContainsPoint(polygon, point)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
if (pointIntersectsBufferedLine(point, polygon, radius)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
30
31
|
return false;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
function polygonIntersectsMultiPolygon(polygon, multiPolygon) {
|
|
34
|
+
export function polygonIntersectsMultiPolygon(polygon, multiPolygon) {
|
|
34
35
|
if (polygon.length === 1) {
|
|
35
36
|
return multiPolygonContainsPoint(multiPolygon, polygon[0]);
|
|
36
37
|
}
|
|
@@ -38,62 +39,82 @@ function polygonIntersectsMultiPolygon(polygon, multiPolygon) {
|
|
|
38
39
|
for (let m = 0; m < multiPolygon.length; m++) {
|
|
39
40
|
const ring = multiPolygon[m];
|
|
40
41
|
for (let n = 0; n < ring.length; n++) {
|
|
41
|
-
if (polygonContainsPoint(polygon, ring[n]))
|
|
42
|
+
if (polygonContainsPoint(polygon, ring[n])) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
42
45
|
}
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
for (let i = 0; i < polygon.length; i++) {
|
|
46
|
-
if (multiPolygonContainsPoint(multiPolygon, polygon[i]))
|
|
49
|
+
if (multiPolygonContainsPoint(multiPolygon, polygon[i])) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
for (let k = 0; k < multiPolygon.length; k++) {
|
|
50
|
-
if (lineIntersectsLine(polygon, multiPolygon[k]))
|
|
55
|
+
if (lineIntersectsLine(polygon, multiPolygon[k])) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
return false;
|
|
54
61
|
}
|
|
55
62
|
|
|
56
|
-
function polygonIntersectsBufferedMultiLine(polygon, multiLine, radius) {
|
|
63
|
+
export function polygonIntersectsBufferedMultiLine(polygon, multiLine, radius) {
|
|
57
64
|
for (let i = 0; i < multiLine.length; i++) {
|
|
58
65
|
const line = multiLine[i];
|
|
59
66
|
|
|
60
67
|
if (polygon.length >= 3) {
|
|
61
68
|
for (let k = 0; k < line.length; k++) {
|
|
62
|
-
if (polygonContainsPoint(polygon, line[k]))
|
|
69
|
+
if (polygonContainsPoint(polygon, line[k])) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
63
72
|
}
|
|
64
73
|
}
|
|
65
74
|
|
|
66
|
-
if (lineIntersectsBufferedLine(polygon, line, radius))
|
|
75
|
+
if (lineIntersectsBufferedLine(polygon, line, radius)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
67
78
|
}
|
|
68
79
|
return false;
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
function lineIntersectsBufferedLine(lineA, lineB, radius) {
|
|
72
83
|
if (lineA.length > 1) {
|
|
73
|
-
if (lineIntersectsLine(lineA, lineB))
|
|
84
|
+
if (lineIntersectsLine(lineA, lineB)) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
74
87
|
|
|
75
88
|
// Check whether any point in either line is within radius of the other line
|
|
76
89
|
for (let j = 0; j < lineB.length; j++) {
|
|
77
|
-
if (pointIntersectsBufferedLine(lineB[j], lineA, radius))
|
|
90
|
+
if (pointIntersectsBufferedLine(lineB[j], lineA, radius)) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
78
93
|
}
|
|
79
94
|
}
|
|
80
95
|
|
|
81
96
|
for (let k = 0; k < lineA.length; k++) {
|
|
82
|
-
if (pointIntersectsBufferedLine(lineA[k], lineB, radius))
|
|
97
|
+
if (pointIntersectsBufferedLine(lineA[k], lineB, radius)) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
83
100
|
}
|
|
84
101
|
|
|
85
102
|
return false;
|
|
86
103
|
}
|
|
87
104
|
|
|
88
105
|
function lineIntersectsLine(lineA, lineB) {
|
|
89
|
-
if (lineA.length === 0 || lineB.length === 0)
|
|
106
|
+
if (lineA.length === 0 || lineB.length === 0) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
90
109
|
for (let i = 0; i < lineA.length - 1; i++) {
|
|
91
110
|
const a0 = lineA[i];
|
|
92
111
|
const a1 = lineA[i + 1];
|
|
93
112
|
for (let j = 0; j < lineB.length - 1; j++) {
|
|
94
113
|
const b0 = lineB[j];
|
|
95
114
|
const b1 = lineB[j + 1];
|
|
96
|
-
if (lineSegmentIntersectsLineSegment(a0, a1, b0, b1))
|
|
115
|
+
if (lineSegmentIntersectsLineSegment(a0, a1, b0, b1)) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
97
118
|
}
|
|
98
119
|
}
|
|
99
120
|
return false;
|
|
@@ -109,25 +130,35 @@ function lineSegmentIntersectsLineSegment(a0, a1, b0, b1) {
|
|
|
109
130
|
function pointIntersectsBufferedLine(p, line, radius) {
|
|
110
131
|
const radiusSquared = radius * radius;
|
|
111
132
|
|
|
112
|
-
if (line.length === 1)
|
|
133
|
+
if (line.length === 1) {
|
|
134
|
+
return p.distSqr(line[0]) < radiusSquared;
|
|
135
|
+
}
|
|
113
136
|
|
|
114
137
|
for (let i = 1; i < line.length; i++) {
|
|
115
138
|
// Find line segments that have a distance <= radius^2 to p
|
|
116
139
|
// In that case, we treat the line as "containing point p".
|
|
117
140
|
const v = line[i - 1];
|
|
118
141
|
const w = line[i];
|
|
119
|
-
if (distToSegmentSquared(p, v, w) < radiusSquared)
|
|
142
|
+
if (distToSegmentSquared(p, v, w) < radiusSquared) {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
120
145
|
}
|
|
121
146
|
return false;
|
|
122
147
|
}
|
|
123
148
|
|
|
124
149
|
// Code from http://stackoverflow.com/a/1501725/331379.
|
|
125
|
-
function distToSegmentSquared(p, v, w) {
|
|
150
|
+
export function distToSegmentSquared(p, v, w) {
|
|
126
151
|
const l2 = v.distSqr(w);
|
|
127
|
-
if (l2 === 0)
|
|
152
|
+
if (l2 === 0) {
|
|
153
|
+
return p.distSqr(v);
|
|
154
|
+
}
|
|
128
155
|
const t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
|
|
129
|
-
if (t < 0)
|
|
130
|
-
|
|
156
|
+
if (t < 0) {
|
|
157
|
+
return p.distSqr(v);
|
|
158
|
+
}
|
|
159
|
+
if (t > 1) {
|
|
160
|
+
return p.distSqr(w);
|
|
161
|
+
}
|
|
131
162
|
return p.distSqr(w.sub(v)._mult(t)._add(v));
|
|
132
163
|
}
|
|
133
164
|
|
|
@@ -163,23 +194,29 @@ function polygonContainsPoint(ring, p) {
|
|
|
163
194
|
return c;
|
|
164
195
|
}
|
|
165
196
|
|
|
166
|
-
function polygonIntersectsBox(ring, boxX1, boxY1, boxX2, boxY2) {
|
|
197
|
+
export function polygonIntersectsBox(ring, boxX1, boxY1, boxX2, boxY2) {
|
|
167
198
|
for (const p of ring) {
|
|
168
|
-
if (boxX1 <= p.x && boxY1 <= p.y && boxX2 >= p.x && boxY2 >= p.y)
|
|
199
|
+
if (boxX1 <= p.x && boxY1 <= p.y && boxX2 >= p.x && boxY2 >= p.y) {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
169
202
|
}
|
|
170
203
|
|
|
171
204
|
const corners = [new Point(boxX1, boxY1), new Point(boxX1, boxY2), new Point(boxX2, boxY2), new Point(boxX2, boxY1)];
|
|
172
205
|
|
|
173
206
|
if (ring.length > 2) {
|
|
174
207
|
for (const corner of corners) {
|
|
175
|
-
if (polygonContainsPoint(ring, corner))
|
|
208
|
+
if (polygonContainsPoint(ring, corner)) {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
176
211
|
}
|
|
177
212
|
}
|
|
178
213
|
|
|
179
214
|
for (let i = 0; i < ring.length - 1; i++) {
|
|
180
215
|
const p1 = ring[i];
|
|
181
216
|
const p2 = ring[i + 1];
|
|
182
|
-
if (edgeIntersectsBox(p1, p2, corners))
|
|
217
|
+
if (edgeIntersectsBox(p1, p2, corners)) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
183
220
|
}
|
|
184
221
|
|
|
185
222
|
return false;
|
|
@@ -194,8 +231,9 @@ function edgeIntersectsBox(e1, e2, corners) {
|
|
|
194
231
|
(e1.x > br.x && e2.x > br.x) ||
|
|
195
232
|
(e1.y < tl.y && e2.y < tl.y) ||
|
|
196
233
|
(e1.y > br.y && e2.y > br.y)
|
|
197
|
-
)
|
|
234
|
+
) {
|
|
198
235
|
return false;
|
|
236
|
+
}
|
|
199
237
|
|
|
200
238
|
// check if all corners of the box are on the same side of the edge
|
|
201
239
|
const dir = isCounterClockwise(e1, e2, corners[0]);
|
package/src/util/key.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
export default createKey;
|
|
2
2
|
|
|
3
3
|
function stringify(obj) {
|
|
4
|
-
if (obj == null)
|
|
4
|
+
if (obj == null) {
|
|
5
|
+
return 'null';
|
|
6
|
+
}
|
|
5
7
|
const type = typeof obj;
|
|
6
|
-
if (type === 'number' || type === 'boolean' || type === 'string')
|
|
8
|
+
if (type === 'number' || type === 'boolean' || type === 'string') {
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
7
11
|
|
|
8
12
|
if (Array.isArray(obj)) {
|
|
9
13
|
return '[' + obj.map(val => stringify(val)).join(',') + ']';
|
package/src/util/loader/image.js
CHANGED
package/src/util/object.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* // justName = { name: 'Charlie' }
|
|
13
13
|
* @private
|
|
14
14
|
*/
|
|
15
|
-
function pick(src, properties) {
|
|
15
|
+
export function pick(src, properties) {
|
|
16
16
|
const entries = properties.filter(p => p in src).map(p => [p, src[p]]);
|
|
17
17
|
return Object.fromEntries(entries);
|
|
18
18
|
}
|
|
@@ -38,7 +38,7 @@ function pick(src, properties) {
|
|
|
38
38
|
* setTimeout(myClass.ontimer, 100);
|
|
39
39
|
* @private
|
|
40
40
|
*/
|
|
41
|
-
function bindAll(fns, context) {
|
|
41
|
+
export function bindAll(fns, context) {
|
|
42
42
|
fns.forEach(fn => {
|
|
43
43
|
if (!context[fn]) {
|
|
44
44
|
return;
|
|
@@ -53,7 +53,7 @@ function bindAll(fns, context) {
|
|
|
53
53
|
*
|
|
54
54
|
* @private
|
|
55
55
|
*/
|
|
56
|
-
function mapObject(input, iterator, context) {
|
|
56
|
+
export function mapObject(input, iterator, context) {
|
|
57
57
|
context ??= this;
|
|
58
58
|
const entries = Object.entries(input).map(([k, v]) => [k, iterator.call(context, v, k, input)]);
|
|
59
59
|
return Object.fromEntries(entries);
|
|
@@ -64,7 +64,7 @@ function mapObject(input, iterator, context) {
|
|
|
64
64
|
*
|
|
65
65
|
* @private
|
|
66
66
|
*/
|
|
67
|
-
function filterObject(input, iterator, context) {
|
|
67
|
+
export function filterObject(input, iterator, context) {
|
|
68
68
|
context ??= this;
|
|
69
69
|
const entries = Object.entries(input).filter(([k, v]) => iterator.call(context, v, k, input));
|
|
70
70
|
return Object.fromEntries(entries);
|
|
@@ -75,20 +75,30 @@ function filterObject(input, iterator, context) {
|
|
|
75
75
|
*
|
|
76
76
|
* @private
|
|
77
77
|
*/
|
|
78
|
-
function deepEqual(a, b) {
|
|
78
|
+
export function deepEqual(a, b) {
|
|
79
79
|
if (Array.isArray(a)) {
|
|
80
|
-
if (!Array.isArray(b) || a.length !== b.length)
|
|
80
|
+
if (!Array.isArray(b) || a.length !== b.length) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
81
83
|
for (let i = 0; i < a.length; i++) {
|
|
82
|
-
if (!deepEqual(a[i], b[i]))
|
|
84
|
+
if (!deepEqual(a[i], b[i])) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
83
87
|
}
|
|
84
88
|
return true;
|
|
85
89
|
}
|
|
86
90
|
if (typeof a === 'object' && a !== null && b !== null) {
|
|
87
|
-
if (!(typeof b === 'object'))
|
|
91
|
+
if (!(typeof b === 'object')) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
88
94
|
const keys = Object.keys(a);
|
|
89
|
-
if (keys.length !== Object.keys(b).length)
|
|
95
|
+
if (keys.length !== Object.keys(b).length) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
90
98
|
for (const key in a) {
|
|
91
|
-
if (!deepEqual(a[key], b[key]))
|
|
99
|
+
if (!deepEqual(a[key], b[key])) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
92
102
|
}
|
|
93
103
|
return true;
|
|
94
104
|
}
|
|
@@ -100,7 +110,7 @@ function deepEqual(a, b) {
|
|
|
100
110
|
*
|
|
101
111
|
* @private
|
|
102
112
|
*/
|
|
103
|
-
function clone(input) {
|
|
113
|
+
export function clone(input) {
|
|
104
114
|
if (Array.isArray(input)) {
|
|
105
115
|
return input.map(clone);
|
|
106
116
|
}
|
|
@@ -115,19 +125,11 @@ function clone(input) {
|
|
|
115
125
|
*
|
|
116
126
|
* @private
|
|
117
127
|
*/
|
|
118
|
-
function arraysIntersect(a, b) {
|
|
128
|
+
export function arraysIntersect(a, b) {
|
|
119
129
|
for (let l = 0; l < a.length; l++) {
|
|
120
|
-
if (b.indexOf(a[l]) >= 0)
|
|
130
|
+
if (b.indexOf(a[l]) >= 0) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
121
133
|
}
|
|
122
134
|
return false;
|
|
123
135
|
}
|
|
124
|
-
|
|
125
|
-
module.exports = {
|
|
126
|
-
pick,
|
|
127
|
-
bindAll,
|
|
128
|
-
mapObject,
|
|
129
|
-
filterObject,
|
|
130
|
-
deepEqual,
|
|
131
|
-
clone,
|
|
132
|
-
arraysIntersect
|
|
133
|
-
};
|