Skip to content

fix clippy #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ fn list_cpp_files<P: AsRef<Path>>(dir: P) -> Vec<String> {
}
}
}
return files;
files
}
30 changes: 18 additions & 12 deletions src/demo/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ pub struct RcMeshLoaderObj(UniquePtr<ffi::rcMeshLoaderObj>);

impl Default for RcMeshLoaderObj {
fn default() -> Self {
return RcMeshLoaderObj::new();
RcMeshLoaderObj::new()
}
}

impl RcMeshLoaderObj {
pub fn new() -> RcMeshLoaderObj {
return RcMeshLoaderObj(ffi::rcNewMeshLoaderObj());
RcMeshLoaderObj(ffi::rcNewMeshLoaderObj())
}

pub fn load(&mut self, file_name: &str) -> bool {
Expand All @@ -88,11 +88,11 @@ impl RcMeshLoaderObj {
}

pub fn get_vert_count(&self) -> i32 {
return self.0.getVertCount();
self.0.getVertCount()
}

pub fn get_tri_count(&self) -> i32 {
return self.0.getTriCount();
self.0.getTriCount()
}

pub fn get_file_name(&self) -> &str {
Expand All @@ -106,8 +106,8 @@ pub fn load_nav_mesh(path: &str) -> RNResult<DtNavMesh> {
if mesh.is_null() {
return Err(RNError::Failed);
}
return Ok(DtNavMesh::from_ptr(mesh));
};
Ok(DtNavMesh::from_ptr(mesh))
}
}

pub fn save_nav_mesh(mesh: &DtNavMesh, path: &str) {
Expand Down Expand Up @@ -161,17 +161,23 @@ impl Drop for RcChunkyTriMesh {
}
}

impl Default for RcChunkyTriMesh {
fn default() -> Self {
Self::new()
}
}

impl RcChunkyTriMesh {
fn inner(&self) -> &CxxRcChunkyTriMesh {
return unsafe { &*self.0 };
unsafe { &*self.0 }
}

fn inner_mut(&mut self) -> Pin<&mut CxxRcChunkyTriMesh> {
return unsafe { Pin::new_unchecked(&mut *self.0) };
unsafe { Pin::new_unchecked(&mut *self.0) }
}

pub fn new() -> RcChunkyTriMesh {
return RcChunkyTriMesh(unsafe { ffi::rcctm_new() });
RcChunkyTriMesh(unsafe { ffi::rcctm_new() })
}

pub fn nodes(&self) -> &[RcChunkyTriMeshNode] {
Expand Down Expand Up @@ -208,7 +214,7 @@ pub fn rc_create_chunky_tri_mesh(
if !result {
return Err(RNError::Failed);
}
return Ok(());
Ok(())
}

pub fn rc_get_chunks_overlapping_rect(
Expand All @@ -220,11 +226,11 @@ pub fn rc_get_chunks_overlapping_rect(
let n = unsafe {
ffi::rcGetChunksOverlappingRect(cm.0, bmin.as_ptr(), bmax.as_ptr(), ids.as_mut_ptr(), ids.len() as i32)
};
return n as usize;
n as usize
}

pub fn rc_get_chunks_overlapping_segment(cm: &RcChunkyTriMesh, p: &[f32; 2], q: &[f32; 2], ids: &mut [i32]) -> usize {
let n =
unsafe { ffi::rcGetChunksOverlappingSegment(cm.0, p.as_ptr(), q.as_ptr(), ids.as_mut_ptr(), ids.len() as i32) };
return n as usize;
n as usize
}
92 changes: 62 additions & 30 deletions src/detour/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ unsafe impl ExternType for DtStatus {
impl DtStatus {
pub fn to_result(self) -> RNResult<()> {
if self.0 & DT_SUCCESS != 0 {
return Ok(());
Ok(())
} else if self.0 & DT_FAILURE != 0 {
match self.0 & DT_STATUS_DETAIL_MASK {
DT_WRONG_MAGIC => return Err(RNError::WrongMagic),
Expand Down Expand Up @@ -75,8 +75,9 @@ pub struct DtBuf {
}

impl Default for DtBuf {
#[inline]
fn default() -> Self {
return DtBuf::from_raw(std::ptr::null_mut(), 0);
DtBuf::from_raw(std::ptr::null_mut(), 0)
}
}

Expand All @@ -88,122 +89,153 @@ impl Drop for DtBuf {
}

impl DtBuf {
#[inline]
pub(crate) fn from_raw(data: *mut u8, size: i32) -> DtBuf {
return DtBuf { data, size };
DtBuf { data, size }
}

pub fn as_ref(&self) -> &[u8] {
#[inline]
pub fn as_slice(&self) -> &[u8] {
return unsafe { std::slice::from_raw_parts(self.data, self.size as usize) };
}

pub fn as_mut(&self) -> &mut [u8] {
#[inline]
pub fn as_slice_mut(&mut self) -> &mut [u8] {
return unsafe { std::slice::from_raw_parts_mut(self.data, self.size as usize) };
}

#[inline]
pub fn len(&self) -> usize {
return self.size as usize;
self.size as usize
}

#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}

#[inline]
pub fn dt_vcross(a: &[f32; 3], b: &[f32; 3]) -> [f32; 3] {
return [
[
a[1] * b[2] - a[2] * b[1],
a[2] * b[0] - a[0] * b[2],
a[0] * b[1] - a[1] * b[0],
];
]
}

#[inline]
pub fn dt_vdot(a: &[f32; 3], b: &[f32; 3]) -> f32 {
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
}

#[inline]
pub fn dt_vdot_2d(a: &[f32; 3], b: &[f32; 3]) -> f32 {
return a[0] * b[0] + a[2] * b[2];
a[0] * b[0] + a[2] * b[2]
}

#[inline]
pub fn dt_vmad(a: &[f32; 3], b: &[f32; 3], s: f32) -> [f32; 3] {
return [a[0] + b[0] * s, a[1] + b[1] * s, a[2] + b[2] * s];
[a[0] + b[0] * s, a[1] + b[1] * s, a[2] + b[2] * s]
}

#[inline]
pub fn dt_vlerp(a: &[f32; 3], b: &[f32; 3], t: f32) -> [f32; 3] {
return [
[
a[0] + (b[0] - a[0]) * t,
a[1] + (b[1] - a[1]) * t,
a[2] + (b[2] - a[2]) * t,
];
]
}

#[inline]
pub fn dt_vadd(a: &[f32; 3], b: &[f32; 3]) -> [f32; 3] {
return [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
[a[0] + b[0], a[1] + b[1], a[2] + b[2]]
}

#[inline]
pub fn dt_vsub(a: &[f32; 3], b: &[f32; 3]) -> [f32; 3] {
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
[a[0] - b[0], a[1] - b[1], a[2] - b[2]]
}

#[inline]
pub fn dt_vscale(a: &[f32; 3], b: f32) -> [f32; 3] {
return [a[0] * b, a[1] * b, a[2] * b];
[a[0] * b, a[1] * b, a[2] * b]
}

#[inline]
pub fn dt_vmin(a: &[f32; 3], b: &[f32; 3]) -> [f32; 3] {
return [a[0].min(b[0]), a[1].min(b[1]), a[2].min(b[2])];
[a[0].min(b[0]), a[1].min(b[1]), a[2].min(b[2])]
}

#[inline]
pub fn dt_vmax(a: &[f32; 3], b: &[f32; 3]) -> [f32; 3] {
return [a[0].max(b[0]), a[1].max(b[1]), a[2].max(b[2])];
[a[0].max(b[0]), a[1].max(b[1]), a[2].max(b[2])]
}

#[inline]
pub fn dt_vlen(a: &[f32; 3]) -> f32 {
return dt_vlen2(a).sqrt();
dt_vlen2(a).sqrt()
}

#[inline]
pub fn dt_vlen2(a: &[f32; 3]) -> f32 {
return a[0] * a[0] + a[1] * a[1] + a[2] * a[2];
a[0] * a[0] + a[1] * a[1] + a[2] * a[2]
}

#[inline]
pub fn dt_vdist(a: &[f32; 3], b: &[f32; 3]) -> f32 {
return dt_vlen(&dt_vsub(a, b));
dt_vlen(&dt_vsub(a, b))
}

#[inline]
pub fn dt_vdist2(a: &[f32; 3], b: &[f32; 3]) -> f32 {
return dt_vlen2(&dt_vsub(a, b));
dt_vlen2(&dt_vsub(a, b))
}

#[inline]
pub fn dt_vdist_2d(a: &[f32; 3], b: &[f32; 3]) -> f32 {
return dt_vdist2_2d(a, b).sqrt();
dt_vdist2_2d(a, b).sqrt()
}

#[inline]
pub fn dt_vdist2_2d(a: &[f32; 3], b: &[f32; 3]) -> f32 {
let dx = a[0] - b[0];
let dz = a[2] - b[2];
return dx * dx + dz * dz;
dx * dx + dz * dz
}

#[inline]
pub fn dt_vnormalize(a: &[f32; 3]) -> [f32; 3] {
let d = 1.0 / dt_vlen(a);
return [a[0] * d, a[1] * d, a[2] * d];
[a[0] * d, a[1] * d, a[2] * d]
}

#[inline]
pub fn dt_visinf(a: &[f32; 3]) -> bool {
return a[0].is_infinite() && a[1].is_infinite() && a[2].is_infinite();
a[0].is_infinite() && a[1].is_infinite() && a[2].is_infinite()
}

#[inline]
pub fn dt_visinf_2d(a: &[f32; 3]) -> bool {
return a[0].is_infinite() && a[2].is_infinite();
a[0].is_infinite() && a[2].is_infinite()
}

#[inline]
pub fn dt_vperp_2d(a: &[f32; 3], b: &[f32; 3]) -> f32 {
return a[2] * b[0] - a[0] * b[2];
a[2] * b[0] - a[0] * b[2]
}

#[inline]
pub fn dt_tri_area_2d(a: &[f32; 3], b: &[f32; 3], c: &[f32; 3]) -> f32 {
let abx = b[0] - a[0];
let abz = b[2] - a[2];
let acx = c[0] - a[0];
let acz = c[2] - a[2];
return acx * abz - abx * acz;
acx * abz - abx * acz
}

#[inline]
pub fn dt_overlap_bounds(amin: &[i32; 3], amax: &[i32; 3], bmin: &[i32; 3], bmax: &[i32; 3]) -> bool {
let mut overlap = true;
overlap = if amin[0] > bmax[0] || amax[0] < bmin[0] {
Expand All @@ -221,5 +253,5 @@ pub fn dt_overlap_bounds(amin: &[i32; 3], amax: &[i32; 3], bmin: &[i32; 3], bmax
} else {
overlap
};
return overlap;
overlap
}
26 changes: 14 additions & 12 deletions src/detour/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ pub struct DtNavMeshCreateParams<'t> {
impl Debug for DtNavMeshCreateParams<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let cp = CxxDtNavMeshCreateParams::from(self);
return write!(f, "{:?}", cp);
write!(f, "{:?}", cp)
}
}

#[inline]
fn unpack_ptr<T>(v: Option<&[T]>) -> *const T {
return v.map(|v| v.as_ptr()).unwrap_or(std::ptr::null());
v.map(|v| v.as_ptr()).unwrap_or(std::ptr::null())
}

#[inline]
fn unpack_len<T>(v: Option<&[T]>) -> i32 {
return v.map(|v| v.len() as i32).unwrap_or(0);
v.map(|v| v.len() as i32).unwrap_or(0)
}

#[repr(C)]
Expand Down Expand Up @@ -129,7 +131,7 @@ unsafe impl ExternType for CxxDtNavMeshCreateParams {

impl CxxDtNavMeshCreateParams {
fn from(params: &DtNavMeshCreateParams<'_>) -> CxxDtNavMeshCreateParams {
return CxxDtNavMeshCreateParams {
CxxDtNavMeshCreateParams {
verts: unpack_ptr(params.verts) as *const _,
vert_count: unpack_len(params.verts),
polys: unpack_ptr(params.polys),
Expand Down Expand Up @@ -166,7 +168,7 @@ impl CxxDtNavMeshCreateParams {
ch: params.ch,

build_bv_tree: params.build_bv_tree,
};
}
}
}

Expand All @@ -193,10 +195,8 @@ pub fn dt_create_nav_mesh_data(params: &mut DtNavMeshCreateParams) -> RNResult<D
return Err(RNError::InvalidParam);
}

if cp.detail_meshes.is_null() {
if unpack_len(params.detail_meshes) != cp.poly_count {
return Err(RNError::InvalidParam);
}
if cp.detail_meshes.is_null() && unpack_len(params.detail_meshes) != cp.poly_count {
return Err(RNError::InvalidParam);
}

if unpack_len(params.off_mesh_con_rad) != cp.off_mesh_con_count {
Expand All @@ -221,22 +221,24 @@ pub fn dt_create_nav_mesh_data(params: &mut DtNavMeshCreateParams) -> RNResult<D
if !res {
return Err(RNError::Failed);
}
return Ok(buf);
Ok(buf)
}
}

#[inline]
pub fn dt_nav_mesh_header_swap_endian(buf: &mut DtBuf) -> RNResult<()> {
let res = unsafe { ffi::dtNavMeshHeaderSwapEndian(buf.data, buf.size) };
if !res {
return Err(RNError::Failed);
}
return Ok(());
Ok(())
}

#[inline]
pub fn dt_nav_mesh_data_swap_endian(buf: &mut DtBuf) -> RNResult<()> {
let res = unsafe { ffi::dtNavMeshDataSwapEndian(buf.data, buf.size) };
if !res {
return Err(RNError::Failed);
}
return Ok(());
Ok(())
}
Loading
Loading