Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a `RGeo::Geos::Analysis.ccw?` method which itself uses the GEOSCoordSeq_isCCW_r to determine if a geometry is counter-clockwise. This method is used by `RGeo::Cartesian::Analysis.ccw?` when possible, and there is a new `LinearRing#ccw?` method as well! This geos version is only valid for the geos capi, and libgeos must be 3.7+. Some refactoring was also done: Add an error.h header to help throwing errors when there is an issue in the c extension. And add a `RGeo::GeosError` for GEOS related errors. Change lots of `require` to `require_relative`. This helps a lot for local development and clarifies usage. Co-authored-by: Keith Doggett <keith.doggett887@gmail.com>
- Loading branch information
Showing
30 changed files
with
527 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
Analysis methos for GEOS wrapper | ||
*/ | ||
|
||
#include "preface.h" | ||
|
||
#ifdef RGEO_GEOS_SUPPORTED | ||
|
||
#include <ruby.h> | ||
#include <geos_c.h> | ||
|
||
#include "analysis.h" | ||
#include "factory.h" | ||
#include "errors.h" | ||
|
||
RGEO_BEGIN_C | ||
|
||
/* | ||
* call-seq: | ||
* RGeo::Geos::Analysis.ccw? -> true or false | ||
* | ||
* Checks direction for a ring, returns +true+ if counter-clockwise, +false+ | ||
* otherwise. | ||
*/ | ||
#ifdef RGEO_GEOS_SUPPORTS_ISCCW | ||
VALUE rgeo_geos_analysis_ccw_p(VALUE self, VALUE ring) | ||
{ | ||
|
||
const RGeo_GeometryData* ring_data; | ||
const GEOSCoordSequence* coord_seq; | ||
char is_ccw; | ||
|
||
rgeo_check_geos_object(ring); | ||
|
||
ring_data = RGEO_GEOMETRY_DATA_PTR(ring); | ||
|
||
coord_seq = GEOSGeom_getCoordSeq_r(ring_data->geos_context, ring_data->geom); | ||
if (!coord_seq) { rb_raise(geos_error, "Could not retrieve CoordSeq from given ring."); } | ||
if (!GEOSCoordSeq_isCCW_r(ring_data->geos_context, coord_seq, &is_ccw)) { | ||
rb_raise(geos_error, "Could not determine if the CoordSeq is CCW."); | ||
} | ||
|
||
return is_ccw ? Qtrue : Qfalse; | ||
}; | ||
#endif // RGEO_GEOS_SUPPORTS_ISCCW | ||
|
||
|
||
/** | ||
* call-seq: | ||
* RGeo::Geos::Analysis.ccw_supported? -> true or false | ||
* | ||
* Checks if the RGEO_GEOS_SUPPORTS_ISCCW macro is defined, returns +true+ | ||
* if it is, +false+ otherwise | ||
*/ | ||
VALUE rgeo_geos_analysis_supports_ccw(VALUE self) | ||
{ | ||
#ifdef RGEO_GEOS_SUPPORTS_ISCCW | ||
return Qtrue; | ||
#else | ||
return Qfalse; | ||
#endif | ||
} | ||
|
||
|
||
void rgeo_init_geos_analysis(RGeo_Globals* globals) | ||
{ | ||
VALUE geos_analysis_module; | ||
|
||
geos_analysis_module = rb_define_module_under(globals->geos_module, "Analysis"); | ||
rb_define_singleton_method(geos_analysis_module, "ccw_supported?", rgeo_geos_analysis_supports_ccw, 0); | ||
#ifdef RGEO_GEOS_SUPPORTS_ISCCW | ||
rb_define_singleton_method(geos_analysis_module, "ccw?", rgeo_geos_analysis_ccw_p, 1); | ||
#endif // RGEO_GEOS_SUPPORTS_ISCCW | ||
} | ||
|
||
RGEO_END_C | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Analysis methos for GEOS wrapper | ||
*/ | ||
|
||
#ifndef RGEO_GEOS_ANALYSIS_INCLUDED | ||
#define RGEO_GEOS_ANALYSIS_INCLUDED | ||
|
||
#include <ruby.h> | ||
|
||
#ifdef RGEO_GEOS_SUPPORTED | ||
|
||
#include "factory.h" | ||
|
||
RGEO_BEGIN_C | ||
|
||
/* | ||
* call-seq: | ||
* RGeo::Geos::Analysis.ccw? -> true or false | ||
* | ||
* Checks direction for a ring, returns +true+ if counter-clockwise, +false+ | ||
* otherwise. | ||
*/ | ||
#ifdef RGEO_GEOS_SUPPORTS_CCW | ||
VALUE rgeo_geos_analysis_ccw_p(VALUE self, VALUE ring); | ||
#endif // RGEO_GEOS_SUPPORTS_CCW | ||
|
||
/** | ||
* call-seq: | ||
* RGeo::Geos::Analysis.ccw_supported? -> true or false | ||
* | ||
* Checks if the RGEO_GEOS_SUPPORTS_ISCCW macro is defined, returns +true+ | ||
* if it is, +false+ otherwise | ||
*/ | ||
VALUE rgeo_geos_analysis_supports_ccw(VALUE self); | ||
|
||
void rgeo_init_geos_analysis(RGeo_Globals* globals); | ||
|
||
RGEO_END_C | ||
|
||
#endif // RGEO_GEOS_SUPPORTED | ||
|
||
#endif // RGEO_GEOS_ANALYSIS_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
#ifndef RGEO_GEOS_ERROS_INCLUDED | ||
#define RGEO_GEOS_ERROS_INCLUDED | ||
|
||
#include <ruby.h> | ||
|
||
#include "preface.h" | ||
|
||
#ifdef RGEO_GEOS_SUPPORTED | ||
|
||
#include "errors.h" | ||
|
||
RGEO_BEGIN_C | ||
|
||
// Any error relative to RGeo. | ||
VALUE rgeo_error; | ||
// RGeo error specific to the GEOS implementation. | ||
VALUE geos_error; | ||
|
||
|
||
void rgeo_init_geos_errors() { | ||
VALUE rgeo_module; | ||
VALUE error_module; | ||
|
||
rgeo_module = rb_define_module("RGeo"); | ||
error_module = rb_define_module_under(rgeo_module, "Error"); | ||
rgeo_error = rb_define_class_under(error_module, "RGeoError", rb_eRuntimeError); | ||
geos_error = rb_define_class_under(error_module, "GeosError", rgeo_error); | ||
} | ||
|
||
RGEO_END_C | ||
|
||
#endif // RGEO_GEOS_SUPPORTED | ||
|
||
#endif // RGEO_GEOS_ERROS_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
#ifndef RGEO_GEOS_ERROS_INCLUDED | ||
#define RGEO_GEOS_ERROS_INCLUDED | ||
|
||
#include <ruby.h> | ||
|
||
#ifdef RGEO_GEOS_SUPPORTED | ||
|
||
RGEO_BEGIN_C | ||
|
||
// Any error relative to RGeo. | ||
extern VALUE rgeo_error; | ||
// RGeo error specific to the GEOS implementation. | ||
extern VALUE geos_error; | ||
|
||
void rgeo_init_geos_errors(); | ||
|
||
RGEO_END_C | ||
|
||
#endif // RGEO_GEOS_SUPPORTED | ||
|
||
#endif // RGEO_GEOS_ERROS_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.