Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add len() and is_empty() to MultiPoint. #1109

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions geo-types/src/geometry/multi_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ use core::iter::FromIterator;
pub struct MultiPoint<T: CoordNum = f64>(pub Vec<Point<T>>);

impl<T: CoordNum, IP: Into<Point<T>>> From<IP> for MultiPoint<T> {
/// Convert a single `Point` (or something which can be converted to a `Point`) into a
/// one-member `MultiPoint`
/// Convert a single `Point` (or something which can be converted to a
/// `Point`) into a one-member `MultiPoint`
fn from(x: IP) -> Self {
Self(vec![x.into()])
}
}

impl<T: CoordNum, IP: Into<Point<T>>> From<Vec<IP>> for MultiPoint<T> {
/// Convert a `Vec` of `Points` (or `Vec` of things which can be converted to a `Point`) into a
/// `MultiPoint`.
/// Convert a `Vec` of `Points` (or `Vec` of things which can be converted
/// to a `Point`) into a `MultiPoint`.
fn from(v: Vec<IP>) -> Self {
Self(v.into_iter().map(|p| p.into()).collect())
}
Expand Down Expand Up @@ -90,6 +90,14 @@ impl<T: CoordNum> MultiPoint<T> {
Self(value)
}

pub fn len(&self) -> usize {
self.0.len()
}

pub fn is_empty(&self) -> bool {
self.0.is_empty()
}

pub fn iter(&self) -> impl Iterator<Item = &Point<T>> {
self.0.iter()
}
Expand Down