<commit_before>use core::cast::transmute;
use core::cmp::Eq;
use core::ptr::to_unsafe_ptr;
use core::sys::size_of;
use core::vec::raw::buf_as_slice;

use angle::Degrees;
use channel::Channel;
use dim::{Dimensional, ToPtr};
use funs::common::Sign;
use num::kinds::{Float, Number};


pub trait Color<T>: Dimensional<T>, ToPtr<T>, Eq {
    pure fn inverse(&self) -> self;
    
    pure fn to_rgb_u8(&self) -> RGB<u8>;
    pure fn to_rgb_u16(&self) -> RGB<u16>;
    pure fn to_rgb_u32(&self) -> RGB<u32>;
    pure fn to_rgb_u64(&self) -> RGB<u64>;
    pure fn to_rgb_f32(&self) -> RGB<f32>;
    pure fn to_rgb_f64(&self) -> RGB<f64>;
    
    pure fn to_hsv_f32(&self) -> HSV<f32>;
    pure fn to_hsv_f64(&self) -> HSV<f64>;
}

// pub trait ColorRGB<T> {
//     static pure fn from_hex(hex: u8) -> self;
// }

pub trait Color3<T>: Color<T> {
    pure fn to_rgba_u8(&self, a: u8) -> RGBA<u8>;
    pure fn to_rgba_u16(&self, a: u16) -> RGBA<u16>;
    pure fn to_rgba_u32(&self, a: u32) -> RGBA<u32>;
    pure fn to_rgba_u64(&self, a: u64) -> RGBA<u64>;
    pure fn to_rgba_f32(&self, a: f32) -> RGBA<f32>;
    pure fn to_rgba_f64(&self, a: f64) -> RGBA<f64>;
    
    pure fn to_hsva_f32(&self, a: f32) -> HSVA<f32>;
    pure fn to_hsva_f64(&self, a: f64) -> HSVA<f64>;
}

pub trait Color4<T>: Color<T> {
    pure fn to_rgba_u8(&self) -> RGBA<u8>;
    pure fn to_rgba_u16(&self) -> RGBA<u16>;
    pure fn to_rgba_u32(&self) -> RGBA<u32>;
    pure fn to_rgba_u64(&self) -> RGBA<u64>;
    pure fn to_rgba_f32(&self) -> RGBA<f32>;
    pure fn to_rgba_f64(&self) -> RGBA<f64>;
    
    pure fn to_hsva_f32(&self) -> HSVA<f32>;
    pure fn to_hsva_f64(&self) -> HSVA<f64>;
}




/**
 * RGB to HSV conversion
 */
