diff --git a/ggdt/src/graphics/bitmap/mod.rs b/ggdt/src/graphics/bitmap/mod.rs index 782065c..78ad678 100644 --- a/ggdt/src/graphics/bitmap/mod.rs +++ b/ggdt/src/graphics/bitmap/mod.rs @@ -150,12 +150,14 @@ impl Bitmap { /// # Arguments /// /// * `region`: the new clipping region + #[inline] pub fn set_clip_region(&mut self, region: &Rect) { self.clip_region = *region; self.clip_region.clamp_to(&self.full_bounds()); } /// Resets the bitmaps clipping region back to the default (full boundaries of the bitmap). + #[inline] pub fn reset_clip_region(&mut self) { self.clip_region = self.full_bounds(); } diff --git a/ggdt/src/graphics/color.rs b/ggdt/src/graphics/color.rs index 45b17a2..1c9ba09 100644 --- a/ggdt/src/graphics/color.rs +++ b/ggdt/src/graphics/color.rs @@ -76,6 +76,7 @@ pub fn to_argb32(a: u8, r: u8, g: u8, b: u8) -> u32 { /// * `b`: the normalized blue component (0.0 to 1.0) /// /// returns: the u32 packed color +#[inline] pub fn to_argb32_normalized(a: f32, r: f32, g: f32, b: f32) -> u32 { (((b * 255.0) as u32) & 0xff) + ((((g * 255.0) as u32) & 0xff) << 8) @@ -108,6 +109,7 @@ pub fn from_argb32(argb: u32) -> (u8, u8, u8, u8) { /// * `argb`: the 32-bit packed color /// /// returns: the individual ARGB normalized color components (0.0 to 1.0 each) in order: alpha, red, green, blue +#[inline] pub fn from_argb32_normalized(argb: u32) -> (f32, f32, f32, f32) { let a = ((argb & 0xff000000) >> 24) as f32 / 255.0; let r = ((argb & 0x00ff0000) >> 16) as f32 / 255.0; @@ -141,6 +143,7 @@ pub fn to_rgb32(r: u8, g: u8, b: u8) -> u32 { /// * `b`: the normalized blue component (0.0 to 1.0) /// /// returns: the u32 packed color +#[inline] pub fn to_rgb32_normalized(r: f32, g: f32, b: f32) -> u32 { to_argb32_normalized(1.0, r, g, b) } @@ -170,6 +173,7 @@ pub fn from_rgb32(rgb: u32) -> (u8, u8, u8) { /// * `argb`: the 32-bit packed color /// /// returns: the individual ARGB normalized color components (0.0 to 1.0 each) in order: red, green, blue +#[inline] pub fn from_rgb32_normalized(rgb: u32) -> (f32, f32, f32) { // ignore alpha component at 0xff000000 ... let r = ((rgb & 0x00ff0000) >> 16) as f32 / 255.0; @@ -234,6 +238,7 @@ pub fn blend_argb32(src: u32, dest: u32) -> u32 { /// alpha value used for blending the source and destination color's RGB components. /// /// returns: the blended result +#[inline] pub fn blend_source_by_value(src: u32, dest: u32, alpha: u8) -> u32 { let (src_a, src_r, src_g, src_b) = from_argb32(src); let (dest_r, dest_g, dest_b) = from_rgb32(dest); @@ -257,6 +262,7 @@ pub fn blend_source_by_value(src: u32, dest: u32, alpha: u8) -> u32 { /// * `tint`: the tint to be applied to the color, where the alpha component represents the tint strength /// /// returns: the resulting tinted color +#[inline] pub fn tint_argb32(color: u32, tint: u32) -> u32 { let (color_a, color_r, color_g, color_b) = from_argb32(color); let (tint_a, tint_r, tint_g, tint_b) = from_argb32(tint); diff --git a/ggdt/src/math/circle.rs b/ggdt/src/math/circle.rs index bae666e..4ada1a2 100644 --- a/ggdt/src/math/circle.rs +++ b/ggdt/src/math/circle.rs @@ -51,6 +51,7 @@ impl Circle { } /// Returns true if the given point is contained within the bounds of this circle. + #[inline] pub fn contains_point(&self, x: i32, y: i32) -> bool { let distance_squared = distance_squared_between(self.x as f32, self.y as f32, x as f32, y as f32); let radius_squared = (self.radius * self.radius) as f32; @@ -58,6 +59,7 @@ impl Circle { } /// Returns true if the given circle at least partially overlaps the bounds of this circle. + #[inline] pub fn overlaps(&self, other: &Circle) -> bool { let distance_squared = distance_squared_between(self.x as f32, self.y as f32, other.x as f32, other.y as f32); let minimum_distance_squared = ((self.radius + other.radius) * (self.radius + other.radius)) as f32; diff --git a/ggdt/src/math/matrix3x3.rs b/ggdt/src/math/matrix3x3.rs index ca4040a..c3be16f 100644 --- a/ggdt/src/math/matrix3x3.rs +++ b/ggdt/src/math/matrix3x3.rs @@ -154,7 +154,7 @@ impl Matrix3x3 { /// # Arguments /// /// * `radians`: angle to rotate by (in radians) - #[inline(always)] + #[inline] pub fn new_2d_rotation(radians: f32) -> Matrix3x3 { Matrix3x3::new_rotation_z(radians) } diff --git a/ggdt/src/math/mod.rs b/ggdt/src/math/mod.rs index ea61042..60912c9 100644 --- a/ggdt/src/math/mod.rs +++ b/ggdt/src/math/mod.rs @@ -150,7 +150,7 @@ pub trait NearlyEqual { impl NearlyEqual for f32 { type Output = f32; - #[inline(always)] + #[inline] fn nearly_equal(self, other: Self::Output, epsilon: f32) -> bool { nearly_equal(self, other, epsilon) } @@ -171,6 +171,7 @@ pub trait WrappingRadians { impl WrappingRadians for f32 { type Type = f32; + #[inline] fn wrapping_radians_add(self, other: Self::Type) -> Self::Type { let result = self + other; if result < RADIANS_0 { @@ -182,6 +183,7 @@ impl WrappingRadians for f32 { } } + #[inline] fn wrapping_radians_sub(self, other: Self::Type) -> Self::Type { let result = self - other; if result < RADIANS_0 { diff --git a/ggdt/src/math/rect.rs b/ggdt/src/math/rect.rs index fe632b2..458acc2 100644 --- a/ggdt/src/math/rect.rs +++ b/ggdt/src/math/rect.rs @@ -23,6 +23,7 @@ impl Rect { /// * `top`: the top y coordinate /// * `right`: the right x coordinate /// * `bottom`: the bottom y coordinate + #[inline] pub fn from_coords(left: i32, top: i32, right: i32, bottom: i32) -> Rect { let x; let y; @@ -53,6 +54,7 @@ impl Rect { } } + #[inline] pub fn set_from_coords(&mut self, left: i32, top: i32, right: i32, bottom: i32) { if left <= right { self.x = left; @@ -92,11 +94,13 @@ impl Rect { } /// Returns true if the given point is contained within the bounds of this rect. + #[inline] pub fn contains_point(&self, x: i32, y: i32) -> bool { (self.x <= x) && (self.right() >= x) && (self.y <= y) && (self.bottom() >= y) } /// Returns true if the given rect is contained completely within the bounds of this rect. + #[inline] pub fn contains_rect(&self, other: &Rect) -> bool { (other.x >= self.x && other.x < self.right()) && (other.right() > self.x && other.right() <= self.right()) @@ -105,6 +109,7 @@ impl Rect { } /// Returns true if the given rect at least partially overlaps the bounds of this rect. + #[inline] pub fn overlaps(&self, other: &Rect) -> bool { (self.x <= other.right()) && (self.right() >= other.x) diff --git a/ggdt/src/math/vector2.rs b/ggdt/src/math/vector2.rs index 6c8f7ae..62413bf 100644 --- a/ggdt/src/math/vector2.rs +++ b/ggdt/src/math/vector2.rs @@ -65,6 +65,7 @@ impl Vector2 { } /// Returns a normalized vector from this vector. + #[inline] pub fn normalize(&self) -> Vector2 { let inverse_length = 1.0 / self.length(); Vector2 { @@ -75,6 +76,7 @@ impl Vector2 { /// Returns an extended (or shrunk) vector from this vector, where the returned vector will /// have a length exactly matching the specified length, but will retain the same direction. + #[inline] pub fn extend(&self, length: f32) -> Vector2 { *self * (length / self.length()) } @@ -233,7 +235,7 @@ impl DivAssign for Vector2 { impl NearlyEqual for Vector2 { type Output = Self; - #[inline(always)] + #[inline] fn nearly_equal(self, other: Self::Output, epsilon: f32) -> bool { nearly_equal(self.x, other.x, epsilon) && nearly_equal(self.y, other.y, epsilon) }