hue hue hue
This commit is contained in:
@@ -9,9 +9,10 @@ const eps = 0.0001
|
||||
const epsSquare = eps * eps
|
||||
|
||||
type Gamut struct {
|
||||
Red XY `json:"red"`
|
||||
Green XY `json:"green"`
|
||||
Blue XY `json:"blue"`
|
||||
Label string `json:"label,omitempty"`
|
||||
Red XY `json:"red"`
|
||||
Green XY `json:"green"`
|
||||
Blue XY `json:"blue"`
|
||||
}
|
||||
|
||||
func (cg *Gamut) side(x1, y1, x2, y2, x, y float64) float64 {
|
||||
@@ -171,7 +172,8 @@ func (xy XY) ToHS() HueSat {
|
||||
}
|
||||
|
||||
func (xy XY) DistanceTo(other XY) float64 {
|
||||
return math.Sqrt(math.Pow(xy.X-other.X, 2) + math.Pow(xy.Y-other.Y, 2))
|
||||
return math.Abs(xy.X-other.X) + math.Abs(xy.Y-other.Y)
|
||||
//return math.Sqrt(math.Pow(xy.X-other.X, 2) + math.Pow(xy.Y-other.Y, 2))
|
||||
}
|
||||
|
||||
func (xy XY) Round() XY {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func CompactIDList(ids []string) []string {
|
||||
ids = append(ids[:0:0], ids...)
|
||||
sort.Strings(ids)
|
||||
|
||||
currentGroup := ""
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package gentools
|
||||
|
||||
func CopyMap[K comparable, V any](m map[K]V) map[K]V {
|
||||
m2 := make(map[K]V, len(m))
|
||||
for k, v := range m {
|
||||
m2[k] = v
|
||||
}
|
||||
|
||||
return m2
|
||||
}
|
||||
|
||||
func OneItemMap[K comparable, V any](key K, value V) map[K]V {
|
||||
m := make(map[K]V, 1)
|
||||
m[key] = value
|
||||
return m
|
||||
}
|
||||
@@ -5,6 +5,16 @@ func Ptr[T any](t T) *T {
|
||||
}
|
||||
|
||||
func ShallowCopy[T any](t *T) *T {
|
||||
if t == nil {
|
||||
return t
|
||||
}
|
||||
|
||||
tCopy := *t
|
||||
return &tCopy
|
||||
}
|
||||
|
||||
func ShallowCopyTo[T any](dst **T, src *T) {
|
||||
if src != nil {
|
||||
*dst = ShallowCopy(src)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,3 +22,21 @@ Outer:
|
||||
*arr = append(*arr, v)
|
||||
}
|
||||
}
|
||||
|
||||
func Map[T any, U any](arr []T, cb func(T) U) []U {
|
||||
arr2 := make([]U, len(arr))
|
||||
for i, v := range arr {
|
||||
arr2[i] = cb(v)
|
||||
}
|
||||
|
||||
return arr2
|
||||
}
|
||||
|
||||
func Flatten[T any](arr [][]T) []T {
|
||||
arr2 := make([]T, 0, 128)
|
||||
for _, sub := range arr {
|
||||
arr2 = sub
|
||||
}
|
||||
|
||||
return arr2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user