Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
d8b2d01274
|
|||
bfa8457e95
|
|||
70106733d9
|
@@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.455"
|
const GoextVersion = "0.0.458"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2024-05-16T15:38:42+0200"
|
const GoextVersionTimestamp = "2024-05-20T00:15:24+0200"
|
||||||
|
@@ -234,11 +234,15 @@ func ObjectFitImage(img image.Image, bbw float64, bbh float64, fit ImageFit, fil
|
|||||||
|
|
||||||
// we scale the bounding box by fac (both dimension the same amount, to keep the bounding-box ratio)
|
// we scale the bounding box by fac (both dimension the same amount, to keep the bounding-box ratio)
|
||||||
|
|
||||||
|
// [ow|oh] ==> size of output image (same ratio as bounding box [bbw|bbh])
|
||||||
|
|
||||||
ow := int(math.Round(bbw * facOut))
|
ow := int(math.Round(bbw * facOut))
|
||||||
oh := int(math.Round(bbh * facOut))
|
oh := int(math.Round(bbh * facOut))
|
||||||
|
|
||||||
facScale := mathext.Min(float64(ow)/float64(iw), float64(oh)/float64(ih))
|
facScale := mathext.Min(float64(ow)/float64(iw), float64(oh)/float64(ih))
|
||||||
|
|
||||||
|
// [dw|dh] ==> size of destination rect (where to draw source in output image) (same ratio as input image [iw|ih])
|
||||||
|
|
||||||
dw := int(math.Round(float64(iw) * facScale))
|
dw := int(math.Round(float64(iw) * facScale))
|
||||||
dh := int(math.Round(float64(ih) * facScale))
|
dh := int(math.Round(float64(ih) * facScale))
|
||||||
|
|
||||||
@@ -248,11 +252,11 @@ func ObjectFitImage(img image.Image, bbw float64, bbh float64, fit ImageFit, fil
|
|||||||
if fit == ImageFitContainCenter {
|
if fit == ImageFitContainCenter {
|
||||||
destBounds = image.Rect((ow-dw)/2, (oh-dh)/2, (ow-dw)/2+dw, (oh-dh)/2+dh)
|
destBounds = image.Rect((ow-dw)/2, (oh-dh)/2, (ow-dw)/2+dw, (oh-dh)/2+dh)
|
||||||
} else if fit == ImageFitContainTopLeft {
|
} else if fit == ImageFitContainTopLeft {
|
||||||
destBounds = image.Rect(0, 0, iw, dh)
|
destBounds = image.Rect(0, 0, dw, dh)
|
||||||
} else if fit == ImageFitContainTopRight {
|
} else if fit == ImageFitContainTopRight {
|
||||||
destBounds = image.Rect(ow-iw, 0, ow, dh)
|
destBounds = image.Rect(ow-dw, 0, dw, dh)
|
||||||
} else if fit == ImageFitContainBottomLeft {
|
} else if fit == ImageFitContainBottomLeft {
|
||||||
destBounds = image.Rect(0, oh-dh, iw, oh)
|
destBounds = image.Rect(0, oh-dh, dw, oh)
|
||||||
} else if fit == ImageFitContainBottomRight {
|
} else if fit == ImageFitContainBottomRight {
|
||||||
destBounds = image.Rect(ow-dw, oh-dh, ow, oh)
|
destBounds = image.Rect(ow-dw, oh-dh, ow, oh)
|
||||||
}
|
}
|
||||||
|
@@ -59,6 +59,18 @@ func ArrUnique[T comparable](array []T) []T {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ArrUniqueStable[T comparable](array []T) []T {
|
||||||
|
hist := make(map[T]bool, len(array))
|
||||||
|
result := make([]T, 0, len(array))
|
||||||
|
for _, v := range array {
|
||||||
|
if _, ok := hist[v]; !ok {
|
||||||
|
hist[v] = true
|
||||||
|
result = append(result, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func ArrEqualsExact[T comparable](arr1 []T, arr2 []T) bool {
|
func ArrEqualsExact[T comparable](arr1 []T, arr2 []T) bool {
|
||||||
if len(arr1) != len(arr2) {
|
if len(arr1) != len(arr2) {
|
||||||
return false
|
return false
|
||||||
|
Reference in New Issue
Block a user