2021-05-26 14:41:59 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
type Markers []Marker
|
|
|
|
|
|
|
|
// Save stores the markers in the database.
|
2021-05-31 15:40:52 +02:00
|
|
|
func (m Markers) Save(fileID uint) error {
|
2021-05-26 14:41:59 +02:00
|
|
|
for _, marker := range m {
|
2021-05-31 15:40:52 +02:00
|
|
|
if fileID > 0 {
|
|
|
|
marker.FileID = fileID
|
|
|
|
}
|
|
|
|
|
2021-05-26 14:41:59 +02:00
|
|
|
if _, err := UpdateOrCreateMarker(&marker); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-05-31 15:40:52 +02:00
|
|
|
|
|
|
|
// Contains returns true if a marker at the same position already exists.
|
|
|
|
func (m Markers) Contains(m2 Marker) bool {
|
2021-06-01 17:39:03 +02:00
|
|
|
const d = 0.07
|
|
|
|
|
2021-05-31 15:40:52 +02:00
|
|
|
for _, m1 := range m {
|
2021-06-01 17:39:03 +02:00
|
|
|
if m2.X > (m1.X-d) && m2.X < (m1.X+d) && m2.Y > (m1.Y-d) && m2.Y < (m1.Y+d) {
|
2021-05-31 15:40:52 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// FaceCount returns the number of valid face markers.
|
|
|
|
func (m Markers) FaceCount() int {
|
|
|
|
result := 0
|
|
|
|
for _, marker := range m {
|
|
|
|
if !marker.MarkerInvalid && marker.MarkerType == MarkerFace {
|
|
|
|
result++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindMarkers returns all markers for a given file id.
|
|
|
|
func FindMarkers(fileID uint) (Markers, error) {
|
|
|
|
m := Markers{}
|
|
|
|
err := Db().Where(`file_id = ?`, fileID).Order("id").Offset(0).Limit(1000).Find(&m).Error
|
|
|
|
|
|
|
|
return m, err
|
|
|
|
}
|