From 6520028cc7aa59913a2e44155d43e6d914b879ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Garc=C3=ADa=20Morillo?= Date: Fri, 18 Oct 2024 20:16:34 +0200 Subject: [PATCH] Improve usability of library by changing how the types are exported Also updated documentation & other minor improvements --- Cargo.toml | 2 +- README.md | 69 ++++++- examples/01_hello_world.rs | 42 ++--- examples/02_ais_read.rs | 3 +- examples/03_ais_assemble.rs | 15 +- examples/ais_full_assemble.rs | 20 +-- src/boxes/box.rs | 2 +- src/boxes/mod.rs | 10 +- src/boxes/stbox.rs | 5 +- src/boxes/tbox.rs | 11 +- src/collections/base/mod.rs | 13 +- src/collections/datetime/date_span.rs | 4 +- src/collections/datetime/date_span_set.rs | 16 +- src/collections/datetime/mod.rs | 15 +- src/collections/datetime/tstz_span.rs | 4 +- src/collections/datetime/tstz_span_set.rs | 6 +- src/collections/geo/mod.rs | 1 - src/collections/mod.rs | 1 - src/collections/number/float_span.rs | 5 +- src/collections/number/float_span_set.rs | 9 +- src/collections/number/int_span.rs | 5 +- src/collections/number/int_span_set.rs | 8 +- src/collections/number/mod.rs | 21 ++- src/collections/number/number_span.rs | 2 +- src/collections/number/number_span_set.rs | 2 +- src/lib.rs | 31 ++-- src/temporal/mod.rs | 41 +++-- src/temporal/number/tfloat.rs | 12 +- src/temporal/number/tint.rs | 12 +- src/temporal/number/tnumber.rs | 4 +- src/temporal/point/tgeogpoint.rs | 18 +- src/temporal/point/tgeompoint.rs | 18 +- src/temporal/point/tpoint.rs | 2 +- src/temporal/tbool.rs | 8 +- src/temporal/temporal.rs | 210 +++++++++------------- src/temporal/ttext.rs | 4 +- sys/README.md | 4 - 37 files changed, 330 insertions(+), 325 deletions(-) delete mode 100644 src/collections/geo/mod.rs diff --git a/Cargo.toml b/Cargo.toml index d09a79e..5249df1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "meos" -version = "0.1.3" +version = "0.2.0" license-file = "LICENSE" authors = ["David García Morillo "] repository = "https://github.com/MobilityDB/RustMEOS" diff --git a/README.md b/README.md index 070f569..381877c 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,44 @@ -# Rust MEOS +# RustMEOS -Rust bindings for [meos](https://libmeos.org/) C API. +RustMEOS is a Rust library providing bindings for the [MEOS](https://libmeos.org/) C library, designed for spatiotemporal data management and analysis. It enables handling of temporal and spatial data, making it ideal for applications that need to work with moving objects, trajectories, and time-varying geographical data. -The supported meos version is >= 1.2 +It supports MEOS version >= 1.2 -## Disclaimer +## Overview -The crate is still in alpha, this means it is not advised for production usage as some tests are still to be added. This project is checked with valgrind, but if you stumble on a crash feel free to open an issue explaining the problem. +The primary goal of this library is to facilitate the creation and manipulation of temporal types, such as time-stamped geographic points, sequences, and numeric values. These temporal data structures can be used for various use cases including: + +- **Tracking Movement:** Efficiently manage and analyze the movement of objects (e.g., vehicles, ships, animals) over time. +- **Spatiotemporal Queries:**: + - **Distance Calculations:** Compute the shortest distance between trajectories, which can be useful for determining when two moving objects were closest to each other. + - **Time-Weighted Averages:** Analyze time-dependent data, like averaging speeds or temperatures over a period. + - **Intersection Queries:** Check if a trajectory passes through specific points or regions, enabling location-based analysis of movement. + +This library provides access to advanced spatiotemporal data handling capabilities of MEOS while maintaining Rust’s memory safety, concurrency, and performance benefits. + +## Installation + +Add the following dependency to your `Cargo.toml`: + +```toml +[dependencies] +meos = "0.1" +``` +Ensure that the `meos` C library is installed on your system. Follow the installation instructions on the [MEOS website](https://github.com/MobilityDB/MobilityDB/?tab=readme-ov-file#requirements). + +## Key Features + +The library offers a range of temporal data types, including: + +- **Temporal Geometric Points (`TGeomPoint`):** These represent geometric points that change over time (e.g., location data of moving objects). +- **Temporal Float (`TFloat`):** These store numeric values associated with time, such as speed or temperature over time. +- **Temporal Boolean (`TBool`):** Represents true/false values that vary over time, useful for tracking binary states such as whether an object is within a specific area at given times. + +The type hierarchy is the following, the main types (`TGeomPoint`, `TFloat`, etc.) are enums that encapsulate the different kinds of temporal subtypes, **Instant**, **Sequence**, and **SequenceSet**, to learn more about these, refer to the [`meos` documentation](https://libmeos.org/documentation/datamodel/). Users can almost seamlessly use either the enums or the concrete structs (e.g. `TGeomPointSequence`). Some users may benefit from using the concrete structs since more concrete types can be inferred in some functions. ## Usage example -You can check the examples in the `examples/` directory. +You can check more examples in the `examples/` directory. ### Constructing trajectories from text: @@ -22,6 +50,35 @@ meos_initialize(); let trajectory: TGeomPoint = "[POINT(1 1)@2000-01-01 08:00, POINT(2 2)@2000-01-01 08:01]".parse().unwrap(); ``` +### Constructing trajectories from a list of pairs (point, timestamp): + +```rust + use chrono::{DateTime, TimeZone, Utc}; + use geos::Geometry; + use meos::{meos_initialize, TGeomPointSequence}; + + meos_initialize(); + + let geometries_with_time: Vec<(Geometry, DateTime)> = vec![ + ( + Geometry::new_from_wkt("POINT(1 1)").unwrap(), + Utc.with_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap(), + ), + ( + Geometry::new_from_wkt("POINT(3 2)").unwrap(), + Utc.with_ymd_and_hms(2020, 1, 1, 0, 1, 0).unwrap(), + ), + ( + Geometry::new_from_wkt("POINT(3 3)").unwrap(), + Utc.with_ymd_and_hms(2020, 1, 1, 0, 2, 0).unwrap(), + ), + ]; + + let tpoint: TGeomPointSequence = geometries_with_time.into_iter().collect(); + + println!("{tpoint:?}"); +``` + ### Get the shortest distance ever between two temporal points ```rust diff --git a/examples/01_hello_world.rs b/examples/01_hello_world.rs index 0b1fb5a..197e32d 100644 --- a/examples/01_hello_world.rs +++ b/examples/01_hello_world.rs @@ -35,7 +35,7 @@ fn main() { // Convert results to MF-JSON let instant_mfjson = - TGeomPoint::Instant(inst).as_mfjson(true, meos::temporal::JSONCVariant::Pretty, 6, "4326"); + TGeomPoint::Instant(inst).as_mfjson(true, meos::JSONCVariant::Pretty, 6, "4326"); println!( "\n\ --------------------\n\ @@ -48,12 +48,8 @@ fn main() { instant_wkt, instant_mfjson ); - let seq_disc_mfjson = TGeomPoint::Sequence(seq_disc).as_mfjson( - true, - meos::temporal::JSONCVariant::Pretty, - 6, - "4326", - ); + let seq_disc_mfjson = + TGeomPoint::Sequence(seq_disc).as_mfjson(true, meos::JSONCVariant::Pretty, 6, "4326"); println!( "\n\ -------------------------------------------------\n\ @@ -66,12 +62,8 @@ fn main() { sequence_discrete_wkt, seq_disc_mfjson ); - let seq_linear_mfjson = TGeomPoint::Sequence(seq_linear).as_mfjson( - true, - meos::temporal::JSONCVariant::Pretty, - 6, - "4326", - ); + let seq_linear_mfjson = + TGeomPoint::Sequence(seq_linear).as_mfjson(true, meos::JSONCVariant::Pretty, 6, "4326"); println!( "\n\ -----------------------------------------------\n\ @@ -84,12 +76,8 @@ fn main() { sequence_linear_wkt, seq_linear_mfjson ); - let seq_step_mfjson = TGeomPoint::Sequence(seq_step).as_mfjson( - true, - meos::temporal::JSONCVariant::Pretty, - 6, - "4326", - ); + let seq_step_mfjson = + TGeomPoint::Sequence(seq_step).as_mfjson(true, meos::JSONCVariant::Pretty, 6, "4326"); println!( "\n\ --------------------------------------------\n\ @@ -102,12 +90,8 @@ fn main() { sequence_step_wkt, seq_step_mfjson ); - let ss_linear_mfjson = TGeomPoint::SequenceSet(ss_linear).as_mfjson( - true, - meos::temporal::JSONCVariant::Pretty, - 6, - "4326", - ); + let ss_linear_mfjson = + TGeomPoint::SequenceSet(ss_linear).as_mfjson(true, meos::JSONCVariant::Pretty, 6, "4326"); println!( "\n\ ---------------------------------------------------\n\ @@ -120,12 +104,8 @@ fn main() { sequence_set_linear_wkt, ss_linear_mfjson ); - let ss_step_mfjson = TGeomPoint::SequenceSet(ss_step).as_mfjson( - true, - meos::temporal::JSONCVariant::Pretty, - 6, - "4326", - ); + let ss_step_mfjson = + TGeomPoint::SequenceSet(ss_step).as_mfjson(true, meos::JSONCVariant::Pretty, 6, "4326"); println!( "\n\ ------------------------------------------------\n\ diff --git a/examples/02_ais_read.rs b/examples/02_ais_read.rs index fbe15b7..51d70be 100644 --- a/examples/02_ais_read.rs +++ b/examples/02_ais_read.rs @@ -6,8 +6,7 @@ use std::{ use chrono::{DateTime, NaiveDateTime, Utc}; use meos::{ - meos_initialize, - temporal::{number::tfloat::TFloatInstant, point::tgeompoint::TGeomPoint}, + meos_initialize, {TFloatInstant, TGeomPoint}, }; const MAX_LENGTH_HEADER: usize = 1024; diff --git a/examples/03_ais_assemble.rs b/examples/03_ais_assemble.rs index 6bfa66c..8bd8676 100644 --- a/examples/03_ais_assemble.rs +++ b/examples/03_ais_assemble.rs @@ -7,19 +7,8 @@ use std::{ use chrono::{DateTime, NaiveDateTime, Utc}; use meos::{ - meos_initialize, - temporal::{ - number::{ - tfloat::{TFloatInstant, TFloatSequence}, - tnumber::TNumber, - }, - point::{ - tgeompoint::{TGeomPoint, TGeomPointInstant, TGeomPointSequence}, - tpoint::TPointTrait, - }, - temporal::Temporal, - tinstant::TInstant, - }, + meos_initialize, TFloatInstant, TFloatSequence, TGeomPoint, TGeomPointInstant, + TGeomPointSequence, TInstant as _, TNumber as _, TPointTrait as _, Temporal as _, }; const MAX_INSTANTS: usize = 50000; diff --git a/examples/ais_full_assemble.rs b/examples/ais_full_assemble.rs index 381d53d..81fc6bb 100644 --- a/examples/ais_full_assemble.rs +++ b/examples/ais_full_assemble.rs @@ -7,20 +7,8 @@ use std::{ use chrono::{DateTime, Utc}; use meos::{ - meos_initialize, - temporal::{ - number::{ - tfloat::{TFloatInstant, TFloatSequence}, - tnumber::TNumber, - }, - point::{ - tgeompoint::{TGeomPoint, TGeomPointInstant, TGeomPointSequence}, - tpoint::TPointTrait, - }, - temporal::Temporal, - tinstant::TInstant, - tsequence::TSequence, - }, + meos_initialize, TFloatInstant, TFloatSequence, TGeomPoint, TGeomPointInstant, + TGeomPointSequence, TInstant, TNumber, TPointTrait, TSequence, Temporal, }; // Constants @@ -153,11 +141,11 @@ fn main() { for trip in trips.iter_mut() { trip.trip = Some(TSequence::new( &trip.trip_instants.iter().collect::>(), - meos::temporal::interpolation::TInterpolation::Linear, + meos::TInterpolation::Linear, )); trip.sog = Some(TSequence::new( &trip.sog_instants.iter().collect::>(), - meos::temporal::interpolation::TInterpolation::Linear, + meos::TInterpolation::Linear, )); println!( diff --git a/src/boxes/box.rs b/src/boxes/box.rs index 853c816..b793909 100644 --- a/src/boxes/box.rs +++ b/src/boxes/box.rs @@ -1,7 +1,7 @@ use chrono::{DateTime, TimeDelta, TimeZone, Utc}; use crate::{ - collections::{base::collection::Collection, datetime::tstz_span::TsTzSpan}, + collections::{base::Collection, datetime::TsTzSpan}, WKBVariant, }; diff --git a/src/boxes/mod.rs b/src/boxes/mod.rs index 7bb300f..0cedb65 100644 --- a/src/boxes/mod.rs +++ b/src/boxes/mod.rs @@ -1,3 +1,7 @@ -pub mod r#box; -pub mod stbox; -pub mod tbox; +mod r#box; +mod stbox; +mod tbox; + +pub use r#box::Box; +pub use stbox::STBox; +pub use tbox::TBox; diff --git a/src/boxes/stbox.rs b/src/boxes/stbox.rs index a2eef7a..38ec885 100644 --- a/src/boxes/stbox.rs +++ b/src/boxes/stbox.rs @@ -12,10 +12,9 @@ use geos::{Geom, Geometry}; use crate::{ collections::{ base::{ - collection::{impl_collection, Collection}, - span::Span, + Span, {impl_collection, Collection}, }, - datetime::tstz_span::TsTzSpan, + datetime::TsTzSpan, }, errors::ParseError, utils::{create_interval, from_meos_timestamp, to_meos_timestamp}, diff --git a/src/boxes/tbox.rs b/src/boxes/tbox.rs index d65ccfe..f74564b 100644 --- a/src/boxes/tbox.rs +++ b/src/boxes/tbox.rs @@ -5,20 +5,19 @@ use std::{ ptr, }; -use crate::temporal::temporal::Temporal; +use crate::temporal::Temporal; use chrono::{DateTime, TimeDelta, TimeZone, Utc}; use crate::{ collections::{ base::{ - collection::{impl_collection, Collection}, - span::Span, + Span, {impl_collection, Collection}, }, - datetime::tstz_span::TsTzSpan, - number::{float_span::FloatSpan, int_span::IntSpan, number_span::NumberSpan}, + datetime::TsTzSpan, + number::{FloatSpan, IntSpan, NumberSpan}, }, errors::ParseError, - temporal::number::tfloat::TFloat, + temporal::TFloat, utils::{create_interval, from_meos_timestamp, to_meos_timestamp}, WKBVariant, }; diff --git a/src/collections/base/mod.rs b/src/collections/base/mod.rs index b71b701..ec0cb3a 100644 --- a/src/collections/base/mod.rs +++ b/src/collections/base/mod.rs @@ -1,3 +1,10 @@ -pub mod collection; -pub mod span; -pub mod span_set; +mod collection; +pub(crate) use collection::impl_collection; +pub use collection::Collection; + +mod span; +pub use span::Span; + +mod span_set; +pub(crate) use span_set::impl_iterator; +pub use span_set::SpanSet; diff --git a/src/collections/datetime/date_span.rs b/src/collections/datetime/date_span.rs index 6b92cd2..3cace46 100644 --- a/src/collections/datetime/date_span.rs +++ b/src/collections/datetime/date_span.rs @@ -8,8 +8,6 @@ use std::{ }; use chrono::{Datelike, NaiveDate, TimeDelta}; -use collection::{impl_collection, Collection}; -use span::Span; use crate::{ collections::{base::*, datetime::DAYS_UNTIL_2000}, @@ -37,7 +35,7 @@ impl Collection for DateSpan { } } -impl span::Span for DateSpan { +impl Span for DateSpan { type SubsetType = TimeDelta; fn inner(&self) -> *const meos_sys::Span { self._inner.as_ptr() diff --git a/src/collections/datetime/date_span_set.rs b/src/collections/datetime/date_span_set.rs index 75771af..1443b92 100644 --- a/src/collections/datetime/date_span_set.rs +++ b/src/collections/datetime/date_span_set.rs @@ -4,16 +4,14 @@ use std::ptr; use chrono::Datelike; use chrono::NaiveDate; use chrono::TimeDelta; -use collection::{impl_collection, Collection}; -use span::Span; -use span_set::impl_iterator; use std::fmt::Debug; use std::hash::Hash; use std::ops::{BitAnd, BitOr}; -use crate::collections::base::span_set::SpanSet; +use crate::collections::base::SpanSet; use crate::collections::base::*; use crate::errors::ParseError; +use crate::utils::from_interval; use super::date_span::DateSpan; use super::DAYS_UNTIL_2000; @@ -37,7 +35,7 @@ impl Collection for DateSpanSet { } } -impl span_set::SpanSet for DateSpanSet { +impl SpanSet for DateSpanSet { type SpanType = DateSpan; type SubsetType = TimeDelta; fn inner(&self) -> *const meos_sys::SpanSet { @@ -246,6 +244,14 @@ impl span_set::SpanSet for DateSpanSet { } } +impl DateSpanSet { + pub fn duration(&self, ignore_gaps: bool) -> TimeDelta { + from_interval(unsafe { + meos_sys::datespanset_duration(self._inner.as_ptr(), ignore_gaps).read() + }) + } +} + impl Clone for DateSpanSet { fn clone(&self) -> DateSpanSet { self.copy() diff --git a/src/collections/datetime/mod.rs b/src/collections/datetime/mod.rs index 8fba208..f6cc8dc 100644 --- a/src/collections/datetime/mod.rs +++ b/src/collections/datetime/mod.rs @@ -1,9 +1,16 @@ use chrono::Days; -pub mod date_span; -pub mod date_span_set; -pub mod tstz_span; -pub mod tstz_span_set; +mod date_span; +pub use date_span::DateSpan; + +mod date_span_set; +pub use date_span_set::DateSpanSet; + +mod tstz_span; +pub use tstz_span::TsTzSpan; + +mod tstz_span_set; +pub use tstz_span_set::TsTzSpanSet; /// Needed since MEOS uses as a baseline date 2000-01-01 pub(crate) const DAYS_UNTIL_2000: Days = Days::new(730_120); diff --git a/src/collections/datetime/tstz_span.rs b/src/collections/datetime/tstz_span.rs index 9de580c..7f910bf 100644 --- a/src/collections/datetime/tstz_span.rs +++ b/src/collections/datetime/tstz_span.rs @@ -8,8 +8,6 @@ use std::{ }; use chrono::{DateTime, Datelike, TimeDelta, TimeZone, Utc}; -use collection::{impl_collection, Collection}; -use span::Span; use crate::{ collections::base::*, @@ -38,7 +36,7 @@ impl Collection for TsTzSpan { } } -impl span::Span for TsTzSpan { +impl Span for TsTzSpan { type SubsetType = TimeDelta; fn inner(&self) -> *const meos_sys::Span { self._inner.as_ptr() diff --git a/src/collections/datetime/tstz_span_set.rs b/src/collections/datetime/tstz_span_set.rs index 7c4608a..7638328 100644 --- a/src/collections/datetime/tstz_span_set.rs +++ b/src/collections/datetime/tstz_span_set.rs @@ -5,14 +5,10 @@ use chrono::DateTime; use chrono::Datelike; use chrono::TimeDelta; use chrono::Utc; -use collection::{impl_collection, Collection}; -use span::Span; -use span_set::impl_iterator; use std::fmt::Debug; use std::hash::Hash; use std::ops::{BitAnd, BitOr}; -use crate::collections::base::span_set::SpanSet; use crate::collections::base::*; use crate::errors::ParseError; use crate::utils::to_meos_timestamp; @@ -39,7 +35,7 @@ impl Collection for TsTzSpanSet { } } -impl span_set::SpanSet for TsTzSpanSet { +impl SpanSet for TsTzSpanSet { type SpanType = TsTzSpan; type SubsetType = TimeDelta; fn inner(&self) -> *const meos_sys::SpanSet { diff --git a/src/collections/geo/mod.rs b/src/collections/geo/mod.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/collections/geo/mod.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/collections/mod.rs b/src/collections/mod.rs index 3192859..17fef62 100644 --- a/src/collections/mod.rs +++ b/src/collections/mod.rs @@ -1,4 +1,3 @@ pub mod base; pub mod datetime; -pub mod geo; pub mod number; diff --git a/src/collections/number/float_span.rs b/src/collections/number/float_span.rs index 2da3638..2c66aba 100644 --- a/src/collections/number/float_span.rs +++ b/src/collections/number/float_span.rs @@ -7,9 +7,6 @@ use std::{ ptr, }; -use collection::{impl_collection, Collection}; -use span::Span; - use crate::{collections::base::*, errors::ParseError}; use super::number_span::NumberSpan; @@ -33,7 +30,7 @@ impl Collection for FloatSpan { } } -impl span::Span for FloatSpan { +impl Span for FloatSpan { type SubsetType = Self::Type; fn inner(&self) -> *const meos_sys::Span { self._inner.as_ptr() diff --git a/src/collections/number/float_span_set.rs b/src/collections/number/float_span_set.rs index 79e75a0..46667de 100644 --- a/src/collections/number/float_span_set.rs +++ b/src/collections/number/float_span_set.rs @@ -5,11 +5,8 @@ use std::hash::Hash; use std::ops::{BitAnd, BitOr}; use std::ptr; -use collection::{impl_collection, Collection}; -use span_set::impl_iterator; - -use crate::collections::base::span::Span; -use crate::collections::base::span_set::SpanSet; +use crate::collections::base::Span; +use crate::collections::base::SpanSet; use crate::collections::base::*; use crate::errors::ParseError; @@ -36,7 +33,7 @@ impl Collection for FloatSpanSet { } } -impl span_set::SpanSet for FloatSpanSet { +impl SpanSet for FloatSpanSet { type SpanType = FloatSpan; type SubsetType = ::Type; fn inner(&self) -> *const meos_sys::SpanSet { diff --git a/src/collections/number/int_span.rs b/src/collections/number/int_span.rs index a320151..2905108 100644 --- a/src/collections/number/int_span.rs +++ b/src/collections/number/int_span.rs @@ -7,9 +7,6 @@ use std::{ ptr, }; -use collection::{impl_collection, Collection}; -use span::Span; - use crate::{collections::base::*, errors::ParseError}; use super::number_span::NumberSpan; @@ -33,7 +30,7 @@ impl Collection for IntSpan { } } -impl span::Span for IntSpan { +impl Span for IntSpan { type SubsetType = Self::Type; fn inner(&self) -> *const meos_sys::Span { self._inner.as_ptr() diff --git a/src/collections/number/int_span_set.rs b/src/collections/number/int_span_set.rs index 1d91185..658508e 100644 --- a/src/collections/number/int_span_set.rs +++ b/src/collections/number/int_span_set.rs @@ -5,11 +5,7 @@ use std::hash::Hash; use std::ops::{BitAnd, BitOr}; use std::ptr; -use collection::{impl_collection, Collection}; -use span::Span; -use span_set::impl_iterator; - -use crate::collections::base::span_set::SpanSet; +use crate::collections::base::SpanSet; use crate::collections::base::*; use crate::errors::ParseError; @@ -35,7 +31,7 @@ impl Collection for IntSpanSet { } } -impl span_set::SpanSet for IntSpanSet { +impl SpanSet for IntSpanSet { type SpanType = IntSpan; type SubsetType = ::Type; fn inner(&self) -> *const meos_sys::SpanSet { diff --git a/src/collections/number/mod.rs b/src/collections/number/mod.rs index 6657133..4e0d419 100644 --- a/src/collections/number/mod.rs +++ b/src/collections/number/mod.rs @@ -1,8 +1,17 @@ -pub mod number_span; -pub mod number_span_set; +mod number_span; +pub use number_span::NumberSpan; -pub mod float_span; -pub mod float_span_set; +mod number_span_set; +pub use number_span_set::NumberSpanSet; -pub mod int_span; -pub mod int_span_set; +mod float_span; +pub use float_span::FloatSpan; + +mod float_span_set; +pub use float_span_set::FloatSpanSet; + +mod int_span; +pub use int_span::IntSpan; + +mod int_span_set; +pub use int_span_set::IntSpanSet; diff --git a/src/collections/number/number_span.rs b/src/collections/number/number_span.rs index cab0c55..ee78caf 100644 --- a/src/collections/number/number_span.rs +++ b/src/collections/number/number_span.rs @@ -1,4 +1,4 @@ -use crate::collections::base::span::Span; +use crate::collections::base::Span; /// You shouldn't probably implement this trait yourself, it's just to run some functions in both IntSpan and FloatSpan pub trait NumberSpan: Span {} diff --git a/src/collections/number/number_span_set.rs b/src/collections/number/number_span_set.rs index 541e0c0..451d79a 100644 --- a/src/collections/number/number_span_set.rs +++ b/src/collections/number/number_span_set.rs @@ -1,4 +1,4 @@ -use crate::collections::base::span_set::SpanSet; +use crate::collections::base::SpanSet; /// You shouldn't probably implement this trait yourself, it's just to run some functions in both IntSpanSet and FloatSpanSet pub trait NumberSpanSet: SpanSet {} diff --git a/src/lib.rs b/src/lib.rs index 54ea5b9..54a5a9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,10 @@ +#![crate_name = "meos"] +#![crate_type = "lib"] +#![cfg_attr(doc, doc = include_str!("../README.md"))] +#![doc(html_logo_url = "https://libmeos.org/brand.svg")] #![allow(refining_impl_trait)] #![allow(clippy::non_canonical_partial_ord_impl)] + use std::{ ffi::{c_void, CStr, CString}, fmt::Debug, @@ -7,26 +12,22 @@ use std::{ }; use bitmask_enum::bitmask; -use boxes::r#box::Box as MeosBox; -pub use meos_sys; +use boxes::Box as MeosBox; +pub use meos_sys as sys; -pub mod boxes; -pub use boxes::{stbox::STBox, tbox::TBox}; +mod boxes; +pub use boxes::{STBox, TBox}; -pub mod collections; -pub use collections::base::{collection::Collection, span::Span, span_set::SpanSet}; +mod collections; +pub use collections::base::{Collection, Span, SpanSet}; +pub use collections::datetime::{DateSpan, DateSpanSet, TsTzSpan, TsTzSpanSet}; +pub use collections::number::*; -pub mod errors; +mod errors; pub use errors::ParseError; -pub mod temporal; -pub use temporal::{ - interpolation::TInterpolation, - number::{tfloat::*, tint::*}, - point::{tgeogpoint::*, tgeompoint::*, tpoint::TPointTrait}, - temporal::Temporal, - JSONCVariant, -}; +mod temporal; +pub use temporal::*; pub(crate) mod utils; diff --git a/src/temporal/mod.rs b/src/temporal/mod.rs index ff16fb9..aec52c8 100644 --- a/src/temporal/mod.rs +++ b/src/temporal/mod.rs @@ -1,16 +1,37 @@ -pub mod interpolation; -pub mod number; +mod interpolation; +pub use interpolation::TInterpolation; + +mod number; +pub use number::tfloat::*; +pub use number::tint::*; +pub use number::tnumber::TNumber; + #[cfg(feature = "geos")] -pub mod point; -pub mod tbool; +mod point; +pub use point::tgeogpoint::*; +pub use point::tgeompoint::*; +pub use point::tpoint::*; + +mod tbool; +pub use tbool::*; + #[allow(clippy::module_inception)] -pub mod temporal; -pub mod tinstant; -pub mod tsequence; -pub mod tsequence_set; -pub mod ttext; +mod temporal; +pub use temporal::{OrderedTemporal, SimplifiableTemporal, Temporal}; + +mod tinstant; +pub use tinstant::TInstant; + +mod tsequence; +pub use tsequence::TSequence; + +mod tsequence_set; +pub use tsequence_set::TSequenceSet; + +mod ttext; +pub use ttext::*; -/// Taken from https://json-c.github.io/json-c/json-c-0.10/doc/html/json__object_8h.html#a3294cb92765cdeb497cfd346644d1059 +/// Taken from pub enum JSONCVariant { Plain, Spaced, diff --git a/src/temporal/number/tfloat.rs b/src/temporal/number/tfloat.rs index bf9ba9a..6fde481 100644 --- a/src/temporal/number/tfloat.rs +++ b/src/temporal/number/tfloat.rs @@ -10,15 +10,11 @@ use chrono::{DateTime, TimeZone}; use super::tnumber::{impl_meos_enum, impl_temporal_for_tnumber, TNumber}; use crate::{ - boxes::tbox::TBox, + boxes::TBox, collections::{ - base::{ - collection::{impl_collection, Collection}, - span::Span, - span_set::SpanSet, - }, - datetime::{tstz_span::TsTzSpan, tstz_span_set::TsTzSpanSet}, - number::float_span_set::FloatSpanSet, + base::*, + datetime::{TsTzSpan, TsTzSpanSet}, + number::FloatSpanSet, }, errors::ParseError, factory, impl_from_str, diff --git a/src/temporal/number/tint.rs b/src/temporal/number/tint.rs index 23586ea..dc7cfa0 100644 --- a/src/temporal/number/tint.rs +++ b/src/temporal/number/tint.rs @@ -9,15 +9,11 @@ use std::{ use chrono::{DateTime, TimeZone}; use crate::{ - boxes::tbox::TBox, + boxes::TBox, collections::{ - base::{ - collection::{impl_collection, Collection}, - span::Span, - span_set::SpanSet, - }, - datetime::{tstz_span::TsTzSpan, tstz_span_set::TsTzSpanSet}, - number::int_span_set::IntSpanSet, + base::*, + datetime::{TsTzSpan, TsTzSpanSet}, + number::IntSpanSet, }, errors::ParseError, factory, impl_from_str, diff --git a/src/temporal/number/tnumber.rs b/src/temporal/number/tnumber.rs index 3015b24..75ea462 100644 --- a/src/temporal/number/tnumber.rs +++ b/src/temporal/number/tnumber.rs @@ -1,6 +1,6 @@ use crate::{ - boxes::tbox::TBox, - collections::number::{number_span::NumberSpan, number_span_set::NumberSpanSet}, + boxes::TBox, + collections::number::{NumberSpan, NumberSpanSet}, temporal::temporal::Temporal, }; diff --git a/src/temporal/point/tgeogpoint.rs b/src/temporal/point/tgeogpoint.rs index eda314e..330d0a8 100644 --- a/src/temporal/point/tgeogpoint.rs +++ b/src/temporal/point/tgeogpoint.rs @@ -11,8 +11,8 @@ use std::{ use crate::temporal::tsequence_set::TSequenceSet; use crate::{ - boxes::stbox::STBox, - collections::base::collection::{impl_collection, Collection}, + boxes::STBox, + collections::base::{impl_collection, Collection}, errors::ParseError, factory, temporal::{ @@ -60,6 +60,12 @@ impl TInstant for TGeogPointInstant { } } +impl From<(Geometry, DateTime)> for TGeogPointInstant { + fn from((value, timestamp): (Geometry, DateTime)) -> Self { + Self::from_value_and_timestamp(value, timestamp) + } +} + impl TPointTrait for TGeogPointInstant {} pub struct TGeogPointSequence { @@ -174,6 +180,14 @@ impl<'a> FromIterator<&'a TGeogPointInstant> for TGeogPointSequence { } } +impl FromIterator<(Geometry, DateTime)> for TGeogPointSequence { + fn from_iter)>>(iter: T) -> Self { + iter.into_iter() + .map(Into::::into) + .collect() + } +} + impl Collection for TGeogPoint { impl_collection!(tpoint, Geometry); fn contains(&self, element: &Self::Type) -> bool { diff --git a/src/temporal/point/tgeompoint.rs b/src/temporal/point/tgeompoint.rs index 5d0242f..f4ba290 100644 --- a/src/temporal/point/tgeompoint.rs +++ b/src/temporal/point/tgeompoint.rs @@ -11,8 +11,8 @@ use std::{ use crate::temporal::tsequence_set::TSequenceSet; use crate::{ - boxes::stbox::STBox, - collections::base::collection::{impl_collection, Collection}, + boxes::STBox, + collections::base::{impl_collection, Collection}, errors::ParseError, factory, temporal::{ @@ -60,6 +60,12 @@ impl TInstant for TGeomPointInstant { } } +impl From<(Geometry, DateTime)> for TGeomPointInstant { + fn from((value, timestamp): (Geometry, DateTime)) -> Self { + Self::from_value_and_timestamp(value, timestamp) + } +} + impl TPointTrait for TGeomPointInstant {} pub struct TGeomPointSequence { @@ -174,6 +180,14 @@ impl<'a> FromIterator<&'a TGeomPointInstant> for TGeomPointSequence { } } +impl FromIterator<(Geometry, DateTime)> for TGeomPointSequence { + fn from_iter)>>(iter: T) -> Self { + iter.into_iter() + .map(Into::::into) + .collect() + } +} + impl Collection for TGeomPoint { impl_collection!(tpoint, Geometry); fn contains(&self, element: &Self::Type) -> bool { diff --git a/src/temporal/point/tpoint.rs b/src/temporal/point/tpoint.rs index b18c123..f1f3a29 100644 --- a/src/temporal/point/tpoint.rs +++ b/src/temporal/point/tpoint.rs @@ -1,7 +1,7 @@ use crate::temporal::tinstant::TInstant; use crate::temporal::JSONCVariant; use crate::{ - boxes::stbox::STBox, + boxes::STBox, factory, temporal::{number::tfloat::TFloat, temporal::Temporal}, }; diff --git a/src/temporal/tbool.rs b/src/temporal/tbool.rs index 1afe9fc..45b63dc 100644 --- a/src/temporal/tbool.rs +++ b/src/temporal/tbool.rs @@ -11,12 +11,8 @@ use chrono::{DateTime, TimeZone}; use crate::{ collections::{ - base::{ - collection::{impl_collection, Collection}, - span::Span, - span_set::SpanSet, - }, - datetime::{tstz_span::TsTzSpan, tstz_span_set::TsTzSpanSet}, + base::*, + datetime::{TsTzSpan, TsTzSpanSet}, }, errors::ParseError, factory, impl_from_str, diff --git a/src/temporal/temporal.rs b/src/temporal/temporal.rs index 7a346a9..defa0d2 100644 --- a/src/temporal/temporal.rs +++ b/src/temporal/temporal.rs @@ -6,8 +6,8 @@ use std::{ use crate::{ collections::{ - base::{collection::Collection, span::Span, span_set::SpanSet}, - datetime::{tstz_span::TsTzSpan, tstz_span_set::TsTzSpanSet}, + base::*, + datetime::{TsTzSpan, TsTzSpanSet}, }, factory, utils::{create_interval, from_interval, from_meos_timestamp, to_meos_timestamp}, @@ -84,6 +84,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// The time span. + #[doc(alias = "temporal_time")] fn time(&self) -> TsTzSpanSet { TsTzSpanSet::from_inner(unsafe { meos_sys::temporal_time(self.inner()) }) } @@ -92,6 +93,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// The time span. + #[doc(alias = "temporal_to_tstzspan")] fn timespan(&self) -> TsTzSpan { unsafe { TsTzSpan::from_inner(meos_sys::temporal_to_tstzspan(self.inner())) } } @@ -103,6 +105,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// The duration of the temporal object. + #[doc(alias = "temporal_duration")] fn duration(&self, ignore_gaps: bool) -> TimeDelta { from_interval(unsafe { meos_sys::temporal_duration(self.inner(), ignore_gaps).read() }) } @@ -111,6 +114,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// The number of instants. + #[doc(alias = "temporal_num_instants")] fn num_instants(&self) -> i32 { unsafe { meos_sys::temporal_num_instants(self.inner()) } } @@ -119,6 +123,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// The first instant. + #[doc(alias = "temporal_start_instant")] fn start_instant(&self) -> Self::TI { ::from_inner(unsafe { meos_sys::temporal_start_instant(self.inner()) @@ -129,6 +134,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// The last instant. + #[doc(alias = "temporal_end_instant")] fn end_instant(&self) -> Self::TI { ::from_inner(unsafe { meos_sys::temporal_end_instant(self.inner()) }) } @@ -137,6 +143,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// The instant with the minimum value. + #[doc(alias = "temporal_min_instant")] fn min_instant(&self) -> Self::TI { ::from_inner(unsafe { meos_sys::temporal_min_instant(self.inner()) }) } @@ -145,6 +152,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// The instant with the maximum value. + #[doc(alias = "temporal_max_instant")] fn max_instant(&self) -> Self::TI { ::from_inner(unsafe { meos_sys::temporal_max_instant(self.inner()) }) } @@ -156,6 +164,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Return /// The n-th instant if exists, None otherwise. + #[doc(alias = "temporal_instant_n")] fn instant_n(&self, n: i32) -> Option { let result = unsafe { meos_sys::temporal_instant_n(self.inner(), n) }; if !result.is_null() { @@ -169,6 +178,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// A list of instants. + #[doc(alias = "temporal_instants")] fn instants(&self) -> Vec { let mut count = 0; unsafe { @@ -185,6 +195,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// The number of timestamps. + #[doc(alias = "temporal_num_timestamps")] fn num_timestamps(&self) -> i32 { unsafe { meos_sys::temporal_num_timestamps(self.inner()) } } @@ -193,6 +204,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// The first timestamp. + #[doc(alias = "temporal_start_timestampz")] fn start_timestamp(&self) -> DateTime { from_meos_timestamp(unsafe { meos_sys::temporal_start_timestamptz(self.inner()) }) } @@ -201,6 +213,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// The last timestamp. + #[doc(alias = "temporal_end_timestampz")] fn end_timestamp(&self) -> DateTime { from_meos_timestamp(unsafe { meos_sys::temporal_end_timestamptz(self.inner()) }) } @@ -212,6 +225,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// The n-th timestamp if exists, None otherwise. + #[doc(alias = "temporal_timestampz_n")] fn timestamp_n(&self, n: i32) -> Option> { let mut timestamp = 0; unsafe { @@ -229,6 +243,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// A list of timestamps. + #[doc(alias = "temporal_timestamps")] fn timestamps(&self) -> Vec> { let mut count = 0; let timestamps = @@ -245,9 +260,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// A list of segments. - /// - /// MEOS Functions: - /// `temporal_segments` + #[doc(alias = "temporal_segments")] fn segments(&self) -> Vec { let mut count = 0; let segments = @@ -263,9 +276,7 @@ pub trait Temporal: Collection + Hash { // ------------------------- Transformations ------------------------------- /// Returns a new `Temporal` object with the given interpolation. - /// - /// MEOS Functions: - /// `temporal_set_interpolation` + #[doc(alias = "temporal_set_interp")] fn set_interpolation(&self, interpolation: TInterpolation) -> Self { Self::from_inner_as_temporal(unsafe { meos_sys::temporal_set_interp(self.inner(), interpolation as u32) @@ -276,9 +287,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Arguments /// * `delta` - TimeDelta to shift the temporal dimension. - /// - /// MEOS Functions: - /// `temporal_shift_time` + #[doc(alias = "temporal_shift_scale_time")] fn shift_time(&self, delta: TimeDelta) -> Self { self.shift_scale_time(Some(delta), None) } @@ -287,9 +296,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Arguments /// * `duration` - TimeDelta representing the new temporal duration. - /// - /// MEOS Functions: - /// `temporal_scale_time` + #[doc(alias = "temporal_shift_scale_time")] fn scale_time(&self, duration: TimeDelta) -> Self { self.shift_scale_time(None, Some(duration)) } @@ -299,9 +306,7 @@ pub trait Temporal: Collection + Hash { /// ## Arguments /// * `shift` - TimeDelta to shift the time dimension. /// * `duration` - TimeDelta representing the new temporal duration. - /// - /// MEOS Functions: - /// `temporal_shift_scale_time` + #[doc(alias = "temporal_shift_scale_time")] fn shift_scale_time(&self, shift: Option, duration: Option) -> Self { let d = { if let Some(d) = shift { @@ -329,9 +334,7 @@ pub trait Temporal: Collection + Hash { /// * `duration` - TimeDelta of the temporal tiles. /// * `start` - Start time of the temporal tiles. /// * `interpolation`- Interpolation of the resulting temporal object. - /// - /// MEOS Functions: - /// `temporal_tsample` + #[doc(alias = "temporal_tsample")] fn temporal_sample( self, duration: TimeDelta, @@ -354,9 +357,7 @@ pub trait Temporal: Collection + Hash { /// ## Arguments /// * `duration` - TimeDelta of the temporal tiles. /// * `start` - Start time of the temporal tiles. - /// - /// MEOS Functions: - /// `temporal_tprecision` + #[doc(alias = "temporal_tprecision")] fn temporal_precision(self, duration: TimeDelta, start: DateTime) -> Self { let interval = create_interval(duration); Self::from_inner_as_temporal(unsafe { @@ -369,9 +370,7 @@ pub trait Temporal: Collection + Hash { } /// Converts `self` into a `TInstant`. - /// - /// MEOS Functions: - /// `temporal_to_tinstant` + #[doc(alias = "temporal_to_instant")] fn to_instant(&self) -> Self::TI { TInstant::from_inner(unsafe { meos_sys::temporal_to_tinstant(self.inner()) }) } @@ -380,9 +379,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Arguments /// * `interpolation` - The interpolation type for the sequence. - /// - /// MEOS Functions: - /// `temporal_to_sequence` + #[doc(alias = "temporal_to_tsequence")] fn to_sequence(&self, interpolation: TInterpolation) -> Self::TS { let c_str = CString::new(interpolation.to_string()).unwrap(); TSequence::from_inner(unsafe { @@ -394,9 +391,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Arguments /// * `interpolation` - The interpolation type for the sequence set. - /// - /// MEOS Functions: - /// `temporal_to_tsequenceset` + #[doc(alias = "temporal_to_tsequenceset")] fn to_sequence_set(&self, interpolation: TInterpolation) -> Self::TSS { let c_str = CString::new(interpolation.to_string()).unwrap(); TSequenceSet::from_inner(unsafe { @@ -412,9 +407,7 @@ pub trait Temporal: Collection + Hash { /// * `instant` - Instant to append. /// * `max_dist` - Maximum distance for defining a gap. /// * `max_time` - Maximum time for defining a gap. - /// - /// MEOS Functions: - /// `temporal_append_tinstant` + #[doc(alias = "temporal_append_tinstant")] fn append_instant( self, instant: Self::TI, @@ -442,9 +435,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Arguments /// * `sequence` - Sequence to append. - /// - /// MEOS Functions: - /// `temporal_append_tsequence` + #[doc(alias = "temporal_append_tsequence")] fn append_sequence(&self, sequence: Self::TS) -> Self::Enum { factory::(unsafe { meos_sys::temporal_append_tsequence( @@ -459,9 +450,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Arguments /// * `other` - Another temporal object - /// - /// MEOS Functions: - /// `temporal_merge` + #[doc(alias = "temporal_merge")] fn merge_other(&self, other: Self::Enum) -> Self::Enum { factory::(unsafe { meos_sys::temporal_merge(self.inner(), other.inner()) }) } @@ -471,9 +460,7 @@ pub trait Temporal: Collection + Hash { /// ## Arguments /// * `other` - Temporal object to insert. /// * `connect` - Whether to connect inserted elements with existing ones. - /// - /// MEOS Functions: - /// `temporal_insert` + #[doc(alias = "temporal_insert")] fn insert(&self, other: Self::Enum, connect: bool) -> Self::Enum { factory::(unsafe { meos_sys::temporal_insert(self.inner(), other.inner(), connect) @@ -485,9 +472,7 @@ pub trait Temporal: Collection + Hash { /// ## Arguments /// * `other` - Temporal object to update with. /// * `connect` - Whether to connect updated elements with existing ones. - /// - /// MEOS Functions: - /// `temporal_update` + #[doc(alias = "temporal_update")] fn update(&self, other: Self::Enum, connect: bool) -> Self::Enum { factory::(unsafe { meos_sys::temporal_update(self.inner(), other.inner(), connect) @@ -499,9 +484,7 @@ pub trait Temporal: Collection + Hash { /// ## Arguments /// * `other` - Time object specifying the elements to delete. /// * `connect` - Whether to connect the potential gaps generated by the deletions. - /// - /// MEOS Functions: - /// `temporal_delete` + #[doc(alias = "temporal_delete_timestamptz")] fn delete_at_timestamp(&self, other: DateTime, connect: bool) -> Self::Enum { factory::(unsafe { meos_sys::temporal_delete_timestamptz(self.inner(), to_meos_timestamp(&other), connect) @@ -513,6 +496,7 @@ pub trait Temporal: Collection + Hash { /// ## Arguments /// * `time_span` - Time span object specifying the elements to delete. /// * `connect` - Whether to connect the potential gaps generated by the deletions. + #[doc(alias = "temporal_delete_tstzspan")] fn delete_at_tstz_span(&self, time_span: TsTzSpan, connect: bool) -> Self::Enum { factory::(unsafe { meos_sys::temporal_delete_tstzspan(self.inner(), time_span.inner(), connect) @@ -524,6 +508,7 @@ pub trait Temporal: Collection + Hash { /// ## Arguments /// * `time_span_set` - Time span set object specifying the elements to delete. /// * `connect` - Whether to connect the potential gaps generated by the deletions. + #[doc(alias = "temporal_delete_tstzspanset")] fn delete_at_tstz_span_set(&self, time_span_set: TsTzSpanSet, connect: bool) -> Self::Enum { factory::(unsafe { meos_sys::temporal_delete_tstzspanset(self.inner(), time_span_set.inner(), connect) @@ -536,9 +521,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Arguments /// * `other` - A timestamp to restrict the values to. - /// - /// MEOS Functions: - /// `temporal_at_temporal_at_timestamptz` + #[doc(alias = "temporal_at_timestamptz")] fn at_timestamp(&self, other: DateTime) -> Self::TI { ::from_inner_as_temporal(unsafe { meos_sys::temporal_at_timestamptz(self.inner(), to_meos_timestamp(&other)) @@ -549,9 +532,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Arguments /// * `time_span` - A time span to restrict the values to. - /// - /// MEOS Functions: - /// `temporal_at_tstzspan` + #[doc(alias = "temporal_at_tstzspan")] fn at_tstz_span(&self, time_span: TsTzSpan) -> Self { Self::from_inner_as_temporal(unsafe { meos_sys::temporal_at_tstzspan(self.inner(), time_span.inner()) @@ -562,9 +543,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Arguments /// * `time_span_set` - A time span set to restrict the values to. - /// - /// MEOS Functions: - /// `temporal_at_tstzspanset` + #[doc(alias = "temporal_at_tstzspanset")] fn at_tstz_span_set(&self, time_span_set: TsTzSpanSet) -> Self { Self::from_inner_as_temporal(unsafe { meos_sys::temporal_at_tstzspanset(self.inner(), time_span_set.inner()) @@ -572,24 +551,16 @@ pub trait Temporal: Collection + Hash { } /// Returns a new temporal object containing the times `self` is at `value`. - /// - /// MEOS Functions: - /// `temporal_at_value` fn at_value(&self, value: &Self::Type) -> Option; /// Returns a new temporal object containing the times `self` is in any of the values of `values`. - /// - /// MEOS Functions: - /// `temporal_at_values` fn at_values(&self, values: &[Self::Type]) -> Option; /// Returns a new temporal object with values at `timestamp` removed. /// /// ## Arguments /// * `timestamp` - A timestamp specifying the values to remove. - /// - /// MEOS Functions: - /// `temporal_minus_*` + #[doc(alias = "temporal_minus_timestampz")] fn minus_timestamp(&self, timestamp: DateTime) -> Self::Enum { factory::(unsafe { meos_sys::temporal_minus_timestamptz(self.inner(), to_meos_timestamp(×tamp)) @@ -600,9 +571,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Arguments /// * `timestamps` - A timestamp specifying the values to remove. - /// - /// MEOS Functions: - /// `temporal_minus_*` + #[doc(alias = "temporal_minus_tstzset")] fn minus_timestamp_set(&self, timestamps: &[DateTime]) -> Self::Enum { let timestamps: Vec<_> = timestamps.iter().map(to_meos_timestamp).collect(); let set = unsafe { meos_sys::tstzset_make(timestamps.as_ptr(), timestamps.len() as i32) }; @@ -613,6 +582,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Arguments /// * `time_span` - A time span specifying the values to remove. + #[doc(alias = "temporal_minus_tstzspan")] fn minus_tstz_span(&self, time_span: TsTzSpan) -> Self::Enum { factory::(unsafe { meos_sys::temporal_minus_tstzspan(self.inner(), time_span.inner()) @@ -623,6 +593,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Arguments /// * `time_span_set` - A time span set specifying the values to remove. + #[doc(alias = "temporal_minus_tstzspanset")] fn minus_tstz_span_set(&self, time_span_set: TsTzSpanSet) -> Self::Enum { factory::(unsafe { meos_sys::temporal_minus_tstzspanset(self.inner(), time_span_set.inner()) @@ -630,15 +601,9 @@ pub trait Temporal: Collection + Hash { } /// Returns a new temporal object containing the times `self` is not at `value`. - /// - /// MEOS Functions: - /// `temporal_minus_value` fn minus_value(&self, value: Self::Type) -> Self::Enum; /// Returns a new temporal object containing the times `self` is not at `values`. - /// - /// MEOS Functions: - /// `temporal_minus_values` fn minus_values(&self, values: &[Self::Type]) -> Self::Enum; // ------------------------- Topological Operations ------------------------ @@ -650,6 +615,7 @@ pub trait Temporal: Collection + Hash { /// /// See also: /// `Collection.is_adjacent` + #[doc(alias = "adjacent_temporal_temporal")] fn is_adjacent(&self, other: Self::Enum) -> bool { unsafe { meos_sys::adjacent_temporal_temporal(self.inner(), other.inner()) } } @@ -672,6 +638,7 @@ pub trait Temporal: Collection + Hash { /// /// See also: /// `Collection.is_contained_in` + #[doc(alias = "contained_temporal_temporal")] fn is_contained_in(&self, other: Self::Enum) -> bool { unsafe { meos_sys::contained_temporal_temporal(self.inner(), other.inner()) } } @@ -691,6 +658,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Arguments /// * `other` - A time or temporal object to compare. + #[doc(alias = "contains_temporal_temporal")] fn contains(&self, other: Self::Enum) -> bool { unsafe { meos_sys::contains_temporal_temporal(self.inner(), other.inner()) } } @@ -710,6 +678,7 @@ pub trait Temporal: Collection + Hash { /// /// See also: /// `Collection.overlaps` + #[doc(alias = "overlaps_temporal_temporal")] fn overlaps(&self, other: Self) -> bool { unsafe { meos_sys::overlaps_temporal_temporal(self.inner(), other.inner()) } } @@ -736,6 +705,7 @@ pub trait Temporal: Collection + Hash { /// /// See also: /// `TsTzSpan.is_left` + #[doc(alias = "before_temporal_temporal")] fn is_before(&self, other: Self::Enum) -> bool { unsafe { meos_sys::before_temporal_temporal(self.inner(), other.inner()) } } @@ -750,6 +720,7 @@ pub trait Temporal: Collection + Hash { /// /// See also: /// `TsTzSpan.is_over_or_left` + #[doc(alias = "overbefore_temporal_temporal")] fn is_over_or_before(&self, other: Self::Enum) -> bool { unsafe { meos_sys::overbefore_temporal_temporal(self.inner(), other.inner()) } } @@ -764,6 +735,7 @@ pub trait Temporal: Collection + Hash { /// /// See also: /// `TsTzSpan.is_right` + #[doc(alias = "after_temporal_temporal")] fn is_after(&self, other: Self::Enum) -> bool { unsafe { meos_sys::after_temporal_temporal(self.inner(), other.inner()) } } @@ -778,6 +750,7 @@ pub trait Temporal: Collection + Hash { /// /// See also: /// `TsTzSpan.is_over_or_right` + #[doc(alias = "overafter_temporal_temporal")] fn is_over_or_after(&self, other: Self::Enum) -> bool { unsafe { meos_sys::overafter_temporal_temporal(self.inner(), other.inner()) } } @@ -790,9 +763,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// A float with the Frechet distance. - /// - /// MEOS Functions: - /// `temporal_frechet_distance` + #[doc(alias = "temporal_frechet_distance")] fn frechet_distance(&self, other: Self) -> f64 { unsafe { meos_sys::temporal_frechet_distance(self.inner(), other.inner()) } } @@ -804,9 +775,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// A float with the Dynamic Time Warp distance. - /// - /// MEOS Functions: - /// `temporal_dyntimewarp_distance` + #[doc(alias = "temporal_dyntimewarp_distance")] fn dyntimewarp_distance(&self, other: Self) -> f64 { unsafe { meos_sys::temporal_dyntimewarp_distance(self.inner(), other.inner()) } } @@ -818,9 +787,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// A float with the Hausdorff distance. - /// - /// MEOS Functions: - /// `temporal_hausdorff_distance` + #[doc(alias = "temporal_hausdorff_distance")] fn hausdorff_distance(&self, other: Self) -> f64 { unsafe { meos_sys::temporal_hausdorff_distance(self.inner(), other.inner()) } } @@ -834,9 +801,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// A list of temporal objects representing the split tiles. - /// - /// MEOS Functions: - /// `temporal_time_split` + #[doc(alias = "temporal_time_split")] fn time_split(&self, duration: TimeDelta, start: DateTime) -> Vec { let duration = create_interval(duration); let start = to_meos_timestamp(&start); @@ -865,9 +830,6 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// A list of temporal objects representing the split parts. - /// - /// MEOS Functions: - /// `temporal_time_split` fn time_split_n(&self, n: usize) -> Vec { let start = self.start_timestamp(); let duration = (self.end_timestamp() - start) / n as i32; @@ -882,9 +844,7 @@ pub trait Temporal: Collection + Hash { /// /// ## Returns /// A sequence set of stops. - /// - /// MEOS Functions: - /// `temporal_stops` + #[doc(alias = "temporal_stops")] fn stops(&self, max_distance: f64, min_duration: TimeDelta) -> Self::TSS { let interval = create_interval(min_duration); unsafe { @@ -905,6 +865,7 @@ pub trait Temporal: Collection + Hash { /// ## Returns /// /// `true` if the values of `self` are always equal to `other`, `false` otherwise. + #[doc(alias = "always_eq_temporal_temporal")] fn always_equal(&self, other: &Self) -> Option { let result = unsafe { meos_sys::always_eq_temporal_temporal(self.inner(), other.inner()) }; if result != -1 { @@ -923,6 +884,7 @@ pub trait Temporal: Collection + Hash { /// ## Returns /// /// `true` if the values of `self` are always not equal to `other`, `false` otherwise. + #[doc(alias = "always_ne_temporal_temporal")] fn always_not_equal(&self, other: &Self) -> Option { let result = unsafe { meos_sys::always_ne_temporal_temporal(self.inner(), other.inner()) }; if result != -1 { @@ -941,6 +903,7 @@ pub trait Temporal: Collection + Hash { /// ## Returns /// /// `true` if the values of `self` are ever equal to `other`, `false` otherwise. + #[doc(alias = "ever_eq_temporal_temporal")] fn ever_equal(&self, other: &Self) -> Option { let result = unsafe { meos_sys::ever_eq_temporal_temporal(self.inner(), other.inner()) }; if result != -1 { @@ -959,6 +922,7 @@ pub trait Temporal: Collection + Hash { /// ## Returns /// /// `true` if the values of `self` are ever not equal to `other`, `false` otherwise. + #[doc(alias = "ever_ne_temporal_temporal")] fn ever_not_equal(&self, other: &Self) -> Option { let result = unsafe { meos_sys::ever_ne_temporal_temporal(self.inner(), other.inner()) }; if result != -1 { @@ -1079,32 +1043,20 @@ pub trait OrderedTemporal: Temporal { fn max_value(&self) -> Self::Type; /// Returns a new temporal object containing the times `self` is at its minimum value. - /// - /// MEOS Functions: - /// `temporal_at_min` fn at_min(&self) -> Self { Self::from_inner_as_temporal(unsafe { meos_sys::temporal_at_min(self.inner()) }) } /// Returns a new temporal object containing the times `self` is at its maximum value. - /// - /// MEOS Functions: - /// `temporal_at_max` fn at_max(&self) -> Self { Self::from_inner_as_temporal(unsafe { meos_sys::temporal_at_max(self.inner()) }) } /// Returns a new temporal object containing the times `self` is not at its minimum value. - /// - /// MEOS Functions: - /// `temporal_minus_min` fn minus_min(&self) -> Self { Self::from_inner_as_temporal(unsafe { meos_sys::temporal_minus_min(self.inner()) }) } /// Returns a new temporal object containing the times `self` is not at its maximum value. - /// - /// MEOS Functions: - /// `temporal_minus_max` fn minus_max(&self) -> Self { Self::from_inner_as_temporal(unsafe { meos_sys::temporal_minus_max(self.inner()) }) } @@ -1222,6 +1174,7 @@ pub trait OrderedTemporal: Temporal { /// ## Returns /// /// `true` if the values of `self` are always less than `other`, `false` otherwise. + #[doc(alias = "always_lt_temporal_temporal")] fn always_less(&self, other: &Self::Enum) -> Option { let result = unsafe { meos_sys::always_lt_temporal_temporal(self.inner(), other.inner()) }; if result != -1 { @@ -1240,6 +1193,7 @@ pub trait OrderedTemporal: Temporal { /// ## Returns /// /// `true` if the values of `self` are always less than or equal to `other`, `false` otherwise. + #[doc(alias = "always_le_temporal_temporal")] fn always_less_or_equal(&self, other: &Self::Enum) -> Option { let result = unsafe { meos_sys::always_le_temporal_temporal(self.inner(), other.inner()) }; if result != -1 { @@ -1258,6 +1212,7 @@ pub trait OrderedTemporal: Temporal { /// ## Returns /// /// `true` if the values of `self` are always greater than or equal to `other`, `false` otherwise. + #[doc(alias = "always_ge_temporal_temporal")] fn always_greater_or_equal(&self, other: &Self::Enum) -> Option { let result = unsafe { meos_sys::always_ge_temporal_temporal(self.inner(), other.inner()) }; if result != -1 { @@ -1276,6 +1231,7 @@ pub trait OrderedTemporal: Temporal { /// ## Returns /// /// `true` if the values of `self` are always greater than `other`, `false` otherwise. + #[doc(alias = "always_gt_temporal_temporal")] fn always_greater(&self, other: &Self::Enum) -> Option { let result = unsafe { meos_sys::always_gt_temporal_temporal(self.inner(), other.inner()) }; if result != -1 { @@ -1298,6 +1254,7 @@ pub trait OrderedTemporal: Temporal { /// ## Returns /// /// `true` if the values of `self` are ever less than `other`, `false` otherwise. + #[doc(alias = "ever_lt_temporal_temporal")] fn ever_less(&self, other: &Self::Enum) -> Option { let result = unsafe { meos_sys::ever_lt_temporal_temporal(self.inner(), other.inner()) }; if result != -1 { @@ -1315,6 +1272,7 @@ pub trait OrderedTemporal: Temporal { /// ## Returns /// /// `true` if the values of `self` are ever less than or equal to `other`, `false` otherwise. + #[doc(alias = "ever_le_temporal_temporal")] fn ever_less_or_equal(&self, other: &Self::Enum) -> Option { let result = unsafe { meos_sys::ever_le_temporal_temporal(self.inner(), other.inner()) }; if result != -1 { @@ -1333,6 +1291,7 @@ pub trait OrderedTemporal: Temporal { /// ## Returns /// /// `true` if the values of `self` are ever greater than or equal to `other`, `false` otherwise. + #[doc(alias = "ever_ge_temporal_temporal")] fn ever_greater_or_equal(&self, other: &Self::Enum) -> Option { let result = unsafe { meos_sys::ever_ge_temporal_temporal(self.inner(), other.inner()) }; if result != -1 { @@ -1351,6 +1310,7 @@ pub trait OrderedTemporal: Temporal { /// ## Returns /// /// `true` if the values of `self` are ever greater than `other`, `false` otherwise. + #[doc(alias = "ever_gt_temporal_temporal")] fn ever_greater(&self, other: &Self::Enum) -> Option { let result = unsafe { meos_sys::ever_gt_temporal_temporal(self.inner(), other.inner()) }; if result != -1 { @@ -1454,17 +1414,16 @@ pub trait SimplifiableTemporal: Temporal { /// Simplifies a temporal value ensuring that consecutive values are at least /// a certain distance apart. /// - /// # Arguments + /// ## Arguments /// /// * `distance` - A `f64` representing the minimum distance between two points. /// - /// # Returns + /// ## Returns /// /// A simplified instance of the implementing type with the same subtype as the input. /// - /// # MEOS Functions - /// - /// This method wraps the `temporal_simplify_min_dist` function from MEOS. + /// ## MEOS Functions + #[doc(alias = "temporal_simplify_min_dist")] fn simplify_min_distance(&self, distance: f64) -> Self::Enum { factory::(unsafe { meos_sys::temporal_simplify_min_dist(self.inner(), distance) @@ -1474,17 +1433,14 @@ pub trait SimplifiableTemporal: Temporal { /// Simplifies a temporal value ensuring that consecutive values are at least /// a certain time apart. /// - /// # Arguments + /// ## Arguments /// /// * `distance` - A `Duration` indicating the minimum time between two points. /// - /// # Returns + /// ## Returns /// /// A simplified instance of the implementing type with the same subtype as the input. - /// - /// # MEOS Functions - /// - /// This method wraps the `temporal_simplify_min_tdelta` function from MEOS. + #[doc(alias = "temporal_simplify_min_tdelta")] fn simplify_min_tdelta(&self, distance: TimeDelta) -> Self::Enum { let interval = create_interval(distance); factory::(unsafe { @@ -1494,19 +1450,16 @@ pub trait SimplifiableTemporal: Temporal { /// Simplifies a temporal value using the Douglas-Peucker line simplification algorithm. /// - /// # Arguments + /// ## Arguments /// /// * `distance` - A `f64` representing the minimum distance between two points. /// * `synchronized` - A `bool` indicating if the Synchronized Distance should be used. /// If `false`, the spatial-only distance will be used. /// - /// # Returns + /// ## Returns /// /// A simplified instance of the implementing type with the same subtype as the input. - /// - /// # MEOS Functions - /// - /// This method wraps the `temporal_simplify_dp` function from MEOS. + #[doc(alias = "temporal_simplify_dp")] fn simplify_douglas_peucker(&self, distance: f64, synchronized: bool) -> Self::Enum { factory::(unsafe { meos_sys::temporal_simplify_dp(self.inner(), distance, synchronized) @@ -1515,19 +1468,16 @@ pub trait SimplifiableTemporal: Temporal { /// Simplifies a temporal value using a single-pass Douglas-Peucker line simplification algorithm. /// - /// # Arguments + /// ## Arguments /// /// * `distance` - A `f64` representing the minimum distance between two points. /// * `synchronized` - A `bool` indicating if the Synchronized Distance should be used. /// If `false`, the spatial-only distance will be used. /// - /// # Returns + /// ## Returns /// /// A simplified instance of the implementing type with the same subtype as the input. - /// - /// # MEOS Functions - /// - /// This method wraps the `temporal_simplify_max_dist` function from MEOS. + #[doc(alias = "temporal_simplify_max_dist")] fn simplify_max_distance(&self, distance: f64, synchronized: bool) -> Self::Enum { factory::(unsafe { meos_sys::temporal_simplify_max_dist(self.inner(), distance, synchronized) diff --git a/src/temporal/ttext.rs b/src/temporal/ttext.rs index 2e33ed1..6888b03 100644 --- a/src/temporal/ttext.rs +++ b/src/temporal/ttext.rs @@ -10,8 +10,8 @@ use chrono::{DateTime, TimeZone}; use crate::{ collections::{ - base::{collection::Collection, span::Span, span_set::SpanSet}, - datetime::{tstz_span::TsTzSpan, tstz_span_set::TsTzSpanSet}, + base::*, + datetime::{TsTzSpan, TsTzSpanSet}, }, errors::ParseError, factory, impl_from_str, diff --git a/sys/README.md b/sys/README.md index 0bb0c60..bf1e1cd 100644 --- a/sys/README.md +++ b/sys/README.md @@ -37,7 +37,3 @@ DYLD_FALLBACK_LIBRARY_PATH=/lib MEOS_LIB_DIR=/lib ME ## Binding generation By default, meos-sys will use the pregenerated bindings for the 1.2 version, the 1.1 ones is also available. Alternatively, you can generate your own bindings from your `libmeos` installation by specifying the `bindgen` feature. - -## Bindings - -Pre-built bindings are available for 1.2 and 1.1 \ No newline at end of file