Skip to content

Commit

Permalink
Add typehint stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGrace2282 committed Aug 31, 2024
1 parent cbb1377 commit 0989fe0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/target
**/target

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
5 changes: 5 additions & 0 deletions manimforge/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .manimforge import *

__doc__ = manimforge.__doc__
if hasattr(manimforge, "__all__"):
__all__ = manimforge.__all__
14 changes: 14 additions & 0 deletions manimforge/cairo.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import Any, Self

import numpy as np
import numpy.typing as npt
import cairo

class CairoCamera:
def __init__(self, *args, **kwargs) -> None: ...

def set_cairo_context_path(self, ctx: cairo.Context, vmobject: Any, points: npt.NDArray[np.float64]) -> None: ...

def __copy__(self) -> Self: ...

def __deepcopy__(self, memo: Any) -> Self: ...
Empty file added manimforge/manimforge.pyi
Empty file.
19 changes: 7 additions & 12 deletions src/cairo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ use pyo3::types::{PyTuple, PyDict};
use std::iter;

/// Check if two points are approximately equal
fn consider_points_equal_2d<T: num_traits::Float>(p1: ArrayView1<T>, p2: ArrayView1<T>) -> bool {
let rtol = T::from(1e-5).expect("rtol is a float");
let atol = T::from(1e-6).expect("atol is a float"); // TODO make this based off vmobject
fn consider_points_equal_2d(p1: ArrayView1<f64>, p2: ArrayView1<f64>) -> bool {
let rtol = 1e-5;
let atol = 1e-6; // TODO make this based off vmobject
((p1[0] - p2[0]).abs() <= atol + rtol * p1[0].abs())
& ((p1[1] - p2[1]).abs() <= atol + rtol * p1[1].abs())
}

// fn consider_points_equal<T: num_traits::Float>(p1: ArrayView1<T>, p2: ArrayView1<T>) -> bool {
// p1.iter().zip(p2.iter()).all(|(a, b)| a == b)
// }

fn gen_subpaths_from_points_2d<T: num_traits::Float + std::fmt::Debug>(
points: ArrayView2<T>,
) -> Vec<Array2<T>> {
fn gen_subpaths_from_points_2d(
points: ArrayView2<f64>,
) -> Vec<Array2<f64>> {
let nppcc = 4;
let filtered = (nppcc..points.len_of(Axis(0))).step_by(nppcc).filter(|&n| {
!consider_points_equal_2d(
Expand All @@ -45,9 +42,7 @@ fn gen_subpaths_from_points_2d<T: num_traits::Float + std::fmt::Debug>(
.collect()
}

fn gen_cubic_bezier_tuples_from_points<T>(points: ArrayView2<T>) -> Vec<Array2<T>>
where
T: Clone,
fn gen_cubic_bezier_tuples_from_points(points: ArrayView2<f64>) -> Vec<Array2<f64>>
{
let nppcc = 4;
let remainder = points.len() % nppcc;
Expand Down
1 change: 1 addition & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from manimforge.cairo import CairoCamera

0 comments on commit 0989fe0

Please sign in to comment.