Skip to content

Commit

Permalink
Add missing functions to Python extension and bootstrap process
Browse files Browse the repository at this point in the history
  • Loading branch information
Cleptomania committed Mar 2, 2024
1 parent d240f60 commit f98b9aa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
29 changes: 29 additions & 0 deletions python/arcade_accelerate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,38 @@ def patch_spritelist_collision(patches):

def patch_math(patches):
patches["arcade.math"].rotate_point = arcade_accelerate.rotate_point
patches["arcade.math"].clamp = arcade_accelerate.clamp
patches["arcade.math"].lerp = arcade_accelerate.lerp
patches["arcade.math"].lerp_vec = arcade_accelerate.lerp_vec
patches["arcade.math"].lerp_angle = arcade_accelerate.lerp_angle
patches["arcade.math"].get_distance = arcade_accelerate.get_distance
patches["arcade.math"].get_angle_degrees = arcade_accelerate.get_angle_degrees
patches["arcade.math"].get_angle_radians = arcade_accelerate.get_angle_radians
patches["arcade.math"].rand_in_rect = arcade_accelerate.rand_in_rect
patches["arcade.math"].rand_in_circle = arcade_accelerate.rand_in_circle
patches["arcade.math"].rand_on_circle = arcade_accelerate.rand_on_circle
patches["arcade.math"].rand_on_line = arcade_accelerate.rand_on_line
patches["arcade.math"].rand_angle_360_deg = arcade_accelerate.rand_angle_360_deg
patches["arcade.math"].rand_angle_spread_deg = (
arcade_accelerate.rand_angle_spread_deg
)
patches["arcade.math"].rand_vec_degree_spread = (
arcade_accelerate.rand_vec_degree_spread
)
patches["arcade.math"].rand_vec_magnitude = arcade_accelerate.rand_vec_magnitude


def patch_geometry(patches):
patches["arcade.geometry"].are_polygons_intersecting = (
arcade_accelerate.are_polygons_intersecting
)
patches["arcade.geometry"].is_point_in_box = arcade_accelerate.is_point_in_box
patches["arcade.geometry"].get_triangle_orientation = (
arcade_accelerate.get_triangle_orientation
)
patches["arcade.geometry"].are_lines_intersecting = (
arcade_accelerate.are_lines_intersecting
)
patches["arcade.geometry"].is_point_in_polygon = (
arcade_accelerate.is_point_in_polygon
)
22 changes: 16 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub use sprite_list::*;
/// A Python module implemented in Rust.
#[pymodule]
fn arcade_accelerate(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<HitBox>()?;
m.add_class::<RotatableHitBox>()?;
m.add_class::<hitbox::HitBox>()?;
m.add_class::<hitbox::RotatableHitBox>()?;
m.add_function(wrap_pyfunction!(math::rotate_point, m)?)?;
m.add_function(wrap_pyfunction!(math::clamp, m)?)?;
m.add_function(wrap_pyfunction!(math::lerp, m)?)?;
Expand All @@ -33,9 +33,19 @@ fn arcade_accelerate(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(math::rand_angle_spread_deg, m)?)?;
m.add_function(wrap_pyfunction!(math::rand_vec_degree_spread, m)?)?;
m.add_function(wrap_pyfunction!(math::rand_vec_magnitude, m)?)?;
m.add_function(wrap_pyfunction!(are_polygons_intersecting, m)?)?;
m.add_function(wrap_pyfunction!(check_for_collision_with_list, m)?)?;
m.add_function(wrap_pyfunction!(check_for_collision_with_lists, m)?)?;
m.add_function(wrap_pyfunction!(is_point_in_polygon, m)?)?;
m.add_function(wrap_pyfunction!(geometry::are_polygons_intersecting, m)?)?;
m.add_function(wrap_pyfunction!(geometry::is_point_in_polygon, m)?)?;
m.add_function(wrap_pyfunction!(geometry::is_point_in_box, m)?)?;
m.add_function(wrap_pyfunction!(geometry::get_triangle_orientation, m)?)?;
m.add_function(wrap_pyfunction!(geometry::are_lines_intersecting, m)?)?;
m.add_function(wrap_pyfunction!(
sprite_list::check_for_collision_with_list,
m
)?)?;
m.add_function(wrap_pyfunction!(
sprite_list::check_for_collision_with_lists,
m
)?)?;

Ok(())
}

0 comments on commit f98b9aa

Please sign in to comment.