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.
|
2021-08-14 16:01:44 +02:00
|
|
|
func (m Markers) FaceCount() (faces int) {
|
2021-05-31 15:40:52 +02:00
|
|
|
for _, marker := range m {
|
|
|
|
if !marker.MarkerInvalid && marker.MarkerType == MarkerFace {
|
2021-08-14 16:01:44 +02:00
|
|
|
faces++
|
2021-05-31 15:40:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-14 16:01:44 +02:00
|
|
|
return faces
|
2021-05-31 15:40:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// FindMarkers returns all markers for a given file id.
|
|
|
|
func FindMarkers(fileID uint) (Markers, error) {
|
|
|
|
m := Markers{}
|
2021-08-12 17:49:48 +02:00
|
|
|
err := Db().
|
|
|
|
Where(`file_id = ?`, fileID).
|
2021-08-16 00:29:36 +02:00
|
|
|
Preload("Subject").
|
2021-08-12 17:49:48 +02:00
|
|
|
Order("id").
|
|
|
|
Offset(0).Limit(1000).
|
|
|
|
Find(&m).Error
|
2021-05-31 15:40:52 +02:00
|
|
|
|
|
|
|
return m, err
|
|
|
|
}
|