-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Populate first draft of color crate (#3)
This is copied from Raph's "koloro" local repository, with lots of fiddly changes to satisfy clippy.
- Loading branch information
Showing
13 changed files
with
2,048 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,50 @@ | ||
// Copyright 2024 the Color Authors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! A simple bitset. | ||
/// A simple bitset, for representing missing components. | ||
#[derive(Default, Clone, Copy, PartialEq, Eq, Debug)] | ||
pub struct Bitset(u8); | ||
|
||
impl Bitset { | ||
pub fn contains(self, ix: usize) -> bool { | ||
(self.0 & (1 << ix)) != 0 | ||
} | ||
|
||
pub fn set(&mut self, ix: usize) { | ||
self.0 |= 1 << ix; | ||
} | ||
|
||
pub fn single(ix: usize) -> Self { | ||
Self(1 << ix) | ||
} | ||
|
||
pub fn any(self) -> bool { | ||
self.0 != 0 | ||
} | ||
} | ||
|
||
impl core::ops::BitAnd for Bitset { | ||
type Output = Self; | ||
|
||
fn bitand(self, rhs: Self) -> Self { | ||
Self(self.0 & rhs.0) | ||
} | ||
} | ||
|
||
impl core::ops::BitOr for Bitset { | ||
type Output = Self; | ||
|
||
fn bitor(self, rhs: Self) -> Self { | ||
Self(self.0 | rhs.0) | ||
} | ||
} | ||
|
||
impl core::ops::Not for Bitset { | ||
type Output = Self; | ||
|
||
fn not(self) -> Self::Output { | ||
Self(!self.0) | ||
} | ||
} |
Oops, something went wrong.