-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start moving js methods to per-folder algs (#55)
- Loading branch information
1 parent
f117113
commit abd1774
Showing
15 changed files
with
186 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::array::*; | ||
use wasm_bindgen::prelude::*; | ||
|
||
macro_rules! impl_area { | ||
($struct_name:ident) => { | ||
#[wasm_bindgen] | ||
impl $struct_name { | ||
/// Unsigned planar area of a geometry. | ||
#[wasm_bindgen] | ||
pub fn area(&self) -> FloatArray { | ||
use geoarrow::algorithm::geo::Area; | ||
FloatArray(Area::unsigned_area(&self.0)) | ||
} | ||
|
||
/// Signed planar area of a geometry. | ||
#[wasm_bindgen] | ||
pub fn signed_area(&self) -> FloatArray { | ||
use geoarrow::algorithm::geo::Area; | ||
FloatArray(Area::signed_area(&self.0)) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_area!(PointArray); | ||
impl_area!(LineStringArray); | ||
impl_area!(PolygonArray); | ||
impl_area!(MultiPointArray); | ||
impl_area!(MultiLineStringArray); | ||
impl_area!(MultiPolygonArray); | ||
impl_area!(GeometryArray); |
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,27 @@ | ||
use crate::array::*; | ||
use wasm_bindgen::prelude::*; | ||
|
||
macro_rules! impl_center { | ||
($struct_name:ident) => { | ||
#[wasm_bindgen] | ||
impl $struct_name { | ||
/// Compute the center of geometries | ||
/// | ||
/// This first computes the axis-aligned bounding rectangle, then takes the center of | ||
/// that box | ||
#[wasm_bindgen] | ||
pub fn center(&self) -> PointArray { | ||
use geoarrow::algorithm::geo::Center; | ||
PointArray(Center::center(&self.0)) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_center!(PointArray); | ||
impl_center!(LineStringArray); | ||
impl_center!(PolygonArray); | ||
impl_center!(MultiPointArray); | ||
impl_center!(MultiLineStringArray); | ||
impl_center!(MultiPolygonArray); | ||
impl_center!(GeometryArray); |
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,29 @@ | ||
use crate::array::*; | ||
use wasm_bindgen::prelude::*; | ||
|
||
macro_rules! impl_centroid { | ||
($struct_name:ident) => { | ||
#[wasm_bindgen] | ||
impl $struct_name { | ||
/// Calculation of the centroid. | ||
/// The centroid is the arithmetic mean position of all points in the shape. | ||
/// Informally, it is the point at which a cutout of the shape could be perfectly | ||
/// balanced on the tip of a pin. | ||
/// The geometric centroid of a convex object always lies in the object. | ||
/// A non-convex object might have a centroid that _is outside the object itself_. | ||
#[wasm_bindgen] | ||
pub fn centroid(&self) -> PointArray { | ||
use geoarrow::algorithm::geo::Centroid; | ||
PointArray(Centroid::centroid(&self.0)) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_centroid!(PointArray); | ||
impl_centroid!(LineStringArray); | ||
impl_centroid!(PolygonArray); | ||
impl_centroid!(MultiPointArray); | ||
impl_centroid!(MultiLineStringArray); | ||
impl_centroid!(MultiPolygonArray); | ||
impl_centroid!(GeometryArray); |
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 @@ | ||
use crate::array::*; | ||
use wasm_bindgen::prelude::*; | ||
|
||
macro_rules! impl_alg { | ||
($struct_name:ident) => { | ||
#[wasm_bindgen] | ||
impl $struct_name { | ||
/// Calculate the unsigned approximate geodesic area of a `Geometry`. | ||
#[wasm_bindgen] | ||
pub fn chamberlain_duquette_unsigned_area(&self) -> FloatArray { | ||
use geoarrow::algorithm::geo::ChamberlainDuquetteArea; | ||
FloatArray(ChamberlainDuquetteArea::chamberlain_duquette_unsigned_area( | ||
&self.0, | ||
)) | ||
} | ||
|
||
/// Calculate the signed approximate geodesic area of a `Geometry`. | ||
#[wasm_bindgen] | ||
pub fn chamberlain_duquette_signed_area(&self) -> FloatArray { | ||
use geoarrow::algorithm::geo::ChamberlainDuquetteArea; | ||
FloatArray(ChamberlainDuquetteArea::chamberlain_duquette_signed_area( | ||
&self.0, | ||
)) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_alg!(PointArray); | ||
impl_alg!(LineStringArray); | ||
impl_alg!(PolygonArray); | ||
impl_alg!(MultiPointArray); | ||
impl_alg!(MultiLineStringArray); | ||
impl_alg!(MultiPolygonArray); | ||
impl_alg!(GeometryArray); |
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,30 @@ | ||
use crate::array::*; | ||
use wasm_bindgen::prelude::*; | ||
|
||
macro_rules! impl_alg { | ||
($struct_name:ident) => { | ||
#[wasm_bindgen] | ||
impl $struct_name { | ||
/// Returns the convex hull of a Polygon. The hull is always oriented | ||
/// counter-clockwise. | ||
/// | ||
/// This implementation uses the QuickHull algorithm, based on [Barber, C. Bradford; | ||
/// Dobkin, David P.; Huhdanpaa, Hannu (1 December | ||
/// 1996)](https://dx.doi.org/10.1145%2F235815.235821) Original paper here: | ||
/// <http://www.cs.princeton.edu/~dpd/Papers/BarberDobkinHuhdanpaa.pdf> | ||
#[wasm_bindgen] | ||
pub fn convex_hull(&self) -> PolygonArray { | ||
use geoarrow::algorithm::geo::ConvexHull; | ||
PolygonArray(ConvexHull::convex_hull(&self.0)) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_alg!(PointArray); | ||
impl_alg!(LineStringArray); | ||
impl_alg!(PolygonArray); | ||
impl_alg!(MultiPointArray); | ||
impl_alg!(MultiLineStringArray); | ||
impl_alg!(MultiPolygonArray); | ||
impl_alg!(GeometryArray); |
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,28 @@ | ||
use crate::array::*; | ||
use wasm_bindgen::prelude::*; | ||
|
||
macro_rules! impl_alg { | ||
($struct_name:ident) => { | ||
#[wasm_bindgen] | ||
impl $struct_name { | ||
/// Some geometries, like a `MultiPoint`, can have zero coordinates - we call these | ||
/// `empty`. | ||
/// | ||
/// Types like `Point`, which have at least one coordinate by construction, can never | ||
/// be considered empty. | ||
#[wasm_bindgen] | ||
pub fn is_empty(&self) -> BooleanArray { | ||
use geoarrow::algorithm::geo::HasDimensions; | ||
BooleanArray(HasDimensions::is_empty(&self.0)) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_alg!(PointArray); | ||
impl_alg!(LineStringArray); | ||
impl_alg!(PolygonArray); | ||
impl_alg!(MultiPointArray); | ||
impl_alg!(MultiLineStringArray); | ||
impl_alg!(MultiPolygonArray); | ||
impl_alg!(GeometryArray); |
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
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