rgeo 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. data/History.rdoc +6 -0
  2. data/README.rdoc +1 -1
  3. data/Version +1 -1
  4. data/ext/geos_c_impl/extconf.rb +13 -13
  5. data/ext/geos_c_impl/factory.c +30 -18
  6. data/ext/geos_c_impl/factory.h +18 -12
  7. data/ext/geos_c_impl/geometry.c +11 -11
  8. data/ext/geos_c_impl/geometry.h +7 -7
  9. data/ext/geos_c_impl/geometry_collection.c +15 -15
  10. data/ext/geos_c_impl/geometry_collection.h +8 -8
  11. data/ext/geos_c_impl/line_string.c +14 -14
  12. data/ext/geos_c_impl/line_string.h +7 -7
  13. data/ext/geos_c_impl/main.c +7 -7
  14. data/ext/geos_c_impl/point.c +9 -9
  15. data/ext/geos_c_impl/point.h +7 -7
  16. data/ext/geos_c_impl/polygon.c +9 -9
  17. data/ext/geos_c_impl/polygon.h +7 -7
  18. data/ext/geos_c_impl/preface.h +7 -7
  19. data/ext/proj4_c_impl/extconf.rb +13 -13
  20. data/ext/proj4_c_impl/main.c +12 -12
  21. data/lib/rgeo.rb +26 -26
  22. data/lib/rgeo/cartesian.rb +12 -12
  23. data/lib/rgeo/cartesian/analysis.rb +26 -26
  24. data/lib/rgeo/cartesian/bounding_box.rb +83 -83
  25. data/lib/rgeo/cartesian/calculations.rb +36 -36
  26. data/lib/rgeo/cartesian/factory.rb +78 -78
  27. data/lib/rgeo/cartesian/feature_classes.rb +74 -74
  28. data/lib/rgeo/cartesian/feature_methods.rb +34 -34
  29. data/lib/rgeo/cartesian/interface.rb +33 -33
  30. data/lib/rgeo/coord_sys.rb +15 -15
  31. data/lib/rgeo/coord_sys/cs/entities.rb +533 -534
  32. data/lib/rgeo/coord_sys/cs/factories.rb +69 -69
  33. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +44 -44
  34. data/lib/rgeo/coord_sys/proj4.rb +85 -85
  35. data/lib/rgeo/coord_sys/srs_database/active_record_table.rb +31 -31
  36. data/lib/rgeo/coord_sys/srs_database/interface.rb +44 -44
  37. data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +31 -31
  38. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +31 -31
  39. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +29 -29
  40. data/lib/rgeo/error.rb +17 -17
  41. data/lib/rgeo/feature.rb +15 -15
  42. data/lib/rgeo/feature/curve.rb +58 -58
  43. data/lib/rgeo/feature/factory.rb +84 -84
  44. data/lib/rgeo/feature/factory_generator.rb +32 -32
  45. data/lib/rgeo/feature/geometry.rb +215 -215
  46. data/lib/rgeo/feature/geometry_collection.rb +46 -46
  47. data/lib/rgeo/feature/line.rb +21 -21
  48. data/lib/rgeo/feature/line_string.rb +35 -35
  49. data/lib/rgeo/feature/linear_ring.rb +20 -20
  50. data/lib/rgeo/feature/mixins.rb +61 -61
  51. data/lib/rgeo/feature/multi_curve.rb +37 -37
  52. data/lib/rgeo/feature/multi_line_string.rb +20 -20
  53. data/lib/rgeo/feature/multi_point.rb +22 -22
  54. data/lib/rgeo/feature/multi_polygon.rb +28 -28
  55. data/lib/rgeo/feature/multi_surface.rb +39 -39
  56. data/lib/rgeo/feature/point.rb +42 -42
  57. data/lib/rgeo/feature/polygon.rb +50 -50
  58. data/lib/rgeo/feature/surface.rb +42 -42
  59. data/lib/rgeo/feature/types.rb +58 -58
  60. data/lib/rgeo/geographic.rb +14 -14
  61. data/lib/rgeo/geographic/factory.rb +87 -87
  62. data/lib/rgeo/geographic/interface.rb +55 -55
  63. data/lib/rgeo/geographic/proj4_projector.rb +35 -35
  64. data/lib/rgeo/geographic/projected_feature_classes.rb +95 -95
  65. data/lib/rgeo/geographic/projected_feature_methods.rb +81 -81
  66. data/lib/rgeo/geographic/projected_window.rb +103 -103
  67. data/lib/rgeo/geographic/simple_mercator_projector.rb +32 -32
  68. data/lib/rgeo/geographic/spherical_feature_classes.rb +93 -93
  69. data/lib/rgeo/geographic/spherical_feature_methods.rb +25 -25
  70. data/lib/rgeo/geographic/spherical_math.rb +58 -58
  71. data/lib/rgeo/geos.rb +22 -17
  72. data/lib/rgeo/geos/factory.rb +93 -93
  73. data/lib/rgeo/geos/ffi_classes.rb +306 -231
  74. data/lib/rgeo/geos/ffi_factory.rb +100 -96
  75. data/lib/rgeo/geos/impl_additions.rb +22 -22
  76. data/lib/rgeo/geos/interface.rb +45 -45
  77. data/lib/rgeo/geos/zm_factory.rb +90 -90
  78. data/lib/rgeo/geos/zm_impl.rb +167 -167
  79. data/lib/rgeo/impl_helper.rb +11 -11
  80. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +71 -71
  81. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +29 -29
  82. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +61 -61
  83. data/lib/rgeo/impl_helper/basic_point_methods.rb +43 -43
  84. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +35 -35
  85. data/lib/rgeo/impl_helper/math.rb +13 -13
  86. data/lib/rgeo/version.rb +10 -10
  87. data/lib/rgeo/wkrep.rb +16 -16
  88. data/lib/rgeo/wkrep/wkb_generator.rb +51 -51
  89. data/lib/rgeo/wkrep/wkb_parser.rb +52 -52
  90. data/lib/rgeo/wkrep/wkt_generator.rb +51 -51
  91. data/lib/rgeo/wkrep/wkt_parser.rb +66 -66
  92. data/lib/rgeo/yaml.rb +14 -14
  93. data/test/common/geometry_collection_tests.rb +53 -53
  94. data/test/common/line_string_tests.rb +57 -57
  95. data/test/common/multi_line_string_tests.rb +43 -43
  96. data/test/common/multi_point_tests.rb +43 -43
  97. data/test/common/multi_polygon_tests.rb +43 -43
  98. data/test/common/point_tests.rb +75 -75
  99. data/test/common/polygon_tests.rb +37 -37
  100. data/test/coord_sys/tc_active_record_table.rb +25 -25
  101. data/test/coord_sys/tc_ogc_cs.rb +72 -72
  102. data/test/coord_sys/tc_proj4.rb +51 -51
  103. data/test/coord_sys/tc_proj4_srs_data.rb +17 -17
  104. data/test/coord_sys/tc_sr_org.rb +15 -15
  105. data/test/coord_sys/tc_url_reader.rb +19 -19
  106. data/test/geos_capi/tc_factory.rb +21 -21
  107. data/test/geos_capi/tc_geometry_collection.rb +15 -15
  108. data/test/geos_capi/tc_line_string.rb +15 -15
  109. data/test/geos_capi/tc_misc.rb +33 -22
  110. data/test/geos_capi/tc_multi_line_string.rb +15 -15
  111. data/test/geos_capi/tc_multi_point.rb +15 -15
  112. data/test/geos_capi/tc_multi_polygon.rb +15 -15
  113. data/test/geos_capi/tc_parsing_unparsing.rb +19 -19
  114. data/test/geos_capi/tc_point.rb +21 -21
  115. data/test/geos_capi/tc_polygon.rb +19 -19
  116. data/test/geos_capi/tc_zmfactory.rb +17 -17
  117. data/test/geos_ffi/tc_factory.rb +21 -21
  118. data/test/geos_ffi/tc_geometry_collection.rb +15 -15
  119. data/test/geos_ffi/tc_line_string.rb +15 -15
  120. data/test/geos_ffi/tc_misc.rb +49 -15
  121. data/test/geos_ffi/tc_multi_line_string.rb +15 -15
  122. data/test/geos_ffi/tc_multi_point.rb +15 -15
  123. data/test/geos_ffi/tc_multi_polygon.rb +15 -15
  124. data/test/geos_ffi/tc_parsing_unparsing.rb +19 -19
  125. data/test/geos_ffi/tc_point.rb +21 -21
  126. data/test/geos_ffi/tc_polygon.rb +19 -19
  127. data/test/geos_ffi/tc_zmfactory.rb +17 -17
  128. data/test/projected_geographic/tc_geometry_collection.rb +15 -15
  129. data/test/projected_geographic/tc_line_string.rb +15 -15
  130. data/test/projected_geographic/tc_multi_line_string.rb +15 -15
  131. data/test/projected_geographic/tc_multi_point.rb +15 -15
  132. data/test/projected_geographic/tc_multi_polygon.rb +15 -15
  133. data/test/projected_geographic/tc_point.rb +23 -23
  134. data/test/projected_geographic/tc_polygon.rb +15 -15
  135. data/test/simple_cartesian/tc_calculations.rb +31 -31
  136. data/test/simple_cartesian/tc_geometry_collection.rb +17 -17
  137. data/test/simple_cartesian/tc_line_string.rb +17 -17
  138. data/test/simple_cartesian/tc_multi_line_string.rb +17 -17
  139. data/test/simple_cartesian/tc_multi_point.rb +17 -17
  140. data/test/simple_cartesian/tc_multi_polygon.rb +17 -17
  141. data/test/simple_cartesian/tc_point.rb +21 -21
  142. data/test/simple_cartesian/tc_polygon.rb +17 -17
  143. data/test/simple_mercator/tc_geometry_collection.rb +15 -15
  144. data/test/simple_mercator/tc_line_string.rb +15 -15
  145. data/test/simple_mercator/tc_multi_line_string.rb +15 -15
  146. data/test/simple_mercator/tc_multi_point.rb +15 -15
  147. data/test/simple_mercator/tc_multi_polygon.rb +15 -15
  148. data/test/simple_mercator/tc_point.rb +23 -23
  149. data/test/simple_mercator/tc_polygon.rb +15 -15
  150. data/test/simple_mercator/tc_window.rb +50 -50
  151. data/test/spherical_geographic/tc_calculations.rb +47 -47
  152. data/test/spherical_geographic/tc_geometry_collection.rb +17 -17
  153. data/test/spherical_geographic/tc_line_string.rb +17 -17
  154. data/test/spherical_geographic/tc_multi_line_string.rb +17 -17
  155. data/test/spherical_geographic/tc_multi_point.rb +17 -17
  156. data/test/spherical_geographic/tc_multi_polygon.rb +17 -17
  157. data/test/spherical_geographic/tc_point.rb +23 -23
  158. data/test/spherical_geographic/tc_polygon.rb +17 -17
  159. data/test/tc_cartesian_analysis.rb +23 -23
  160. data/test/tc_mixins.rb +39 -39
  161. data/test/tc_oneoff.rb +15 -15
  162. data/test/tc_types.rb +17 -17
  163. data/test/wkrep/tc_wkb_generator.rb +67 -67
  164. data/test/wkrep/tc_wkb_parser.rb +73 -73
  165. data/test/wkrep/tc_wkt_generator.rb +75 -75
  166. data/test/wkrep/tc_wkt_parser.rb +97 -97
  167. metadata +3 -3
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Spherical geographic feature classes
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,19 +35,19 @@
35
35
 
