Verified Commit f88502a3 authored by Soren's avatar Soren

New ColorImpl to help with generifying

parent 6138180a
package tf.bug.nose
import tf.bug.nose.implicits._
sealed trait Color {
def rgb: RGBFormat
def hsv: HSVFormat
}
private case class ColorImpl[C](c: C)(implicit colorFormat: ColorFormat[C]) extends Color {
override def rgb: RGBFormat = colorFormat.asRGB(c)
override def hsv: HSVFormat = colorFormat.asHSV(c)
}
object Color {
def apply[C: ColorFormat](c: C): Color = ColorImpl(c)
def unapply[C: ColorFormat](arg: Color): Option[C] = arg match {
case ColorImpl(c: C) => Some(c)
case _ => None
}
def rgb(red: Double, green: Double, blue: Double): Color = {
Color(RGBFormat(red, green, blue))
}
def rgb(red: Int, green: Int, blue: Int): Color = {
Color(RGBFormat(red / 255.0, green / 255.0, blue / 255.0))
}
def rgb(rgb: Int): Color = {
val red = (rgb >> 16) & 0xFF
val green = (rgb >> 8) & 0xFF
val blue = rgb & 0xFF
Color.rgb(red, green, blue)
}
}
package tf.bug.nose
import tf.bug.nose
import tf.bug.nose.implicits._
case class Color[C](c: C)(implicit colorFormat: ColorFormat[C]) {
def rgb: RGBFormat = colorFormat.asRGB(c)
def hsv: HSVFormat = colorFormat.asHSV(c)
}
object Color {
def rgb(red: Double, green: Double, blue: Double): Color[RGBFormat] = {
Color(nose.RGBFormat(red, green, blue))
}
def rgb(red: Int, green: Int, blue: Int): Color[RGBFormat] = {
Color(nose.RGBFormat(red / 255.0, green / 255.0, blue / 255.0))
}
def rgb(rgb: Int): Color[RGBFormat] = {
val red = (rgb >> 16) & 0xFF
val green = (rgb >> 8) & 0xFF
val blue = rgb & 0xFF
Color.rgb(red, green, blue)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment