Permalink
Browse files

Implement mixins

  • Loading branch information...
dazuma committed May 21, 2011
1 parent 93108fa commit e018ba9995f6d21754d236f7f180b6f2f8c8f0ca
View
@@ -1,11 +1,13 @@
-=== 0.3.0 / 2011-05-18
+=== 0.3.0 / 2011-05-23
-RailsConf Edition
-
-* GEOS implementation now supports native GEOS integration via ffi-geos in addition to RGeo's built-in C integration. This should enable us to provide the GEOS implementation on JRuby. This is experimental at the moment since ffi-geos is still in early beta.
+* GEOS implementation now supports native GEOS integration via ffi-geos in addition to RGeo's built-in C integration. This is experimental right now, since ffi-geos is still in early beta. Indeed, under JRuby, I'm still seeing intermittent segfaults that may be concurrency-related. Caveat emptor. However, this is an important step towards providing the GEOS implementation on JRuby in the future.
+* It is now possible to add mixins to geometry objects "globally". This was not possible previously because there is no global base class; however, the framework now provides global mixin containers that implementations are expected to include.
+* Added RGeo::Feature::Type.supertype.
* Taking the boundary of a GEOS GeometryCollection now returns nil. It used to return an empty GeometryCollection, regardless of the contents of the original collection. GeometryCollection subclasses like MultiPoint, however, do have proper boundaries.
* Renamed the lenient_multi_polygon_assertions GEOS factory parameter to uses_lenient_multi_polygon_assertions. The older name will continue to work.
* The GEOS buffer_resolution and uses_lenient_multi_polygon_assertions options are now exposed via properties.
+* The RGeo::Feature::Polygon module incorrectly included Enumerable. Fixed.
+* Several of the implementations included some extraneous (nonfunctional) methods due to including the wrong modules. Fixed.
=== 0.2.9 / 2011-04-25
@@ -246,6 +246,7 @@ RGeo_Globals* rgeo_init_geos_factory()
VALUE rgeo_module = rb_define_module("RGeo");
globals->geos_module = rb_define_module_under(rgeo_module, "Geos");
globals->feature_module = rb_define_module_under(rgeo_module, "Feature");
+ globals->global_mixins = rb_const_get_at(rb_const_get_at(globals->feature_module, rb_intern("MixinCollection")), rb_intern("GLOBAL"));
// Add C methods to the factory.
VALUE geos_factory_class = rb_const_get_at(globals->geos_module, rb_intern("Factory"));
@@ -51,6 +51,7 @@ RGEO_BEGIN_C
*/
typedef struct {
VALUE feature_module;
+ VALUE global_mixins;
VALUE feature_geometry;
VALUE feature_point;
VALUE feature_line_string;
@@ -652,6 +652,8 @@ void rgeo_init_geos_geometry(RGeo_Globals* globals)
VALUE geos_geometry_class = rb_define_class_under(globals->geos_module, "GeometryImpl", rb_cObject);
globals->geos_geometry = geos_geometry_class;
globals->feature_geometry = rb_const_get_at(globals->feature_module, rb_intern("Geometry"));
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ globals->feature_geometry, geos_geometry_class);
rb_define_alloc_func(geos_geometry_class, alloc_geometry);
rb_define_method(geos_geometry_class, "_set_factory", method_geometry_set_factory, 1);
@@ -390,15 +390,30 @@ void rgeo_init_geos_geometry_collection(RGeo_Globals* globals)
VALUE geos_geometry_collection_class = rb_define_class_under(globals->geos_module, "GeometryCollectionImpl", globals->geos_geometry);
globals->geos_geometry_collection = geos_geometry_collection_class;
globals->feature_geometry_collection = rb_const_get_at(globals->feature_module, rb_intern("GeometryCollection"));
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ globals->feature_geometry_collection, geos_geometry_collection_class);
+
VALUE geos_multi_point_class = rb_define_class_under(globals->geos_module, "MultiPointImpl", geos_geometry_collection_class);
globals->geos_multi_point = geos_multi_point_class;
globals->feature_multi_point = rb_const_get_at(globals->feature_module, rb_intern("MultiPoint"));
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ globals->feature_multi_point, geos_multi_point_class);
+
VALUE geos_multi_line_string_class = rb_define_class_under(globals->geos_module, "MultiLineStringImpl", geos_geometry_collection_class);
globals->geos_multi_line_string = geos_multi_line_string_class;
globals->feature_multi_line_string = rb_const_get_at(globals->feature_module, rb_intern("MultiLineString"));
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ rb_const_get_at(globals->feature_module, rb_intern("MultiCurve")), geos_multi_line_string_class);
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ globals->feature_multi_line_string, geos_multi_line_string_class);
+
VALUE geos_multi_polygon_class = rb_define_class_under(globals->geos_module, "MultiPolygonImpl", geos_geometry_collection_class);
globals->geos_multi_polygon = geos_multi_polygon_class;
globals->feature_multi_polygon = rb_const_get_at(globals->feature_module, rb_intern("MultiPolygon"));
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ rb_const_get_at(globals->feature_module, rb_intern("MultiSurface")), geos_multi_polygon_class);
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ globals->feature_multi_polygon, geos_multi_polygon_class);
// Methods for GeometryCollectionImpl
rb_define_module_function(geos_geometry_collection_class, "create", cmethod_geometry_collection_create, 2);
@@ -447,12 +447,22 @@ void rgeo_init_geos_line_string(RGeo_Globals* globals)
VALUE geos_line_string_class = rb_define_class_under(globals->geos_module, "LineStringImpl", globals->geos_geometry);
globals->geos_line_string = geos_line_string_class;
globals->feature_line_string = rb_const_get_at(globals->feature_module, rb_intern("LineString"));
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ rb_const_get_at(globals->feature_module, rb_intern("Curve")), geos_line_string_class);
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ globals->feature_line_string, geos_line_string_class);
+
VALUE geos_linear_ring_class = rb_define_class_under(globals->geos_module, "LinearRingImpl", geos_line_string_class);
globals->geos_linear_ring = geos_linear_ring_class;
globals->feature_linear_ring = rb_const_get_at(globals->feature_module, rb_intern("LinearRing"));
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ globals->feature_linear_ring, geos_linear_ring_class);
+
VALUE geos_line_class = rb_define_class_under(globals->geos_module, "LineImpl", geos_line_string_class);
globals->geos_line = geos_line_class;
globals->feature_line = rb_const_get_at(globals->feature_module, rb_intern("Line"));
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ globals->feature_line, geos_line_class);
rb_define_module_function(geos_line_string_class, "create", cmethod_create_line_string, 2);
rb_define_module_function(geos_line_string_class, "_copy_from", cmethod_line_string_copy_from, 2);
View
@@ -154,6 +154,8 @@ void rgeo_init_geos_point(RGeo_Globals* globals)
VALUE geos_point_class = rb_define_class_under(globals->geos_module, "PointImpl", globals->geos_geometry);
globals->geos_point = geos_point_class;
globals->feature_point = rb_const_get_at(globals->feature_module, rb_intern("Point"));
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ globals->feature_point, geos_point_class);
rb_define_module_function(geos_point_class, "create", cmethod_create, 4);
@@ -223,6 +223,10 @@ void rgeo_init_geos_polygon(RGeo_Globals* globals)
VALUE geos_polygon_class = rb_define_class_under(globals->geos_module, "PolygonImpl", globals->geos_geometry);
globals->geos_polygon = geos_polygon_class;
globals->feature_polygon = rb_const_get_at(globals->feature_module, rb_intern("Polygon"));
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ rb_const_get_at(globals->feature_module, rb_intern("Surface")), geos_polygon_class);
+ rb_funcall(globals->global_mixins, rb_intern("include_in_class"), 2,
+ globals->feature_polygon, geos_polygon_class);
rb_define_module_function(geos_polygon_class, "create", cmethod_create, 3);
@@ -1,6 +1,6 @@
# -----------------------------------------------------------------------------
#
-# Spherical geography feature classes
+# Cartesian feature classes
#
# -----------------------------------------------------------------------------
# Copyright 2010 Daniel Azuma
@@ -46,19 +46,9 @@ class PointImpl # :nodoc:
include ::RGeo::ImplHelper::BasicGeometryMethods
include ::RGeo::ImplHelper::BasicPointMethods
include ::RGeo::Cartesian::GeometryMethods
+ include ::RGeo::Cartesian::PointMethods
-
- def distance(rhs_)
- rhs_ = ::RGeo::Feature.cast(rhs_, @factory)
- case rhs_
- when PointImpl
- dx_ = @x - rhs_.x
- dy_ = @y - rhs_.y
- ::Math.sqrt(dx_ * dx_ + dy_ * dy_)
- else
- super
- end
- end
+ Feature::MixinCollection::GLOBAL.for_type(Feature::Point).include_in_class(self, true)
end
@@ -73,6 +63,8 @@ class LineStringImpl # :nodoc:
include ::RGeo::Cartesian::GeometryMethods
include ::RGeo::Cartesian::LineStringMethods
+ Feature::MixinCollection::GLOBAL.for_type(Feature::LineString).include_in_class(self, true)
+
end
@@ -87,20 +79,24 @@ class LineImpl # :nodoc:
include ::RGeo::Cartesian::GeometryMethods
include ::RGeo::Cartesian::LineStringMethods
+ Feature::MixinCollection::GLOBAL.for_type(Feature::Line).include_in_class(self, true)
+
end
class LinearRingImpl # :nodoc:
- include ::RGeo::Feature::Line
+ include ::RGeo::Feature::LinearRing
include ::RGeo::ImplHelper::BasicGeometryMethods
include ::RGeo::ImplHelper::BasicLineStringMethods
include ::RGeo::ImplHelper::BasicLinearRingMethods
include ::RGeo::Cartesian::GeometryMethods
include ::RGeo::Cartesian::LineStringMethods
+ Feature::MixinCollection::GLOBAL.for_type(Feature::LinearRing).include_in_class(self, true)
+
end
@@ -113,6 +109,8 @@ class PolygonImpl # :nodoc:
include ::RGeo::ImplHelper::BasicPolygonMethods
include ::RGeo::Cartesian::GeometryMethods
+ Feature::MixinCollection::GLOBAL.for_type(Feature::Polygon).include_in_class(self, true)
+
end
@@ -125,45 +123,53 @@ class GeometryCollectionImpl # :nodoc:
include ::RGeo::ImplHelper::BasicGeometryCollectionMethods
include ::RGeo::Cartesian::GeometryMethods
+ Feature::MixinCollection::GLOBAL.for_type(Feature::GeometryCollection).include_in_class(self, true)
+
end
class MultiPointImpl # :nodoc:
- include ::RGeo::Feature::GeometryCollection
+ include ::RGeo::Feature::MultiPoint
include ::RGeo::ImplHelper::BasicGeometryMethods
include ::RGeo::ImplHelper::BasicGeometryCollectionMethods
include ::RGeo::ImplHelper::BasicMultiPointMethods
include ::RGeo::Cartesian::GeometryMethods
+ Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPoint).include_in_class(self, true)
+
end
class MultiLineStringImpl # :nodoc:
- include ::RGeo::Feature::GeometryCollection
+ include ::RGeo::Feature::MultiLineString
include ::RGeo::ImplHelper::BasicGeometryMethods
include ::RGeo::ImplHelper::BasicGeometryCollectionMethods
include ::RGeo::ImplHelper::BasicMultiLineStringMethods
include ::RGeo::Cartesian::GeometryMethods
+ Feature::MixinCollection::GLOBAL.for_type(Feature::MultiLineString).include_in_class(self, true)
+
end
class MultiPolygonImpl # :nodoc:
- include ::RGeo::Feature::GeometryCollection
+ include ::RGeo::Feature::MultiPolygon
include ::RGeo::ImplHelper::BasicGeometryMethods
include ::RGeo::ImplHelper::BasicGeometryCollectionMethods
include ::RGeo::ImplHelper::BasicMultiPolygonMethods
include ::RGeo::Cartesian::GeometryMethods
+ Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPolygon).include_in_class(self, true)
+
end
@@ -1,6 +1,6 @@
# -----------------------------------------------------------------------------
#
-# Spherical geometry common methods
+# Cartesian common methods
#
# -----------------------------------------------------------------------------
# Copyright 2010 Daniel Azuma
@@ -55,6 +55,25 @@ def envelope
end
+ module PointMethods # :nodoc:
+
+
+ def distance(rhs_)
+ rhs_ = ::RGeo::Feature.cast(rhs_, @factory)
+ case rhs_
+ when PointImpl
+ dx_ = @x - rhs_.x
+ dy_ = @y - rhs_.y
+ ::Math.sqrt(dx_ * dx_ + dy_ * dy_)
+ else
+ super
+ end
+ end
+
+
+ end
+
+
module LineStringMethods # :nodoc:
View
@@ -70,6 +70,7 @@ module Feature
# Implementation files
require 'rgeo/feature/factory'
+require 'rgeo/feature/mixins'
require 'rgeo/feature/types'
require 'rgeo/feature/geometry'
require 'rgeo/feature/point'
@@ -74,9 +74,8 @@ module Feature
module Curve
- extend Type
-
include Geometry
+ extend Type
# === SFS 1.1 Description
@@ -62,9 +62,9 @@ module Feature
module GeometryCollection
+ include Geometry
extend Type
- include Geometry
include ::Enumerable
View
@@ -53,9 +53,9 @@ module Feature
module Line
- extend Type
include LineString
+ extend Type
end
@@ -54,9 +54,8 @@ module Feature
module LineString
- extend Type
-
include Curve
+ extend Type
# === SFS 1.1 Description
@@ -53,9 +53,8 @@ module Feature
module LinearRing
- extend Type
-
include LineString
+ extend Type
end
Oops, something went wrong.

0 comments on commit e018ba9

Please sign in to comment.