36
36
 
37
37
  module RGeo
38
-
38
+
39
39
  module Geographic
40
-
41
-
40
+
41
+
42
42
  class SphericalPointImpl # :nodoc:
43
-
44
-
43
+
44
+
45
45
  include Feature::Point
46
46
  include ImplHelper::BasicGeometryMethods
47
47
  include ImplHelper::BasicPointMethods
48
48
  include SphericalGeometryMethods
49
-
50
-
49
+
50
+
51
51
  def _validate_geometry
52
52
  @x = @x % 360.0
53
53
  @x -= 360.0 if @x >= 180.0
@@ -55,13 +55,13 @@ module RGeo
55
55
  @y = -90.0 if @y < -90.0
56
56
  super
57
57
  end
58
-
59
-
58
+
59
+
60
60
  def _xyz
61
61
  @xyz ||= SphericalMath::PointXYZ.from_latlon(@y, @x)
62
62
  end
63
-
64
-
63
+
64
+
65
65
  def distance(rhs_)
66
66
  rhs_ = Feature.cast(rhs_, @factory)
67
67
  case rhs_
@@ -71,8 +71,8 @@ module RGeo
71
71
  super
72
72
  end
73
73
  end
74
-
75
-
74
+
75
+
76
76
  def equals?(rhs_)
