2019-05-20 04:12:40 +00:00
|
|
|
package util
|
2019-03-02 21:30:16 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"math"
|
|
|
|
)
|
|
|
|
|
2019-03-16 04:35:00 +00:00
|
|
|
func GetRectLeftSideCenter(rect image.Rectangle) image.Point {
|
2019-03-02 21:30:16 +00:00
|
|
|
return image.Point{
|
|
|
|
X: rect.Min.X,
|
|
|
|
Y: rect.Min.Y + rect.Dy()/2,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-16 04:35:00 +00:00
|
|
|
func GetRectRightSideCenter(rect image.Rectangle) image.Point {
|
2019-03-02 21:30:16 +00:00
|
|
|
return image.Point{
|
|
|
|
X: rect.Max.X,
|
|
|
|
Y: rect.Min.Y + rect.Dy()/2,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-16 04:35:00 +00:00
|
|
|
func GetRectTopSideCenter(rect image.Rectangle) image.Point {
|
2019-03-02 21:30:16 +00:00
|
|
|
return image.Point{
|
|
|
|
X: rect.Min.X + rect.Dx()/2,
|
|
|
|
Y: rect.Min.Y,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-16 04:35:00 +00:00
|
|
|
func GetRectBottomSideCenter(rect image.Rectangle) image.Point {
|
2019-03-02 21:30:16 +00:00
|
|
|
return image.Point{
|
|
|
|
X: rect.Min.X + rect.Dx()/2,
|
|
|
|
Y: rect.Max.Y,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-08 04:04:46 +00:00
|
|
|
func GetDistance(p1 image.Point, p2 image.Point) float64 {
|
2019-03-02 21:30:16 +00:00
|
|
|
x := math.Abs(float64(p1.X - p2.X))
|
|
|
|
y := math.Abs(float64(p1.Y - p2.Y))
|
|
|
|
return math.Sqrt(x*x + y*y)
|
|
|
|
}
|
2019-05-20 04:12:40 +00:00
|
|
|
|
|
|
|
func GetRectCoordinates(area image.Rectangle, width int, height int) (int, int, int, int) {
|
|
|
|
x1 := area.Min.X + area.Dx()/2 - width/2
|
|
|
|
y1 := area.Min.Y + area.Dy()/2 - height
|
|
|
|
return x1, y1, x1 + width, y1 + height + 2
|
|
|
|
}
|