use crate::b2_collision::*;
use crate::b2_settings::*;
use crate::b2_math::*;
use crate::b2_common::*;
use crate::b2_shape::*;
use crate::private::collision::b2_polygon_shape as private;
use std::rc::Rc;
#[derive(Clone, Copy, Debug)]
pub struct B2polygonShape {
pub base: B2Shape,
pub m_centroid: B2vec2,
pub m_vertices: [B2vec2; B2_MAX_POLYGON_VERTICES],
pub m_normals: [B2vec2; B2_MAX_POLYGON_VERTICES],
pub m_count: usize,
}
impl Default for B2polygonShape {
fn default() -> Self {
return inline::b2_polygon_shape();
}
}
impl B2shapeDynTrait for B2polygonShape {
fn get_base(&self) -> &B2Shape {
return &self.base;
}
fn get_type(&self) -> B2ShapeType {
return self.base.get_type();
}
fn clone_box(&self) -> Box<dyn B2shapeDynTrait> {
return private::b2_shape_dyn_trait_clone(self);
}
fn clone_rc(&self) -> ShapePtr {
return Rc::new(self.clone());
}
fn get_child_count(&self) -> usize {
return private::b2_shape_dyn_trait_get_child_count(self);
}
fn test_point(&self, transform: B2Transform, p: B2vec2) -> bool {
return private::b2_shape_dyn_trait_test_point(self, transform, p);
}
fn ray_cast(
&self,
output: &mut B2rayCastOutput,
input: &B2rayCastInput,
xf: B2Transform,
child_index: usize,
) -> bool {
return private::b2_shape_dyn_trait_ray_cast(self, output, input, xf, child_index);
}
fn compute_aabb(&self, aabb: &mut B2AABB, xf: B2Transform, child_index: usize) {
private::b2_shape_dyn_trait_compute_aabb(self, aabb, xf, child_index);
}
fn compute_mass(&self, mass_data: &mut B2massData, density: f32) {
private::b2_shape_dyn_trait_compute_mass(self, mass_data, density);
}
}
impl B2polygonShape {
pub const STRUCT_NAME: &'static str = "B2polygonShape";
pub fn set(&mut self, points: &[B2vec2]) {
private::b2_polygon_shape_set(self, points);
}
pub fn set_as_box(&mut self, hx: f32, hy: f32) {
private::b2_polygon_shape_set_as_box(self, hx, hy);
}
pub fn set_as_box_angle(&mut self, hx: f32, hy: f32, center: B2vec2, angle: f32) {
private::b2_polygon_shape_set_as_box_angle(self, hx, hy, center, angle);
}
pub fn validate(self) -> bool {
return private::b2_polygon_shape_validate(self);
}
}
mod inline {
use super::*;
pub fn b2_polygon_shape() -> B2polygonShape {
return B2polygonShape {
base: B2Shape {
m_type: B2ShapeType::EPolygon,
m_radius: B2_POLYGON_RADIUS,
},
m_centroid: B2vec2::zero(),
m_count: 0,
m_vertices: <[B2vec2; B2_MAX_POLYGON_VERTICES]>::default(),
m_normals: <[B2vec2; B2_MAX_POLYGON_VERTICES]>::default(),
};
}
}