77
77
  return false unless rhs_.is_a?(self.class) && rhs_.factory == self.factory
78
78
  case rhs_
@@ -92,148 +92,148 @@ module RGeo
92
92
  false
93
93
  end
94
94
  end
95
-
96
-
95
+
96
+
97
97
  alias_method :longitude, :x
98
98
  alias_method :lon, :x
99
99
  alias_method :latitude, :y
100
100
  alias_method :lat, :y
101
-
102
-
101
+
102
+
103
103
  Feature::MixinCollection::GLOBAL.for_type(Feature::Point).include_in_class(self, true)
104
-
105
-
104
+
105
+
106
106
  end
107
-
108
-
107
+
108
+
109
109
  class SphericalLineStringImpl # :nodoc:
110
-
111
-
110
+
111
+
112
112
  include Feature::LineString
113
113
  include ImplHelper::BasicGeometryMethods
114
114
  include ImplHelper::BasicLineStringMethods
115
115
  include SphericalGeometryMethods
116
116
  include SphericalLineStringMethods
117
-
118
-
117
+
118
+
119
119
  Feature::MixinCollection::GLOBAL.for_type(Feature::LineString).include_in_class(self, true)
120
-
121
-
120
+
121
+
122
122
  end
123
-
124
-
123
+
124
+
125
125
  class SphericalLineImpl # :nodoc:
126
-
127
-
126
+
127
+
128
128
  include Feature::Line
129
129
  include ImplHelper::BasicGeometryMethods
130
130
  include ImplHelper::BasicLineStringMethods
131
131
  include ImplHelper::BasicLineMethods
132
132
  include SphericalGeometryMethods
133
133
  include SphericalLineStringMethods
134
-
135
-
134
+
135
+
136
136
  Feature::MixinCollection::GLOBAL.for_type(Feature::Line).include_in_class(self, true)
137
-
138
-
137
+
138
+
139
139
  end
140
-
141
-
140
+
141
+
142
142
  class SphericalLinearRingImpl # :nodoc:
143
-
144
-
143
+
144
+
145
145
  include Feature::LinearRing
146
146
  include ImplHelper::BasicGeometryMethods
147
147
  include ImplHelper::BasicLineStringMethods
148
148
  include ImplHelper::BasicLinearRingMethods
149
149
  include SphericalGeometryMethods
150
150
  include SphericalLineStringMethods
151
-
152
-
151
+
152
+
153
153
  Feature::MixinCollection::GLOBAL.for_type(Feature::LinearRing).include_in_class(self, true)
154
-
155
-
154
+
155
+
156
156
  end
157
-
158
-
157
+
158
+
159
159
  class SphericalPolygonImpl # :nodoc:
160
-
161
-
160
+
161
+
162
162
  include Feature::Polygon
163
163
  include ImplHelper::BasicGeometryMethods
164
164
  include ImplHelper::BasicPolygonMethods
165
165
  include SphericalGeometryMethods
166
-
167
-
166
+
167
+
168
168
  Feature::MixinCollection::GLOBAL.for_type(Feature::Polygon).include_in_class(self, true)
169
-
170
-
169
+
170
+
171
171
  end
172
-
173
-
172
+
173
+
174
174
  class SphericalGeometryCollectionImpl # :nodoc:
175
-
176
-
175
+
176
+
177
177
  include Feature::GeometryCollection
178
178
  include ImplHelper::BasicGeometryMethods
179
179
  include ImplHelper::BasicGeometryCollectionMethods
180
180
  include SphericalGeometryMethods
181
-
182
-
181
+
182
+
183
183
  Feature::MixinCollection::GLOBAL.for_type(Feature::GeometryCollection).include_in_class(self, true)
184
-
185
-
184
+
185
+
186
186
  end
187
-
188
-
187
+
188
+
189
189
  class SphericalMultiPointImpl # :nodoc:
190
-
191
-
190
+
191
+
192
192
  include Feature::MultiPoint
193
193
  include ImplHelper::BasicGeometryMethods
194
194
  include ImplHelper::BasicGeometryCollectionMethods
195
195
  include ImplHelper::BasicMultiPointMethods
196
196
  include SphericalGeometryMethods
197
-
198
-
197
+
198
+
199
199
  Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPoint).include_in_class(self, true)
200
-
201
-
200
+
201
+
202
202
  end
