scenemap and effect enforcers.

This commit is contained in:
2022-08-18 22:46:38 +02:00
parent d6350ff0c6
commit fd898050bf
9 changed files with 319 additions and 24 deletions
+51
View File
@@ -3,6 +3,7 @@ package color
import (
"fmt"
"github.com/lucasb-eyer/go-colorful"
"math"
"strconv"
"strings"
)
@@ -38,6 +39,56 @@ func (col *Color) SetXY(xy XY) {
*col = Color{XY: &xy}
}
func (col *Color) AlmostEquals(other Color) bool {
if (col.K != nil) != (other.K != nil) {
return false
}
if col.HS != nil && other.HS != nil {
if math.Abs(col.HS.Hue-other.HS.Hue) > 0.01 {
return false
}
if math.Abs(col.HS.Sat-other.HS.Sat) > 0.01 {
return false
}
if col.K != nil && *col.K != *other.K {
return false
}
return true
}
if col.K != nil {
return *col.K == *other.K
}
if col.RGB != nil && other.RGB != nil {
if math.Abs(col.RGB.Red-other.RGB.Red) > 0.01 {
return false
}
if math.Abs(col.RGB.Blue-other.RGB.Blue) > 0.01 {
return false
}
if math.Abs(col.RGB.Green-other.RGB.Green) > 0.01 {
return false
}
return true
}
xy1, _ := col.ToXY()
xy2, _ := col.ToXY()
if math.Abs(xy1.XY.X-xy2.XY.X) > 0.001 {
return false
}
if math.Abs(xy1.XY.Y-xy2.XY.Y) > 0.001 {
return false
}
return true
}
// ToRGB tries to copy the color to an RGB color. If it's already RGB, it will be plainly copied, but HS
// will be returned. If ok is false, then no copying has occurred and cv2 will be blank.
func (col *Color) ToRGB() (col2 Color, ok bool) {