#[inline(always)]
pub pure fn to_hsv<T:Copy Float>(color: &RGB<T>) -> HSV<T> {
    // Algorithm taken from the Wikipedia article on HSL and HSV:
    // http://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV
    
    let _0 = Number::from(0f);
    
    let mx = [color.r, color.g, color.b].max();
    let mn = [color.r, color.g, color.b].min();
    let chr = mx - mn;
    
    if chr != Number::from(0f) {
        let h = Degrees(<commit_msg>Document color conversions for the `Color` trait<commit_after>use core::cast::transmute;
use core::cmp::Eq;
use core::ptr::to_unsafe_ptr;
use core::sys::size_of;
use core::vec::raw::buf_as_slice;

use angle::Degrees;
use channel::Channel;
use dim::{Dimensional, ToPtr};
use funs::common::Sign;
use num::kinds::{Float, Number};
/**
 * A generic color trait.
 */

pub trait Color<T>: Dimensional<T>, ToPtr<T>, Eq {
    /**
     * Returns the color with each component inverted
     */
    pure fn inverse(&self) -> self;
    
    /**
     * Convert the color to a `RGB<u8>`
     *
     * # Returns
     *
     * The color as a `RGB<u8>` color with components ranging from
     * `0x00u8` to `0xFFu8`
     */
    pure fn to_rgb_u8(&self) -> RGB<u8>;
    
    /**
     * Convert the color to a RGB<u16>
     *
     * # Returns
     *
     * The color as a `RGB<u16>` color with components ranging from
     * `0x0000u16` to `0xFFFFu16`
     */
    pure fn to_rgb_u16(&self) -> RGB<u16>;
    
    /**
     * Convert the color to a `RGB<u32>`
     *
     * # Returns
     *
     * The color as a `RGB<u32>` color with components ranging from
     * `0x0000_0000_u32` to `0xFFFF_FFFF_u32`
     */
    pure fn to_rgb_u32(&self) -> RGB<u32>;
    
    /**
     * Convert the color to a `RGB<u64>`
     *
     * # Returns
     *
     * The color as a `RGB<u32>` color with components ranging from
     * `0x0000_0000_u32` to `0xFFFF_FFFF_u32`
     */
    pure fn to_rgb_u64(&self) -> RGB<u64>;
    
    /**
     * Convert the color to a `RGB<f32>`
     *
     * # Returns
     *
     * The color as a `RGB<f32>` color with components ranging from
     * `0f32` to `1f32`
     */
    pure fn to_rgb_f32(&self) -> RGB<f32>;
    
    /**
     * Convert the color to a `RGB<f64>`
     *
     * # Returns
     *
     * The color as a `RGB<f64>` color with components ranging from
     * `0f64` to `1f64`
     */
    pure fn to_rgb_f64(&self) -> RGB<f64>;
    
    
    /**
     * Convert the color to a `HSV<f32>`
     *
     * # Returns
     *
     * The color as a `HSV<f32>` with the `h` component as a `f32` angle and
     * saturation and value components ranging from `0f32` to `1f32`
     */
    pure fn to_hsv_f32(&self) -> HSV<f32>;
    
    /**
     * Convert the color to a `HSV<f64>`
     *
     * # Returns
     *
     * The color as a `HSV<f64>` with the `h` component as a `f64` angle and
     * saturation and value components ranging from `0f64` to `1f64`
     */
    pure fn to_hsv_f64(&self) -> HSV<f64>;
}

// pub trait ColorRGB<T> {
//     static pure fn from_hex(hex: u8) -> self;
// }

pub trait Color3<T>: Color<T> {
    // TODO: documentation (bleh, so much writing)
    pure fn to_rgba_u8(&self, a: u8) -> RGBA<u8>;
    pure fn to_rgba_u16(&self, a: u16) -> RGBA<u16>;
    pure fn to_rgba_u32(&self, a: u32) -> RGBA<u32>;
    pure fn to_rgba_u64(&self, a: u64) -> RGBA<u64>;
    pure fn to_rgba_f32(&self, a: f32) -> RGBA<f32>;
    pure fn to_rgba_f64(&self, a: f64) -> RGBA<f64>;
    
    pure fn to_hsva_f32(&self, a: f32) -> HSVA<f32>;
    pure fn to_hsva_f64(&self, a: f64) -> HSVA<f64>;
}

pub trait Color4<T>: Color<T> {
    // TODO: documentation (arrg...)
    pure fn to_rgba_u8(&self) -> RGBA<u8>;
    pure fn to_rgba_u16(&self) -> RGBA<u16>;
    pure fn to_rgba_u32(&self) -> RGBA<u32>;
    pure fn to_rgba_u64(&self) -> RGBA<u64>;
    pure fn to_rgba_f32(&self) -> RGBA<f32>;
    pure fn to_rgba_f64(&self) -> RGBA<f64>;
    
    pure fn to_hsva_f32(&self) -> HSVA<f32>;
    pure fn to_hsva_f64(&self) -> HSVA<f64>;
}




/**
 * RGB to HSV conversion
 */
#[inline(always)]
pub pure fn to_hsv<T:Copy Float>(color: &RGB<T>) -> HSV<T> {
    // Algorithm taken from the Wikipedia article on HSL and HSV:
    // http://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV
    
    let _0 = Number::from(0f);
    
    let mx = [color.r, color.g, color.b].max();
    let mn = [color.r, color.g, color.b].min();
    let chr = mx - mn;
    
    if chr != Number::from(0f) {
        let h = Degrees(
{'fraction_non_alphanumeric': 0.16408668730650156, 'fraction_numerical': 0.052794525012220955, 'mean_word_length': 2.6470588235294117, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 143, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6393551', 'n_tokens_mistral': 2701, 'n_tokens_neox': 2476, 'n_words': 619}