203
-
204
-
203
+
204
+
205
205
  class SphericalMultiLineStringImpl # :nodoc:
206
-
207
-
206
+
207
+
208
208
  include Feature::MultiLineString
209
209
  include ImplHelper::BasicGeometryMethods
210
210
  include ImplHelper::BasicGeometryCollectionMethods
211
211
  include ImplHelper::BasicMultiLineStringMethods
212
212
  include SphericalGeometryMethods
213
-
214
-
213
+
214
+
215
215
  Feature::MixinCollection::GLOBAL.for_type(Feature::MultiLineString).include_in_class(self, true)
216
-
217
-
216
+
217
+
218
218
  end
219
-
220
-
219
+
220
+
221
221
  class SphericalMultiPolygonImpl # :nodoc:
222
-
223
-
222
+
223
+
224
224
  include Feature::MultiPolygon
225
225
  include ImplHelper::BasicGeometryMethods
226
226
  include ImplHelper::BasicGeometryCollectionMethods
227
227
  include ImplHelper::BasicMultiPolygonMethods
228
228
  include SphericalGeometryMethods
229
-
230
-
229
+
230
+
231
231
  Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPolygon).include_in_class(self, true)
232
-
233
-
232
+
233
+
234
234
  end
235
-
236
-
235
+
236
+
237
237
  end
238
-
238
+
239
239
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Spherical geographic common methods
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,24 +35,24 @@
35
35
 
36
36
 
37
37
  module RGeo
38
-
38
+
39
39
  module Geographic
40
-
41
-
40
+
41
+
42
42
  module SphericalGeometryMethods # :nodoc:
43
-
44
-
43
+
44
+
45
45
  def srid
46
46
  factory.srid
47
47
  end
48
-
49
-
48
+
49
+
50
50
  end
51
-
52
-
51
+
52
+
53
53
  module SphericalLineStringMethods # :nodoc:
54
-
55
-
54
+
55
+
56
56
  def _arcs
57
57
  unless @arcs
58
58
  @arcs = (0..num_points-2).map do |i_|
@@ -61,8 +61,8 @@ module RGeo
61
61
  end
62
62
  @arcs
63
63
  end
64
-
65
-
64
+
65
+
66
66
  def is_simple?
67
67
  arcs_ = _arcs
68
68
  len_ = arcs_.length
@@ -87,11 +87,11 @@ module RGeo
87
87
  end
88
88
  true
89
89
  end
90
-
91
-
90
+
91
+
92
92
  end
93
-
94
-
93
+
94
+
95
95
  end
96
-
96
+
97
97
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Core calculations on the sphere
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
- # Copyright 2010 Daniel Azuma
7
- #
6
+ # Copyright 2010-2012 Daniel Azuma
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,28 +35,28 @@
35
35
 
36
36
 
37
37
  module RGeo
38
-
38
+
39
39
  module Geographic
40
-
40
+
41
41
  module SphericalMath # :nodoc:
42
-
43
-
42
+
43
+
44
44
  RADIUS = 6378137.0
45
-
46
-
45
+
46
+
47
47
  # Represents a point on the unit sphere in (x,y,z) coordinates
48
48
  # instead of lat-lon. This form is often faster, more convenient,
49
49
  # and more numerically stable for certain computations.
50
- #
50
+ #
51
51
  # The coordinate system is a right-handed system where the z-axis
52
52
  # goes through the north pole, the x-axis goes through the prime
53
53
  # meridian, and the y-axis goes through +90 degrees longitude.
54
- #
54
+ #
55
55
  # This object is also used to represent a great circle, as its axis
56
56
  # of rotation.
57
-
57
+
58
58
  class PointXYZ # :nodoc:
59
-
59
+
60
60
  def initialize(x_, y_, z_)
61
61
  r_ = ::Math.sqrt(x_ * x_ + y_ * y_ + z_ * z_)
62
62
  @x = x_ / r_
@@ -64,48 +64,48 @@ module RGeo
64
64
  @z = z_ / r_
65
65
  raise "Not a number" if @x.nan? || @y.nan? || @z.nan?
66
66
  end
67
-
68
-
67
+
68
+
69
69
  def to_s
70
70
  "(#{@x}, #{@y}, #{@z})"
71
71
  end
72
-
73
-
72
+
73
+
74
74
  attr_reader :x
75
75
  attr_reader :y
76
76
  attr_reader :z
