Skip to content
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

Remove types.rs and move its types into the relevant files. #963

Merged
merged 2 commits into from Mar 7, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Missing color.rs.

  • Loading branch information
nical committed Mar 6, 2017
commit 0c5575d7b95699a51cbb7bba4bf077e4e6eb64af
@@ -0,0 +1,64 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub struct ColorF {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}
known_heap_size!(0, ColorF);

#[repr(C)]
#[derive(Clone, Copy, Hash, Eq, Debug, Deserialize, PartialEq, PartialOrd, Ord, Serialize)]
pub struct ColorU {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}

impl From<ColorF> for ColorU {
fn from(color: ColorF) -> ColorU {
ColorU {
r: ColorU::round_to_int(color.r),
g: ColorU::round_to_int(color.g),
b: ColorU::round_to_int(color.b),
a: ColorU::round_to_int(color.a),
}
}
}

impl Into<ColorF> for ColorU {
fn into(self) -> ColorF {
ColorF {
r: self.r as f32 / 255.0,
g: self.g as f32 / 255.0,
b: self.b as f32 / 255.0,
a: self.a as f32 / 255.0,
}
}
}

impl ColorU {
fn round_to_int(x: f32) -> u8 {
debug_assert!((0.0 <= x) && (x <= 1.0));
let f = (255.0 * x) + 0.5;
let val = f.floor();
debug_assert!(val <= 255.0);
val as u8
}

pub fn new(r: u8, g: u8, b: u8, a: u8) -> ColorU {
ColorU {
r: r,
g: g,
b: b,
a: a,
}
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.