feat: base colorizer project

This commit is contained in:
2025-08-10 00:18:27 +02:00
commit 2e125ac301
13 changed files with 390 additions and 0 deletions

View File

@@ -0,0 +1 @@
pub mod ranged;

View File

@@ -0,0 +1,78 @@
use super::*;
use std::{
cmp::Ordering,
ops::{Add, Div, Mul, Sub},
};
impl<const LOW: BaseNumber, const HIGH: BaseNumber> PartialEq<BaseNumber>
for RangedInt<{ LOW }, { HIGH }>
{
fn eq(&self, other: &BaseNumber) -> bool {
self.0 == *other
}
fn ne(&self, other: &BaseNumber) -> bool {
self.0 != *other
}
}
impl<const LOW: BaseNumber, const HIGH: BaseNumber> PartialOrd<BaseNumber>
for RangedInt<{ LOW }, { HIGH }>
{
fn partial_cmp(&self, other: &BaseNumber) -> Option<Ordering> {
self.0.partial_cmp(other)
}
fn ge(&self, other: &BaseNumber) -> bool {
self.0 >= *other
}
fn le(&self, other: &BaseNumber) -> bool {
self.0 <= *other
}
fn gt(&self, other: &BaseNumber) -> bool {
self.0 > *other
}
fn lt(&self, other: &BaseNumber) -> bool {
self.0 < *other
}
}
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Add<BaseNumber>
for RangedInt<{ LOW }, { HIGH }>
{
type Output = BaseNumber;
fn add(self, rhs: BaseNumber) -> Self::Output {
self.0 + rhs
}
}
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Sub<BaseNumber>
for RangedInt<{ LOW }, { HIGH }>
{
type Output = BaseNumber;
fn sub(self, rhs: BaseNumber) -> Self::Output {
self.0 - rhs
}
}
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Div<BaseNumber>
for RangedInt<{ LOW }, { HIGH }>
{
type Output = BaseNumber;
fn div(self, rhs: BaseNumber) -> Self::Output {
self.0 / rhs
}
}
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Mul<BaseNumber>
for RangedInt<{ LOW }, { HIGH }>
{
type Output = BaseNumber;
fn mul(self, rhs: BaseNumber) -> Self::Output {
self.0 * rhs
}
}

View File

@@ -0,0 +1,16 @@
mod foreign_operations;
mod self_operations;
pub type BaseNumber = i16;
#[derive(Eq, Clone)]
pub struct RangedInt<const LOW: BaseNumber, const HIGH: BaseNumber>(BaseNumber);
impl<const LOW: BaseNumber, const HIGH: BaseNumber> RangedInt<{ LOW }, { HIGH }> {
pub const LOW: BaseNumber = LOW;
pub const HIGH: BaseNumber = HIGH;
pub fn new(number: BaseNumber) -> Self {
Self(number.min(Self::HIGH).max(Self::LOW))
}
}

View File

@@ -0,0 +1,66 @@
use super::*;
use std::{
cmp::Ordering,
ops::{Add, Div, Mul, Sub},
};
impl<const LOW: BaseNumber, const HIGH: BaseNumber> PartialEq for RangedInt<{ LOW }, { HIGH }> {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
fn ne(&self, other: &Self) -> bool {
self.0 != other.0
}
}
impl<const LOW: BaseNumber, const HIGH: BaseNumber> PartialOrd for RangedInt<{ LOW }, { HIGH }> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.0.partial_cmp(&other.0)
}
fn ge(&self, other: &Self) -> bool {
self.0 >= other.0
}
fn le(&self, other: &Self) -> bool {
self.0 <= other.0
}
fn gt(&self, other: &Self) -> bool {
self.0 > other.0
}
fn lt(&self, other: &Self) -> bool {
self.0 < other.0
}
}
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Add for RangedInt<{ LOW }, { HIGH }> {
type Output = BaseNumber;
fn add(self, rhs: Self) -> Self::Output {
self.0 + rhs.0
}
}
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Sub for RangedInt<{ LOW }, { HIGH }> {
type Output = BaseNumber;
fn sub(self, rhs: Self) -> Self::Output {
self.0 - rhs.0
}
}
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Div for RangedInt<{ LOW }, { HIGH }> {
type Output = BaseNumber;
fn div(self, rhs: Self) -> Self::Output {
self.0 / rhs.0
}
}
impl<const LOW: BaseNumber, const HIGH: BaseNumber> Mul for RangedInt<{ LOW }, { HIGH }> {
type Output = BaseNumber;
fn mul(self, rhs: Self) -> Self::Output {
self.0 * rhs.0
}
}

20
colorizer/src/main.rs Normal file
View File

@@ -0,0 +1,20 @@
use clipboard::ClipboardContext;
use clipboard::ClipboardProvider;
pub mod core;
mod transmuter;
#[cfg(test)]
#[path = "./test/transmuter.test.rs"]
mod test;
fn example() {
let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
println!("{:?}", ctx.get_contents());
ctx.set_contents("some string".to_owned()).unwrap();
}
fn main() {
println!("Hello, world!");
example();
}

View File

@@ -0,0 +1,8 @@
#[cfg(test)]
pub mod tests {
#[test]
fn test_success() {
let my_hello = "Hello world!";
assert_eq!(my_hello, "Hello world!");
}
}

View File

@@ -0,0 +1,60 @@
use std::convert::From;
use crate::core::ranged::{BaseNumber, RangedInt};
type ColorIntensity = RangedInt<0, 255>;
struct RGB(ColorIntensity, ColorIntensity, ColorIntensity);
struct HSL(RangedInt<0, 360>, RangedInt<0, 100>, RangedInt<0, 100>);
struct HSV(RangedInt<0, 360>, RangedInt<0, 100>, RangedInt<0, 100>);
pub struct Color(RGB);
impl Color {}
impl RGB {
fn new(r: u8, g: u8, b: u8) -> Self {
Self(
ColorIntensity::new(r as BaseNumber),
ColorIntensity::new(g as BaseNumber),
ColorIntensity::new(b as BaseNumber),
)
}
}
impl From<RGB> for Color {
fn from(color: RGB) -> Self {
Self(color)
}
}
impl From<HSL> for Color {
fn from(color: HSL) -> Self {
Color(RGB::from(color))
}
}
impl From<HSL> for RGB {
fn from(color: HSL) -> Self {
// No saturation
if color.1 == 0 {
let shade = color.2 / 100 * 255;
let intensity = ColorIntensity::new(shade);
return Self(intensity.clone(), intensity.clone(), intensity.clone());
}
let mut temp_1: i16 = 0;
if color.2 < 50 {
// Low lum
temp_1 = color.2.clone() * (color.1 + 100);
} else {
// High lum
temp_1 = color.2.clone() + color.1.clone() - color.2.clone() * color.1.clone();
}
let temp_2: i16 = color.2 * 2 - temp_1;
let hue = (color.0.clone() / 360) * 100;
Self::new(0, 0, 0)
}
}

View File

@@ -0,0 +1,2 @@
mod colors;
mod parsers;

View File

@@ -0,0 +1 @@