Skip to content

Commit b03cf9b

Browse files
committed
Export modules, rename ctors.
1 parent 670a404 commit b03cf9b

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
from .mewnala import *
2+
3+
import sys as _sys
4+
from . import mewnala as _native
5+
for _name in ("math", "color"):
6+
_sub = getattr(_native, _name, None)
7+
if _sub is not None:
8+
_sys.modules[f"{__name__}.{_name}"] = _sub
9+
del _sys, _native, _name, _sub

crates/processing_pyo3/src/color.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,66 +87,66 @@ impl PyColor {
8787

8888
#[staticmethod]
8989
#[pyo3(signature = (r, g, b, a=1.0))]
90-
pub fn from_srgb(r: f32, g: f32, b: f32, a: f32) -> Self {
90+
pub fn srgb(r: f32, g: f32, b: f32, a: f32) -> Self {
9191
Self(Color::Srgba(Srgba::new(r, g, b, a)))
9292
}
9393

9494
#[staticmethod]
9595
#[pyo3(signature = (r, g, b, a=1.0))]
96-
pub fn from_linear(r: f32, g: f32, b: f32, a: f32) -> Self {
96+
pub fn linear(r: f32, g: f32, b: f32, a: f32) -> Self {
9797
Self(Color::LinearRgba(LinearRgba::new(r, g, b, a)))
9898
}
9999

100100
#[staticmethod]
101101
#[pyo3(signature = (h, s, l, a=1.0))]
102-
pub fn from_hsla(h: f32, s: f32, l: f32, a: f32) -> Self {
102+
pub fn hsla(h: f32, s: f32, l: f32, a: f32) -> Self {
103103
Self(Color::Hsla(Hsla::new(h, s, l, a)))
104104
}
105105

106106
#[staticmethod]
107107
#[pyo3(signature = (h, s, v, a=1.0))]
108-
pub fn from_hsva(h: f32, s: f32, v: f32, a: f32) -> Self {
108+
pub fn hsva(h: f32, s: f32, v: f32, a: f32) -> Self {
109109
Self(Color::Hsva(Hsva::new(h, s, v, a)))
110110
}
111111

112112
#[staticmethod]
113113
#[pyo3(signature = (h, w, b, a=1.0))]
114-
pub fn from_hwba(h: f32, w: f32, b: f32, a: f32) -> Self {
114+
pub fn hwba(h: f32, w: f32, b: f32, a: f32) -> Self {
115115
Self(Color::Hwba(Hwba::new(h, w, b, a)))
116116
}
117117

118118
#[staticmethod]
119119
#[pyo3(signature = (l, a_axis, b_axis, alpha=1.0))]
120-
pub fn from_oklab(l: f32, a_axis: f32, b_axis: f32, alpha: f32) -> Self {
120+
pub fn oklab(l: f32, a_axis: f32, b_axis: f32, alpha: f32) -> Self {
121121
Self(Color::Oklaba(Oklaba::new(l, a_axis, b_axis, alpha)))
122122
}
123123

124124
#[staticmethod]
125125
#[pyo3(signature = (l, c, h, a=1.0))]
126-
pub fn from_oklch(l: f32, c: f32, h: f32, a: f32) -> Self {
126+
pub fn oklch(l: f32, c: f32, h: f32, a: f32) -> Self {
127127
Self(Color::Oklcha(Oklcha::new(l, c, h, a)))
128128
}
129129

130130
#[staticmethod]
131131
#[pyo3(signature = (l, a_axis, b_axis, alpha=1.0))]
132-
pub fn from_lab(l: f32, a_axis: f32, b_axis: f32, alpha: f32) -> Self {
132+
pub fn lab(l: f32, a_axis: f32, b_axis: f32, alpha: f32) -> Self {
133133
Self(Color::Laba(Laba::new(l, a_axis, b_axis, alpha)))
134134
}
135135

136136
#[staticmethod]
137137
#[pyo3(signature = (l, c, h, a=1.0))]
138-
pub fn from_lch(l: f32, c: f32, h: f32, a: f32) -> Self {
138+
pub fn lch(l: f32, c: f32, h: f32, a: f32) -> Self {
139139
Self(Color::Lcha(Lcha::new(l, c, h, a)))
140140
}
141141

142142
#[staticmethod]
143143
#[pyo3(signature = (x, y, z, a=1.0))]
144-
pub fn from_xyz(x: f32, y: f32, z: f32, a: f32) -> Self {
144+
pub fn xyz(x: f32, y: f32, z: f32, a: f32) -> Self {
145145
Self(Color::Xyza(Xyza::new(x, y, z, a)))
146146
}
147147

148148
#[staticmethod]
149-
pub fn from_hex(s: &str) -> PyResult<Self> {
149+
pub fn hex(s: &str) -> PyResult<Self> {
150150
parse_hex(s).map(Self)
151151
}
152152

@@ -242,7 +242,7 @@ impl PyColor {
242242
self.0.set_alpha(val);
243243
}
244244

245-
fn hex(&self) -> String {
245+
fn to_hex(&self) -> String {
246246
to_srgba(&self.0).to_hex()
247247
}
248248

@@ -493,7 +493,7 @@ mod tests {
493493

494494
#[test]
495495
fn test_hsla_roundtrip() {
496-
let c = PyColor::from_hsla(0.0, 1.0, 0.5, 1.0);
496+
let c = PyColor::hsla(0.0, 1.0, 0.5, 1.0);
497497
let s = to_srgba(&c.0);
498498
assert!((s.red - 1.0).abs() < 0.01);
499499
assert!(s.green < 0.01);
@@ -508,7 +508,7 @@ mod tests {
508508

509509
#[test]
510510
fn test_oklch_roundtrip() {
511-
let c = PyColor::from_oklch(0.7, 0.15, 30.0, 1.0);
511+
let c = PyColor::oklch(0.7, 0.15, 30.0, 1.0);
512512
let (l, ch, h, a) = c.to_oklch();
513513
assert!((l - 0.7).abs() < 0.01);
514514
assert!((ch - 0.15).abs() < 0.01);
@@ -518,7 +518,7 @@ mod tests {
518518

519519
#[test]
520520
fn test_linear_roundtrip() {
521-
let c = PyColor::from_linear(0.5, 0.25, 0.1, 0.8);
521+
let c = PyColor::linear(0.5, 0.25, 0.1, 0.8);
522522
let (r, g, b, a) = c.to_linear();
523523
assert!((r - 0.5).abs() < 0.01);
524524
assert!((g - 0.25).abs() < 0.01);

crates/processing_pyo3/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,67 +196,67 @@ mod mewnala {
196196

197197
#[pyfunction]
198198
fn hex(s: &str) -> PyResult<PyColor> {
199-
PyColor::from_hex(s)
199+
PyColor::hex(s)
200200
}
201201

202202
#[pyfunction]
203203
#[pyo3(signature = (r, g, b, a=1.0))]
204204
fn srgb(r: f32, g: f32, b: f32, a: f32) -> PyColor {
205-
PyColor::from_srgb(r, g, b, a)
205+
PyColor::srgb(r, g, b, a)
206206
}
207207

208208
#[pyfunction]
209209
#[pyo3(signature = (r, g, b, a=1.0))]
210210
fn linear(r: f32, g: f32, b: f32, a: f32) -> PyColor {
211-
PyColor::from_linear(r, g, b, a)
211+
PyColor::linear(r, g, b, a)
212212
}
213213

214214
#[pyfunction]
215215
#[pyo3(signature = (h, s, l, a=1.0))]
216216
fn hsla(h: f32, s: f32, l: f32, a: f32) -> PyColor {
217-
PyColor::from_hsla(h, s, l, a)
217+
PyColor::hsla(h, s, l, a)
218218
}
219219

220220
#[pyfunction]
221221
#[pyo3(signature = (h, s, v, a=1.0))]
222222
fn hsva(h: f32, s: f32, v: f32, a: f32) -> PyColor {
223-
PyColor::from_hsva(h, s, v, a)
223+
PyColor::hsva(h, s, v, a)
224224
}
225225

226226
#[pyfunction]
227227
#[pyo3(signature = (h, w, b, a=1.0))]
228228
fn hwba(h: f32, w: f32, b: f32, a: f32) -> PyColor {
229-
PyColor::from_hwba(h, w, b, a)
229+
PyColor::hwba(h, w, b, a)
230230
}
231231

232232
#[pyfunction]
233233
#[pyo3(signature = (l, a_axis, b_axis, alpha=1.0))]
234234
fn oklab(l: f32, a_axis: f32, b_axis: f32, alpha: f32) -> PyColor {
235-
PyColor::from_oklab(l, a_axis, b_axis, alpha)
235+
PyColor::oklab(l, a_axis, b_axis, alpha)
236236
}
237237

238238
#[pyfunction]
239239
#[pyo3(signature = (l, c, h, a=1.0))]
240240
fn oklch(l: f32, c: f32, h: f32, a: f32) -> PyColor {
241-
PyColor::from_oklch(l, c, h, a)
241+
PyColor::oklch(l, c, h, a)
242242
}
243243

244244
#[pyfunction]
245245
#[pyo3(signature = (l, a_axis, b_axis, alpha=1.0))]
246246
fn lab(l: f32, a_axis: f32, b_axis: f32, alpha: f32) -> PyColor {
247-
PyColor::from_lab(l, a_axis, b_axis, alpha)
247+
PyColor::lab(l, a_axis, b_axis, alpha)
248248
}
249249

250250
#[pyfunction]
251251
#[pyo3(signature = (l, c, h, a=1.0))]
252252
fn lch(l: f32, c: f32, h: f32, a: f32) -> PyColor {
253-
PyColor::from_lch(l, c, h, a)
253+
PyColor::lch(l, c, h, a)
254254
}
255255

256256
#[pyfunction]
257257
#[pyo3(signature = (x, y, z, a=1.0))]
258258
fn xyz(x: f32, y: f32, z: f32, a: f32) -> PyColor {
259-
PyColor::from_xyz(x, y, z, a)
259+
PyColor::xyz(x, y, z, a)
260260
}
261261
}
262262

0 commit comments

Comments
 (0)