77
-
78
-
77
+
78
+
79
79
  def eql?(rhs_)
80
80
  rhs_.kind_of?(PointXYZ) && @x == rhs_.x && @y == rhs_.y && @z == rhs_.z
81
81
  end
82
82
  alias_method :==, :eql?
83
-
84
-
83
+
84
+
85
85
  def latlon
86
86
  lat_rad_ = ::Math.asin(@z)
87
87
  lon_rad_ = ::Math.atan2(@y, @x) rescue 0.0
88
88
  rpd_ = ImplHelper::Math::RADIANS_PER_DEGREE
89
89
  [lat_rad_ / rpd_, lon_rad_ / rpd_]
90
90
  end
91
-
92
-
91
+
92
+
93
93
  def *(rhs_)
94
94
  val_ = @x * rhs_.x + @y * rhs_.y + @z * rhs_.z
95
95
  val_ = 1.0 if val_ > 1.0
96
96
  val_ = -1.0 if val_ < -1.0
97
97
  val_
98
98
  end
99
-
100
-
99
+
100
+
101
101
  def %(rhs_)
102
102
  rx_ = rhs_.x
103
103
  ry_ = rhs_.y
104
104
  rz_ = rhs_.z
105
105
  PointXYZ.new(@y*rz_-@z*ry_, @z*rx_-@x*rz_, @x*ry_-@y*rx_) rescue nil
106
106
  end
107
-
108
-
107
+
108
+
109
109
  def dist_to_point(rhs_)
110
110
  rx_ = rhs_.x
111
111
  ry_ = rhs_.y
@@ -117,8 +117,8 @@ module RGeo
117
117
  r_ = 1.0 if r_ > 1.0
118
118
  ::Math.asin(r_)
119
119
  end
120
-
121
-
120
+
121
+
122
122
  def self.from_latlon(lat_, lon_)
123
123
  rpd_ = ImplHelper::Math::RADIANS_PER_DEGREE
124
124
  lat_rad_ = rpd_ * lat_
@@ -129,58 +129,58 @@ module RGeo
129
129
  y_ = ::Math.sin(lon_rad_) * r_
130
130
  new(x_, y_, z_)
131
131
  end
132
-
132
+
133
133
  end
134
-
135
-
134
+
135
+
136
136
  # Represents a finite arc on the sphere.
137
-
137
+
138
138
  class ArcXYZ # :nodoc:
139
-
139
+
140
140
  def initialize(start_, end_)
141
141
  @s = start_
142
142
  @e = end_
143
143
  @axis = false
144
144
  end
145
-
146
-
145
+
146
+
147
147
  attr_reader :s
148
148
  attr_reader :e
149
-
150
-
149
+
150
+
151
151
  def to_s
152
152
  "#{@s} - #{@e}"
153
153
  end
154
-
155
-
154
+
155
+
156
156
  def eql?(rhs_)
157
157
  rhs_.kind_of?(ArcXYZ) && @s == rhs_.s && @e == rhs_.e
158
158
  end
159
159
  alias_method :==, :eql?
160
-
161
-
160
+
161
+
162
162
  def degenerate?
163
163
  axis_ = axis
164
164
  axis_.x == 0 && axis_.y == 0 && axis_.z == 0
165
165
  end
166
-
167
-
166
+
167
+
168
168
  def axis
169
169
  if @axis == false
170
170
  @axis = @s % @e
171
171
  end
172
172
  @axis
173
173
  end
174
-
175
-
174
+
175
+
176
176
  def contains_point?(obj_)
177
177
  axis_ = axis
178
178
  saxis_ = ArcXYZ.new(@s, obj_).axis
179
179
  eaxis_ = ArcXYZ.new(obj_, @e).axis
180
180
  !saxis_ || !eaxis_ || obj_ * axis_ == 0.0 && saxis_ * axis_ > 0 && eaxis_ * axis_ > 0
181
181
  end
182
-
183
-
182
+
183
+
184
184
  def intersects_arc?(obj_)
185
185
  my_axis_ = axis
186
186
  dot1_ = my_axis_ * obj_.s
@@ -194,13 +194,13 @@ module RGeo
194
194
  false
195
195
  end
196
196
  end
197
-
198
-
197
+
198
+
199
199
  end
200
-
201
-
200
+
201
+
202
202
  end
203
-
203
+
204
204
  end
205
-
205
+
206
206
  end