turf-ruby 0.8.1 → 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.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +21 -0
  3. data/README.md +163 -140
  4. data/lib/turf/along.rb +10 -3
  5. data/lib/turf/angle.rb +8 -0
  6. data/lib/turf/area.rb +4 -1
  7. data/lib/turf/bbox.rb +36 -0
  8. data/lib/turf/bbox_clip.rb +74 -0
  9. data/lib/turf/bbox_polygon.rb +41 -0
  10. data/lib/turf/bearing.rb +5 -2
  11. data/lib/turf/bezier_spline.rb +8 -0
  12. data/lib/turf/boolean_clockwise.rb +26 -0
  13. data/lib/turf/boolean_concave.rb +40 -0
  14. data/lib/turf/boolean_contains.rb +52 -0
  15. data/lib/turf/boolean_crosses.rb +8 -0
  16. data/lib/turf/boolean_disjoint.rb +8 -0
  17. data/lib/turf/boolean_equal.rb +8 -0
  18. data/lib/turf/boolean_intersects.rb +8 -0
  19. data/lib/turf/boolean_overlap.rb +8 -0
  20. data/lib/turf/boolean_parallel.rb +8 -0
  21. data/lib/turf/boolean_point_in_polygon.rb +5 -3
  22. data/lib/turf/boolean_point_on_line.rb +128 -0
  23. data/lib/turf/boolean_touches.rb +8 -0
  24. data/lib/turf/boolean_valid.rb +8 -0
  25. data/lib/turf/boolean_within.rb +8 -0
  26. data/lib/turf/buffer.rb +8 -0
  27. data/lib/turf/center.rb +32 -0
  28. data/lib/turf/center_mean.rb +8 -0
  29. data/lib/turf/center_median.rb +8 -0
  30. data/lib/turf/center_of_mass.rb +8 -0
  31. data/lib/turf/centroid.rb +5 -2
  32. data/lib/turf/circle.rb +5 -2
  33. data/lib/turf/clean_coords.rb +8 -0
  34. data/lib/turf/clone.rb +8 -0
  35. data/lib/turf/clusters.rb +32 -0
  36. data/lib/turf/clusters_dbscan.rb +8 -0
  37. data/lib/turf/clusters_kmeans.rb +8 -0
  38. data/lib/turf/collect.rb +8 -0
  39. data/lib/turf/combine.rb +8 -0
  40. data/lib/turf/concave.rb +8 -0
  41. data/lib/turf/convex.rb +8 -0
  42. data/lib/turf/destination.rb +6 -3
  43. data/lib/turf/difference.rb +8 -0
  44. data/lib/turf/directional_mean.rb +8 -0
  45. data/lib/turf/dissolve.rb +8 -0
  46. data/lib/turf/distance.rb +5 -2
  47. data/lib/turf/distance_weight.rb +12 -0
  48. data/lib/turf/ellipse.rb +8 -0
  49. data/lib/turf/envelope.rb +8 -0
  50. data/lib/turf/explode.rb +29 -0
  51. data/lib/turf/flatten.rb +8 -0
  52. data/lib/turf/flip.rb +8 -0
  53. data/lib/turf/geojson_rbush.rb +8 -0
  54. data/lib/turf/great_circle.rb +8 -0
  55. data/lib/turf/helpers.rb +166 -26
  56. data/lib/turf/hex_grid.rb +8 -0
  57. data/lib/turf/interpolate.rb +8 -0
  58. data/lib/turf/intersect.rb +8 -0
  59. data/lib/turf/invariant.rb +127 -1
  60. data/lib/turf/isobands.rb +8 -0
  61. data/lib/turf/isolines.rb +8 -0
  62. data/lib/turf/kinks.rb +8 -0
  63. data/lib/turf/length.rb +6 -3
  64. data/lib/turf/lib/lineclip.rb +118 -0
  65. data/lib/turf/line_arc.rb +8 -0
  66. data/lib/turf/line_chunk.rb +8 -0
  67. data/lib/turf/line_intersect.rb +8 -0
  68. data/lib/turf/line_offset.rb +8 -0
  69. data/lib/turf/line_overlap.rb +8 -0
  70. data/lib/turf/line_segment.rb +8 -0
  71. data/lib/turf/line_slice.rb +8 -0
  72. data/lib/turf/line_slice_along.rb +8 -0
  73. data/lib/turf/line_split.rb +8 -0
  74. data/lib/turf/line_to_polygon.rb +8 -0
  75. data/lib/turf/mask.rb +8 -0
  76. data/lib/turf/meta.rb +445 -79
  77. data/lib/turf/midpoint.rb +8 -0
  78. data/lib/turf/moran_index.rb +8 -0
  79. data/lib/turf/nearest_neighbor_analysis.rb +8 -0
  80. data/lib/turf/nearest_point.rb +8 -0
  81. data/lib/turf/nearest_point_on_line.rb +8 -0
  82. data/lib/turf/nearest_point_to_line.rb +8 -0
  83. data/lib/turf/planepoint.rb +8 -0
  84. data/lib/turf/point_grid.rb +8 -0
  85. data/lib/turf/point_on_feature.rb +8 -0
  86. data/lib/turf/point_to_line_distance.rb +8 -0
  87. data/lib/turf/point_to_polygon_distance.rb +8 -0
  88. data/lib/turf/points_within_polygon.rb +8 -0
  89. data/lib/turf/polygon_smooth.rb +8 -0
  90. data/lib/turf/polygon_tangents.rb +8 -0
  91. data/lib/turf/polygon_to_line.rb +20 -0
  92. data/lib/turf/polygonize.rb +8 -0
  93. data/lib/turf/projection.rb +12 -0
  94. data/lib/turf/quadrat_analysis.rb +8 -0
  95. data/lib/turf/random.rb +20 -0
  96. data/lib/turf/rectangle_grid.rb +8 -0
  97. data/lib/turf/rewind.rb +8 -0
  98. data/lib/turf/rhumb_bearing.rb +8 -0
  99. data/lib/turf/rhumb_destination.rb +8 -0
  100. data/lib/turf/rhumb_distance.rb +8 -0
  101. data/lib/turf/sample.rb +8 -0
  102. data/lib/turf/sector.rb +8 -0
  103. data/lib/turf/shortest_path.rb +8 -0
  104. data/lib/turf/simplify.rb +8 -0
  105. data/lib/turf/square.rb +42 -0
  106. data/lib/turf/square_grid.rb +8 -0
  107. data/lib/turf/standard_deviational_ellipse.rb +8 -0
  108. data/lib/turf/tag.rb +8 -0
  109. data/lib/turf/tesselate.rb +8 -0
  110. data/lib/turf/tin.rb +8 -0
  111. data/lib/turf/transform_rotate.rb +8 -0
  112. data/lib/turf/transform_scale.rb +8 -0
  113. data/lib/turf/transform_translate.rb +8 -0
  114. data/lib/turf/triangle_grid.rb +8 -0
  115. data/lib/turf/truncate.rb +3 -0
  116. data/lib/turf/union.rb +8 -0
  117. data/lib/turf/unkink_polygon.rb +8 -0
  118. data/lib/turf/version.rb +2 -1
  119. data/lib/turf/voronoi.rb +8 -0
  120. data/lib/turf.rb +2 -0
  121. data/lib/turf_ruby.rb +107 -3
  122. metadata +106 -3
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Turf
4
+ # :nodoc:
5
+ module Lineclip
6
+ # Cohen-Sutherland line clipping algorithm, adapted to efficiently
7
+ # handle polylines rather than just segments.
8
+ def self.lineclip(points, bbox, result = [])
9
+ len = points.length
10
+ code_a = bit_code(points[0], bbox)
11
+ part = []
12
+ a = nil
13
+ b = nil
14
+
15
+ (1...len).each do |i|
16
+ a = points[i - 1]
17
+ b = points[i]
18
+ code_b = last_code = bit_code(b, bbox)
19
+
20
+ loop do
21
+ if (code_a | code_b).zero?
22
+ # accept
23
+ part << a
24
+
25
+ if code_b != last_code
26
+ # segment went outside
27
+ part << b
28
+
29
+ if i < len - 1
30
+ # start a new line
31
+ result << part
32
+ part = []
33
+ end
34
+ elsif i == len - 1
35
+ part << b
36
+ end
37
+ break
38
+ elsif code_a.anybits?(code_b)
39
+ # trivial reject
40
+ break
41
+ elsif code_a != 0
42
+ # a outside, intersect with clip edge
43
+ a = intersect(a, b, code_a, bbox)
44
+ code_a = bit_code(a, bbox)
45
+ else
46
+ # b outside
47
+ b = intersect(a, b, code_b, bbox)
48
+ code_b = bit_code(b, bbox)
49
+ end
50
+ end
51
+
52
+ code_a = last_code
53
+ end
54
+
55
+ result << part unless part.empty?
56
+
57
+ result
58
+ end
59
+
60
+ # Sutherland-Hodgeman polygon clipping algorithm
61
+ def self.polygonclip(points, bbox)
62
+ result = []
63
+ prev = nil
64
+ prev_inside = nil
65
+
66
+ # clip against each side of the clip rectangle
67
+ [8, 4, 2, 1].each do |edge|
68
+ result = []
69
+ prev = points.last
70
+ prev_inside = bit_code(prev, bbox).nobits?(edge)
71
+
72
+ points.each do |p|
73
+ inside = bit_code(p, bbox).nobits?(edge)
74
+
75
+ # if segment goes through the clip window, add an intersection
76
+ result << intersect(prev, p, edge, bbox) if inside != prev_inside
77
+
78
+ result << p if inside # add a point if it's inside
79
+
80
+ prev = p
81
+ prev_inside = inside
82
+ end
83
+
84
+ points = result
85
+ break if points.empty?
86
+ end
87
+
88
+ result
89
+ end
90
+
91
+ # intersect a segment against one of the 4 lines that make up the bbox
92
+ def self.intersect(a, b, edge, bbox) # rubocop:disable Naming/MethodParameterName
93
+ if edge.anybits?(8)
94
+ [a[0] + (((b[0] - a[0]) * (bbox[3] - a[1]).to_f) / (b[1] - a[1])), bbox[3]]
95
+ elsif edge.anybits?(4)
96
+ [a[0] + (((b[0] - a[0]) * (bbox[1] - a[1]).to_f) / (b[1] - a[1])), bbox[1]]
97
+ elsif edge.anybits?(2)
98
+ [bbox[2], a[1] + (((b[1] - a[1]) * (bbox[2] - a[0]).to_f) / (b[0] - a[0]))]
99
+ elsif edge.anybits?(1)
100
+ [bbox[0], a[1] + (((b[1] - a[1]) * (bbox[0] - a[0]).to_f) / (b[0] - a[0]))]
101
+ end
102
+ end
103
+
104
+ # bit code reflects the point position relative to the bbox:
105
+ # left mid right
106
+ # top 1001 1000 1010
107
+ # mid 0001 0000 0010
108
+ # bottom 0101 0100 0110
109
+ def self.bit_code(p, bbox) # rubocop:disable Naming/MethodParameterName
110
+ code = 0
111
+ code |= 1 if p[0] < bbox[0] # left
112
+ code |= 2 if p[0] > bbox[2] # right
113
+ code |= 4 if p[1] < bbox[1] # bottom
114
+ code |= 8 if p[1] > bbox[3] # top
115
+ code
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def line_arc(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def line_chunk(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def line_intersect(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def line_offset(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def line_overlap(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def line_segment(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def line_slice(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def line_slice_along(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def line_split(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def line_to_polygon(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end
data/lib/turf/mask.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :nodoc:
4
+ module Turf
5
+ def mask(*args)
6
+ raise NotImplementedError
7
+ end
8
+ end