增加部分结构的构造函数。

This commit is contained in:
徐涛
2025-02-10 14:31:32 +08:00
parent 88e3d1f928
commit f944d48e1b
10 changed files with 371 additions and 204 deletions

View File

@@ -12,6 +12,18 @@ pub struct HctDiffference {
pub lightness: Differ,
}
#[wasm_bindgen]
impl HctDiffference {
#[wasm_bindgen(constructor)]
pub fn new(hue: Differ, chroma: Differ, lightness: Differ) -> Self {
Self {
hue,
chroma,
lightness,
}
}
}
impl ColorDifference for Cam16Jch<f32> {
type Difference = HctDiffference;

View File

@@ -12,6 +12,18 @@ pub struct HSLDifference {
pub lightness: Differ,
}
#[wasm_bindgen]
impl HSLDifference {
#[wasm_bindgen(constructor)]
pub fn new(hue: Differ, saturation: Differ, lightness: Differ) -> Self {
Self {
hue,
saturation,
lightness,
}
}
}
impl ColorDifference for Hsl {
type Difference = HSLDifference;

View File

@@ -13,6 +13,14 @@ pub struct Differ {
pub percent: f32,
}
#[wasm_bindgen]
impl Differ {
#[wasm_bindgen(constructor)]
pub fn new(delta: f32, percent: f32) -> Self {
Self { delta, percent }
}
}
pub trait ColorDifference {
type Difference;

View File

@@ -12,6 +12,18 @@ pub struct OklchDifference {
pub lightness: Differ,
}
#[wasm_bindgen]
impl OklchDifference {
#[wasm_bindgen(constructor)]
pub fn new(hue: Differ, chroma: Differ, lightness: Differ) -> Self {
Self {
hue,
chroma,
lightness,
}
}
}
impl ColorDifference for Oklch {
type Difference = OklchDifference;

View File

@@ -12,6 +12,14 @@ pub struct RGBDifference {
pub b: Differ,
}
#[wasm_bindgen]
impl RGBDifference {
#[wasm_bindgen(constructor)]
pub fn new(r: Differ, g: Differ, b: Differ) -> Self {
Self { r, g, b }
}
}
impl ColorDifference for Srgb {
type Difference = RGBDifference;

View File

@@ -11,6 +11,19 @@ pub struct MixReversing {
pub average: f32,
}
#[wasm_bindgen]
impl MixReversing {
#[wasm_bindgen(constructor)]
pub fn new(r_factor: f32, g_factor: f32, b_factor: f32, average: f32) -> Self {
Self {
r_factor,
g_factor,
b_factor,
average,
}
}
}
impl MixReversing {
pub fn from_tint_rgb(basic_color: Rgb, mixed_result: Rgb) -> Self {
let r_factor = if basic_color.red == 1.0 {