Skip to content

Commit ad12537

Browse files
author
AGAEV Denis E
committed
Add another geo types
1 parent 3a4c7b5 commit ad12537

File tree

4 files changed

+176
-8
lines changed

4 files changed

+176
-8
lines changed

python/psqlpy/_internal/geometric_types.pyi

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class PyBox:
3030
"""Create new instance of PyBox.
3131
3232
You need to pass any of this structures:
33-
- sequence of two sequences, each with two float numbers
34-
- sequence of four float
33+
- sequence of two sequences, each with pair of float numbers
34+
- sequence of two pairs of float
3535
3636
### Parameters:
37-
- `value`: any valid sequence with four float numbers.
37+
- `value`: any valid sequence with two pairs of float numbers.
3838
"""
3939

4040
class PyPath:
@@ -50,8 +50,69 @@ class PyPath:
5050
"""Create new instance of PyPath.
5151
5252
You need to pass any of this structures:
53-
- sequence of sequences, each with two float numbers
54-
- sequence of float numbers which amount must be a multiple of two
53+
- sequence of sequences, each with pair of float numbers
54+
- sequence with pairs of float numbers
55+
56+
### Parameters:
57+
- `value`: any valid structure with float numbers.
58+
"""
59+
60+
class PyLine:
61+
"""Represent line field in PostgreSQL and Line in Rust."""
62+
63+
def __init__(
64+
self: Self,
65+
value: Union[
66+
Sequence[Sequence[float]],
67+
Sequence[float],
68+
],
69+
) -> None:
70+
"""Create new instance of PyLine.
71+
72+
You need to pass any of this structures:
73+
- sequence of three float numbers
74+
- sequence of two sequences, each with pair of float numbers
75+
- sequence with two pairs of float numbers
76+
77+
### Parameters:
78+
- `value`: any valid structure with float numbers.
79+
"""
80+
81+
class PyLineSegment:
82+
"""Represent lseg field in PostgreSQL and Line in Rust."""
83+
84+
def __init__(
85+
self: Self,
86+
value: Union[
87+
Sequence[Sequence[float]],
88+
Sequence[float],
89+
],
90+
) -> None:
91+
"""Create new instance of PyLineSegment.
92+
93+
You need to pass any of this structures:
94+
- sequence of two sequences, each with pair of float numbers
95+
- sequence with two pairs of float numbers
96+
97+
### Parameters:
98+
- `value`: any valid structure with float numbers.
99+
"""
100+
101+
class PyPolygon:
102+
"""Represent polygon field in PostgreSQL and Polygon in Rust."""
103+
104+
def __init__(
105+
self: Self,
106+
value: Union[
107+
Sequence[Sequence[float]],
108+
Sequence[float],
109+
],
110+
) -> None:
111+
"""Create new instance of PyPolygon.
112+
113+
You need to pass any of this structures:
114+
- sequence of sequences, each with pair of float numbers
115+
- sequence with pairs of float numbers
55116
56117
### Parameters:
57118
- `value`: any valid structure with float numbers.

python/psqlpy/geometric_types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
PyPoint,
33
PyBox,
44
PyPath,
5+
PyLine,
6+
PyLineSegment,
7+
PyPolygon,
58
)
69

710

811
__all__ = [
912
"PyPoint",
1013
"PyBox",
1114
"PyPath",
15+
"PyLine",
16+
"PyLineSegment",
17+
"PyPolygon",
1218
]

src/geometric_types.rs

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use geo_types::{Point, Rect, LineString};
1+
use geo_types::{Point, Rect, Line, LineString, Polygon};
22
use pyo3::{pyclass, pymethods, types::PyModule, PyAny, PyResult, Python};
33

44
// use crate::{exceptions::rust_errors::RustPSQLDriverPyResult, value_converter::build_serde_value};
@@ -44,7 +44,7 @@ impl PyBox {
4444
// impl PyBox {
4545
// #[new]
4646
// #[allow(clippy::missing_errors_doc)]
47-
// pub fn new_point(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
47+
// pub fn new_box(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
4848
// Ok(Self {
4949
// inner: build_serde_value(value)?,
5050
// })
@@ -68,7 +68,103 @@ impl PyPath {
6868
// impl PyPath {
6969
// #[new]
7070
// #[allow(clippy::missing_errors_doc)]
71-
// pub fn new_point(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
71+
// pub fn new_path(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
72+
// Ok(Self {
73+
// inner: build_serde_value(value)?,
74+
// })
75+
// }
76+
// }
77+
78+
#[pyclass]
79+
#[derive(Clone)]
80+
pub struct PyLine {
81+
inner: Line,
82+
}
83+
84+
impl PyLine {
85+
#[must_use]
86+
pub fn inner(&self) -> &Line {
87+
&self.inner
88+
}
89+
}
90+
91+
// #[pymethods]
92+
// impl PyLine {
93+
// #[new]
94+
// #[allow(clippy::missing_errors_doc)]
95+
// pub fn new_path(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
96+
// Ok(Self {
97+
// inner: build_serde_value(value)?,
98+
// })
99+
// }
100+
// }
101+
102+
#[pyclass]
103+
#[derive(Clone)]
104+
pub struct PyLineSegment {
105+
inner: Line,
106+
}
107+
108+
impl PyLineSegment {
109+
#[must_use]
110+
pub fn inner(&self) -> &Line {
111+
&self.inner
112+
}
113+
}
114+
115+
// #[pymethods]
116+
// impl PyLineSegment {
117+
// #[new]
118+
// #[allow(clippy::missing_errors_doc)]
119+
// pub fn new_path(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
120+
// Ok(Self {
121+
// inner: build_serde_value(value)?,
122+
// })
123+
// }
124+
// }
125+
126+
#[pyclass]
127+
#[derive(Clone)]
128+
pub struct PyPolygon {
129+
inner: Polygon,
130+
}
131+
132+
impl PyPolygon {
133+
#[must_use]
134+
pub fn inner(&self) -> &Polygon {
135+
&self.inner
136+
}
137+
}
138+
139+
// #[pymethods]
140+
// impl PyPolygon {
141+
// #[new]
142+
// #[allow(clippy::missing_errors_doc)]
143+
// pub fn new_path(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
144+
// Ok(Self {
145+
// inner: build_serde_value(value)?,
146+
// })
147+
// }
148+
// }
149+
150+
// #[pyclass]
151+
// #[derive(Clone)]
152+
// pub struct PyCircle {
153+
// inner: Polygon,
154+
// }
155+
156+
// impl PyCircle {
157+
// #[must_use]
158+
// pub fn inner(&self) -> &Polygon {
159+
// &self.inner
160+
// }
161+
// }
162+
163+
// #[pymethods]
164+
// impl PyCircle {
165+
// #[new]
166+
// #[allow(clippy::missing_errors_doc)]
167+
// pub fn new_path(value: &PyAny) -> RustPSQLDriverPyResult<Self> {
72168
// Ok(Self {
73169
// inner: build_serde_value(value)?,
74170
// })
@@ -81,5 +177,9 @@ pub fn geometric_types_module(_py: Python<'_>, pymod: &PyModule) -> PyResult<()>
81177
pymod.add_class::<PyPoint>()?;
82178
pymod.add_class::<PyBox>()?;
83179
pymod.add_class::<PyPath>()?;
180+
pymod.add_class::<PyLine>()?;
181+
pymod.add_class::<PyLineSegment>()?;
182+
pymod.add_class::<PyPolygon>()?;
183+
// pymod.add_class::<PyCircle>()?;
84184
Ok(())
85185
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub mod exceptions;
55
pub mod extra_types;
66
pub mod query_result;
77
pub mod value_converter;
8+
pub mod geometric_types;
89

910
use common::add_module;
1011
use geometric_types::geometric_types_module;

0 commit comments

Comments
 (0)