fix clippy lints

This commit is contained in:
Robin Appelman 2020-05-01 23:54:16 +02:00
commit 1607b851c5
3 changed files with 16 additions and 13 deletions

View file

@ -11,8 +11,10 @@ use euclid::{TypedPoint2D, TypedRect, TypedSize2D};
mod navmesh;
mod parser;
type Rect = TypedRect<f32, HammerUnit>;
/// A tree of all navigation areas
pub struct NavTree(QuadTree<NavArea, HammerUnit, [(ItemId, TypedRect<f32, HammerUnit>); 4]>);
pub struct NavTree(QuadTree<NavArea, HammerUnit, [(ItemId, Rect); 4]>);
/// Parse all navigation areas from a nav file
///
@ -43,7 +45,7 @@ pub fn get_area_tree(data: Vec<u8>) -> Result<NavTree, ParseError> {
);
let mut tree = QuadTree::default(
TypedRect::new(
Rect::new(
TypedPoint2D::new(min_x - 1.0, min_y - 1.0),
TypedSize2D::new(max_x - min_x + 2.0, max_y - min_y + 2.0),
),
@ -73,7 +75,7 @@ impl NavTree {
/// # }
/// ```
pub fn query(&self, x: f32, y: f32) -> impl Iterator<Item = &NavArea> {
let query_box = TypedRect::new(TypedPoint2D::new(x, y), TypedSize2D::new(1.0, 1.0));
let query_box = Rect::new(TypedPoint2D::new(x, y), TypedSize2D::new(1.0, 1.0));
self.0.query(query_box).into_iter().map(|(area, ..)| area)
}

View file

@ -1,6 +1,7 @@
use crate::Rect;
use aabb_quadtree::Spatial;
use bitbuffer::{BitRead, BitReadStream, Endianness, ReadError};
use euclid::{TypedPoint2D, TypedRect, TypedSize2D};
use euclid::{TypedPoint2D, TypedSize2D};
use std::fmt;
use std::fmt::Debug;
use std::ops::Index;
@ -84,8 +85,8 @@ impl NavArea {
pub(crate) struct HammerUnit;
impl Spatial<HammerUnit> for NavArea {
fn aabb(&self) -> TypedRect<f32, HammerUnit> {
TypedRect {
fn aabb(&self) -> Rect {
Rect {
origin: TypedPoint2D::new(self.north_west.0, self.north_west.1),
size: TypedSize2D::new(
self.south_east.0 - self.north_west.0,
@ -120,11 +121,11 @@ impl<E: Endianness> BitRead<E> for Connections {
fn read(stream: &mut BitReadStream<E>) -> Result<Self, ReadError> {
let mut connections = [Vec::new(), Vec::new(), Vec::new(), Vec::new()];
for direction in 0..4 {
for direction in connections.iter_mut() {
let connection_count: u32 = stream.read()?;
connections[direction] = Vec::with_capacity(connection_count as usize);
direction.reserve(connection_count as usize);
for _ in 0..connection_count {
connections[direction].push(stream.read()?);
direction.push(stream.read()?);
}
}
@ -165,11 +166,11 @@ impl<E: Endianness> BitRead<E> for LadderConnections {
fn read(stream: &mut BitReadStream<E>) -> Result<Self, ReadError> {
let mut connections = [Vec::new(), Vec::new()];
for direction in 0..2 {
for direction in connections.iter_mut() {
let connection_count: u32 = stream.read()?;
connections[direction] = Vec::with_capacity(connection_count as usize);
direction.reserve(connection_count as usize);
for _ in 0..connection_count {
connections[direction].push(stream.read()?);
direction.push(stream.read()?);
}
}

View file

@ -22,7 +22,7 @@ pub enum ParseError {
pub(crate) fn read_areas(data: Vec<u8>) -> Result<Vec<NavArea>, ParseError> {
let mut data = BitReadStream::new(BitReadBuffer::new(data, LittleEndian));
let magic = data.read()?;
if magic != 0xFEEDFACE {
if magic != 0xFEED_FACE {
return Err(ParseError::InvalidMagicNumber(magic));
}