-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
362 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use super::ClassId; | ||
|
||
impl From<u16> for ClassId { | ||
fn from(value: u16) -> Self { | ||
Self(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use super::Color; | ||
|
||
impl Color { | ||
#[inline] | ||
pub fn from_rgb(r: u8, g: u8, b: u8) -> Self { | ||
Self::from([r, g, b, 255]) | ||
} | ||
|
||
#[inline] | ||
pub fn from_unmultiplied_rgba(r: u8, g: u8, b: u8, a: u8) -> Self { | ||
Self::from([r, g, b, a]) | ||
} | ||
|
||
#[inline] | ||
pub fn to_array(&self) -> [u8; 4] { | ||
[ | ||
(self.0 >> 24) as u8, | ||
(self.0 >> 16) as u8, | ||
(self.0 >> 8) as u8, | ||
self.0 as u8, | ||
] | ||
} | ||
} | ||
|
||
impl From<u32> for Color { | ||
#[inline] | ||
fn from(c: u32) -> Self { | ||
Self(c) | ||
} | ||
} | ||
|
||
impl From<[u8; 4]> for Color { | ||
#[inline] | ||
fn from(bytes: [u8; 4]) -> Self { | ||
Self( | ||
(bytes[0] as u32) << 24 | ||
| (bytes[1] as u32) << 16 | ||
| (bytes[2] as u32) << 8 | ||
| (bytes[3] as u32), | ||
) | ||
} | ||
} | ||
|
||
#[cfg(feature = "ecolor")] | ||
impl From<Color> for ecolor::Color32 { | ||
fn from(color: Color) -> Self { | ||
let [r, g, b, a] = color.to_array(); | ||
Self::from_rgba_premultiplied(r, g, b, a) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use super::DrawOrder; | ||
|
||
// TODO(cmc): come up with some DSL in our flatbuffers definitions so that we can declare these | ||
// constants directly in there. | ||
impl DrawOrder { | ||
/// Draw order used for images if no draw order was specified. | ||
pub const DEFAULT_IMAGE: DrawOrder = DrawOrder(-10.0); | ||
|
||
/// Draw order used for 2D boxes if no draw order was specified. | ||
pub const DEFAULT_BOX2D: DrawOrder = DrawOrder(10.0); | ||
|
||
/// Draw order used for 2D lines if no draw order was specified. | ||
pub const DEFAULT_LINES2D: DrawOrder = DrawOrder(20.0); | ||
|
||
/// Draw order used for 2D points if no draw order was specified. | ||
pub const DEFAULT_POINTS2D: DrawOrder = DrawOrder(30.0); | ||
} | ||
|
||
impl std::cmp::PartialEq for DrawOrder { | ||
#[inline] | ||
fn eq(&self, other: &Self) -> bool { | ||
self.0.is_nan() && other.0.is_nan() || self.0 == other.0 | ||
} | ||
} | ||
|
||
impl std::cmp::Eq for DrawOrder {} | ||
|
||
impl std::cmp::PartialOrd for DrawOrder { | ||
#[inline] | ||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { | ||
if other == self { | ||
Some(std::cmp::Ordering::Equal) | ||
} else if other.0.is_nan() || self.0 < other.0 { | ||
Some(std::cmp::Ordering::Less) | ||
} else { | ||
Some(std::cmp::Ordering::Greater) | ||
} | ||
} | ||
} | ||
|
||
impl std::cmp::Ord for DrawOrder { | ||
#[inline] | ||
fn cmp(&self, other: &Self) -> std::cmp::Ordering { | ||
self.partial_cmp(other).unwrap() | ||
} | ||
} | ||
|
||
impl From<f32> for DrawOrder { | ||
#[inline] | ||
fn from(value: f32) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl From<DrawOrder> for f32 { | ||
#[inline] | ||
fn from(value: DrawOrder) -> Self { | ||
value.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use super::InstanceKey; | ||
|
||
// TODO(cmc): come up with some DSL in our flatbuffers definitions so that we can declare these | ||
// constants directly in there. | ||
impl InstanceKey { | ||
/// Draw order used for images if no draw order was specified. | ||
pub const SPLAT: Self = Self(u64::MAX); | ||
} | ||
|
||
impl From<u64> for InstanceKey { | ||
#[inline] | ||
fn from(value: u64) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl From<InstanceKey> for u64 { | ||
#[inline] | ||
fn from(value: InstanceKey) -> Self { | ||
value.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use super::KeypointId; | ||
|
||
impl From<u16> for KeypointId { | ||
fn from(value: u16) -> Self { | ||
Self(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use super::Label; | ||
|
||
impl Label { | ||
#[inline] | ||
pub fn as_str(&self) -> &str { | ||
self.0.as_str() | ||
} | ||
} | ||
|
||
impl From<String> for Label { | ||
#[inline] | ||
fn from(value: String) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl From<&str> for Label { | ||
#[inline] | ||
fn from(value: &str) -> Self { | ||
Self(value.to_owned()) | ||
} | ||
} | ||
|
||
impl From<Label> for String { | ||
#[inline] | ||
fn from(value: Label) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
impl AsRef<str> for Label { | ||
#[inline] | ||
fn as_ref(&self) -> &str { | ||
self.as_str() | ||
} | ||
} | ||
|
||
impl std::borrow::Borrow<str> for Label { | ||
#[inline] | ||
fn borrow(&self) -> &str { | ||
self.as_str() | ||
} | ||
} | ||
|
||
impl std::ops::Deref for Label { | ||
type Target = str; | ||
#[inline] | ||
fn deref(&self) -> &str { | ||
self.as_str() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use super::Point2D; | ||
|
||
impl Point2D { | ||
pub const ZERO: Self = Self::new(0.0, 0.0); | ||
pub const ONE: Self = Self::new(1.0, 1.0); | ||
|
||
#[inline] | ||
pub const fn new(x: f32, y: f32) -> Self { | ||
Self(crate::datatypes::Vec2D::new(x, y)) | ||
} | ||
} | ||
|
||
impl std::ops::Deref for Point2D { | ||
type Target = crate::datatypes::Vec2D; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl From<(f32, f32)> for Point2D { | ||
#[inline] | ||
fn from(xy: (f32, f32)) -> Self { | ||
Self(xy.into()) | ||
} | ||
} | ||
|
||
impl From<[f32; 2]> for Point2D { | ||
#[inline] | ||
fn from(p: [f32; 2]) -> Self { | ||
Self(p.into()) | ||
} | ||
} | ||
|
||
#[cfg(feature = "glam")] | ||
impl From<glam::Vec2> for Point2D { | ||
#[inline] | ||
fn from(pt: glam::Vec2) -> Self { | ||
Self::new(pt.x, pt.y) | ||
} | ||
} | ||
|
||
#[cfg(feature = "glam")] | ||
impl From<Point2D> for glam::Vec2 { | ||
#[inline] | ||
fn from(pt: Point2D) -> Self { | ||
Self::new(pt.x(), pt.y()) | ||
} | ||
} | ||
|
||
#[cfg(feature = "glam")] | ||
impl From<Point2D> for glam::Vec3 { | ||
#[inline] | ||
fn from(pt: Point2D) -> Self { | ||
Self::new(pt.x(), pt.y(), 0.0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use super::Radius; | ||
|
||
impl Radius { | ||
pub const ZERO: Self = Self::new(0.0); | ||
pub const ONE: Self = Self::new(1.0); | ||
|
||
#[inline] | ||
pub const fn new(r: f32) -> Self { | ||
Self(r) | ||
} | ||
} | ||
|
||
impl From<f32> for Radius { | ||
#[inline] | ||
fn from(r: f32) -> Self { | ||
Self::new(r) | ||
} | ||
} | ||
|
||
impl std::fmt::Display for Radius { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{:.prec$}", self.0, prec = crate::DISPLAY_PRECISION,) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
// NOTE: This file was autogenerated by re_types_builder; DO NOT EDIT. | ||
|
||
mod vec2d; | ||
mod vec2d_ext; | ||
|
||
pub use self::vec2d::Vec2D; |
Oops, something went wrong.