add some #[inline] attributes to various math stuff
also switch away from #[inline(always)] to just #[inline]
This commit is contained in:
parent
e5fda9cb25
commit
4b91d494d0
|
@ -150,12 +150,14 @@ impl<PixelType: Pixel> Bitmap<PixelType> {
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `region`: the new clipping region
|
/// * `region`: the new clipping region
|
||||||
|
#[inline]
|
||||||
pub fn set_clip_region(&mut self, region: &Rect) {
|
pub fn set_clip_region(&mut self, region: &Rect) {
|
||||||
self.clip_region = *region;
|
self.clip_region = *region;
|
||||||
self.clip_region.clamp_to(&self.full_bounds());
|
self.clip_region.clamp_to(&self.full_bounds());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resets the bitmaps clipping region back to the default (full boundaries of the bitmap).
|
/// Resets the bitmaps clipping region back to the default (full boundaries of the bitmap).
|
||||||
|
#[inline]
|
||||||
pub fn reset_clip_region(&mut self) {
|
pub fn reset_clip_region(&mut self) {
|
||||||
self.clip_region = self.full_bounds();
|
self.clip_region = self.full_bounds();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
/// * `b`: the normalized blue component (0.0 to 1.0)
|
||||||
///
|
///
|
||||||
/// returns: the u32 packed color
|
/// returns: the u32 packed color
|
||||||
|
#[inline]
|
||||||
pub fn to_argb32_normalized(a: f32, r: f32, g: f32, b: f32) -> u32 {
|
pub fn to_argb32_normalized(a: f32, r: f32, g: f32, b: f32) -> u32 {
|
||||||
(((b * 255.0) as u32) & 0xff)
|
(((b * 255.0) as u32) & 0xff)
|
||||||
+ ((((g * 255.0) as u32) & 0xff) << 8)
|
+ ((((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
|
/// * `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
|
/// 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) {
|
pub fn from_argb32_normalized(argb: u32) -> (f32, f32, f32, f32) {
|
||||||
let a = ((argb & 0xff000000) >> 24) as f32 / 255.0;
|
let a = ((argb & 0xff000000) >> 24) as f32 / 255.0;
|
||||||
let r = ((argb & 0x00ff0000) >> 16) 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)
|
/// * `b`: the normalized blue component (0.0 to 1.0)
|
||||||
///
|
///
|
||||||
/// returns: the u32 packed color
|
/// returns: the u32 packed color
|
||||||
|
#[inline]
|
||||||
pub fn to_rgb32_normalized(r: f32, g: f32, b: f32) -> u32 {
|
pub fn to_rgb32_normalized(r: f32, g: f32, b: f32) -> u32 {
|
||||||
to_argb32_normalized(1.0, r, g, b)
|
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
|
/// * `argb`: the 32-bit packed color
|
||||||
///
|
///
|
||||||
/// returns: the individual ARGB normalized color components (0.0 to 1.0 each) in order: red, green, blue
|
/// 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) {
|
pub fn from_rgb32_normalized(rgb: u32) -> (f32, f32, f32) {
|
||||||
// ignore alpha component at 0xff000000 ...
|
// ignore alpha component at 0xff000000 ...
|
||||||
let r = ((rgb & 0x00ff0000) >> 16) as f32 / 255.0;
|
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.
|
/// alpha value used for blending the source and destination color's RGB components.
|
||||||
///
|
///
|
||||||
/// returns: the blended result
|
/// returns: the blended result
|
||||||
|
#[inline]
|
||||||
pub fn blend_source_by_value(src: u32, dest: u32, alpha: u8) -> u32 {
|
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 (src_a, src_r, src_g, src_b) = from_argb32(src);
|
||||||
let (dest_r, dest_g, dest_b) = from_rgb32(dest);
|
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
|
/// * `tint`: the tint to be applied to the color, where the alpha component represents the tint strength
|
||||||
///
|
///
|
||||||
/// returns: the resulting tinted color
|
/// returns: the resulting tinted color
|
||||||
|
#[inline]
|
||||||
pub fn tint_argb32(color: u32, tint: u32) -> u32 {
|
pub fn tint_argb32(color: u32, tint: u32) -> u32 {
|
||||||
let (color_a, color_r, color_g, color_b) = from_argb32(color);
|
let (color_a, color_r, color_g, color_b) = from_argb32(color);
|
||||||
let (tint_a, tint_r, tint_g, tint_b) = from_argb32(tint);
|
let (tint_a, tint_r, tint_g, tint_b) = from_argb32(tint);
|
||||||
|
|
|
@ -51,6 +51,7 @@ impl Circle {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the given point is contained within the bounds of this 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 {
|
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 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;
|
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.
|
/// Returns true if the given circle at least partially overlaps the bounds of this circle.
|
||||||
|
#[inline]
|
||||||
pub fn overlaps(&self, other: &Circle) -> bool {
|
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 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;
|
let minimum_distance_squared = ((self.radius + other.radius) * (self.radius + other.radius)) as f32;
|
||||||
|
|
|
@ -154,7 +154,7 @@ impl Matrix3x3 {
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `radians`: angle to rotate by (in radians)
|
/// * `radians`: angle to rotate by (in radians)
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn new_2d_rotation(radians: f32) -> Matrix3x3 {
|
pub fn new_2d_rotation(radians: f32) -> Matrix3x3 {
|
||||||
Matrix3x3::new_rotation_z(radians)
|
Matrix3x3::new_rotation_z(radians)
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ pub trait NearlyEqual {
|
||||||
impl NearlyEqual for f32 {
|
impl NearlyEqual for f32 {
|
||||||
type Output = f32;
|
type Output = f32;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn nearly_equal(self, other: Self::Output, epsilon: f32) -> bool {
|
fn nearly_equal(self, other: Self::Output, epsilon: f32) -> bool {
|
||||||
nearly_equal(self, other, epsilon)
|
nearly_equal(self, other, epsilon)
|
||||||
}
|
}
|
||||||
|
@ -171,6 +171,7 @@ pub trait WrappingRadians {
|
||||||
impl WrappingRadians for f32 {
|
impl WrappingRadians for f32 {
|
||||||
type Type = f32;
|
type Type = f32;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn wrapping_radians_add(self, other: Self::Type) -> Self::Type {
|
fn wrapping_radians_add(self, other: Self::Type) -> Self::Type {
|
||||||
let result = self + other;
|
let result = self + other;
|
||||||
if result < RADIANS_0 {
|
if result < RADIANS_0 {
|
||||||
|
@ -182,6 +183,7 @@ impl WrappingRadians for f32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn wrapping_radians_sub(self, other: Self::Type) -> Self::Type {
|
fn wrapping_radians_sub(self, other: Self::Type) -> Self::Type {
|
||||||
let result = self - other;
|
let result = self - other;
|
||||||
if result < RADIANS_0 {
|
if result < RADIANS_0 {
|
||||||
|
|
|
@ -23,6 +23,7 @@ impl Rect {
|
||||||
/// * `top`: the top y coordinate
|
/// * `top`: the top y coordinate
|
||||||
/// * `right`: the right x coordinate
|
/// * `right`: the right x coordinate
|
||||||
/// * `bottom`: the bottom y coordinate
|
/// * `bottom`: the bottom y coordinate
|
||||||
|
#[inline]
|
||||||
pub fn from_coords(left: i32, top: i32, right: i32, bottom: i32) -> Rect {
|
pub fn from_coords(left: i32, top: i32, right: i32, bottom: i32) -> Rect {
|
||||||
let x;
|
let x;
|
||||||
let y;
|
let y;
|
||||||
|
@ -53,6 +54,7 @@ impl Rect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn set_from_coords(&mut self, left: i32, top: i32, right: i32, bottom: i32) {
|
pub fn set_from_coords(&mut self, left: i32, top: i32, right: i32, bottom: i32) {
|
||||||
if left <= right {
|
if left <= right {
|
||||||
self.x = left;
|
self.x = left;
|
||||||
|
@ -92,11 +94,13 @@ impl Rect {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the given point is contained within the bounds of this 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 {
|
pub fn contains_point(&self, x: i32, y: i32) -> bool {
|
||||||
(self.x <= x) && (self.right() >= x) && (self.y <= y) && (self.bottom() >= y)
|
(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.
|
/// Returns true if the given rect is contained completely within the bounds of this rect.
|
||||||
|
#[inline]
|
||||||
pub fn contains_rect(&self, other: &Rect) -> bool {
|
pub fn contains_rect(&self, other: &Rect) -> bool {
|
||||||
(other.x >= self.x && other.x < self.right())
|
(other.x >= self.x && other.x < self.right())
|
||||||
&& (other.right() > self.x && other.right() <= 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.
|
/// Returns true if the given rect at least partially overlaps the bounds of this rect.
|
||||||
|
#[inline]
|
||||||
pub fn overlaps(&self, other: &Rect) -> bool {
|
pub fn overlaps(&self, other: &Rect) -> bool {
|
||||||
(self.x <= other.right())
|
(self.x <= other.right())
|
||||||
&& (self.right() >= other.x)
|
&& (self.right() >= other.x)
|
||||||
|
|
|
@ -65,6 +65,7 @@ impl Vector2 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a normalized vector from this vector.
|
/// Returns a normalized vector from this vector.
|
||||||
|
#[inline]
|
||||||
pub fn normalize(&self) -> Vector2 {
|
pub fn normalize(&self) -> Vector2 {
|
||||||
let inverse_length = 1.0 / self.length();
|
let inverse_length = 1.0 / self.length();
|
||||||
Vector2 {
|
Vector2 {
|
||||||
|
@ -75,6 +76,7 @@ impl Vector2 {
|
||||||
|
|
||||||
/// Returns an extended (or shrunk) vector from this vector, where the returned vector will
|
/// 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.
|
/// have a length exactly matching the specified length, but will retain the same direction.
|
||||||
|
#[inline]
|
||||||
pub fn extend(&self, length: f32) -> Vector2 {
|
pub fn extend(&self, length: f32) -> Vector2 {
|
||||||
*self * (length / self.length())
|
*self * (length / self.length())
|
||||||
}
|
}
|
||||||
|
@ -233,7 +235,7 @@ impl DivAssign<f32> for Vector2 {
|
||||||
impl NearlyEqual for Vector2 {
|
impl NearlyEqual for Vector2 {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
fn nearly_equal(self, other: Self::Output, epsilon: f32) -> bool {
|
fn nearly_equal(self, other: Self::Output, epsilon: f32) -> bool {
|
||||||
nearly_equal(self.x, other.x, epsilon) && nearly_equal(self.y, other.y, epsilon)
|
nearly_equal(self.x, other.x, epsilon) && nearly_equal(self.y, other.y, epsilon)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue