Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
damongolding committed Oct 17, 2024
1 parent 6e34ed8 commit c7e8b16
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 45 deletions.
16 changes: 12 additions & 4 deletions immich/immich_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,23 @@ func (i *ImmichAsset) FacesCenterPoint() (float64, float64) {
centerY := float64(minY+maxY) / 2

var percentX, percentY float64
var imageWidth, imageHeight int

if len(i.People) != 0 {
percentX = centerX / float64(i.People[0].Faces[0].ImageWidth) * 100
percentY = centerY / float64(i.People[0].Faces[0].ImageHeight) * 100
imageWidth = i.People[0].Faces[0].ImageWidth
imageHeight = i.People[0].Faces[0].ImageHeight
} else {
percentX = centerX / float64(i.UnassignedFaces[0].ImageWidth) * 100
percentY = centerY / float64(i.UnassignedFaces[0].ImageHeight) * 100
imageWidth = i.UnassignedFaces[0].ImageWidth
imageHeight = i.UnassignedFaces[0].ImageHeight
}

if imageWidth == 0 || imageHeight == 0 {
return 0, 0
}

percentX = centerX / float64(imageWidth) * 100
percentY = centerY / float64(imageHeight) * 100

return percentX, percentY
}

Expand Down
61 changes: 20 additions & 41 deletions immich/immich_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ func TestFacesCenterPoint(t *testing.T) {
{
name: "No people",
asset: ImmichAsset{
People: []Person{},
ExifInfo: ExifInfo{
ExifImageWidth: 1000,
ExifImageHeight: 1000,
},
People: []Person{},
UnassignedFaces: []Face{},
},
wantX: 0,
wantY: 0,
Expand All @@ -82,13 +79,10 @@ func TestFacesCenterPoint(t *testing.T) {
name: "People but no faces",
asset: ImmichAsset{
People: []Person{
{Faces: []Face{{BoundingBoxX1: 0, BoundingBoxY1: 0, BoundingBoxX2: 0, BoundingBoxY2: 0}}},
{Faces: []Face{{BoundingBoxX1: 0, BoundingBoxY1: 0, BoundingBoxX2: 0, BoundingBoxY2: 0}}},
},
ExifInfo: ExifInfo{
ExifImageWidth: 1000,
ExifImageHeight: 1000,
{Faces: []Face{{BoundingBoxX1: 0, BoundingBoxY1: 0, BoundingBoxX2: 0, BoundingBoxY2: 0, ImageWidth: 1000, ImageHeight: 1000}}},
{Faces: []Face{{BoundingBoxX1: 0, BoundingBoxY1: 0, BoundingBoxX2: 0, BoundingBoxY2: 0, ImageWidth: 1000, ImageHeight: 1000}}},
},
UnassignedFaces: []Face{},
},
wantX: 0,
wantY: 0,
Expand All @@ -97,12 +91,9 @@ func TestFacesCenterPoint(t *testing.T) {
name: "Zero dimensions",
asset: ImmichAsset{
People: []Person{
{Faces: []Face{{BoundingBoxX1: 10, BoundingBoxY1: 10, BoundingBoxX2: 20, BoundingBoxY2: 20}}},
},
ExifInfo: ExifInfo{
ExifImageWidth: 0,
ExifImageHeight: 0,
{Faces: []Face{{BoundingBoxX1: 10, BoundingBoxY1: 10, BoundingBoxX2: 20, BoundingBoxY2: 20, ImageWidth: 0, ImageHeight: 0}}},
},
UnassignedFaces: []Face{},
},
wantX: 0,
wantY: 0,
Expand All @@ -111,12 +102,9 @@ func TestFacesCenterPoint(t *testing.T) {
name: "Single face",
asset: ImmichAsset{
People: []Person{
{Faces: []Face{{BoundingBoxX1: 100, BoundingBoxY1: 100, BoundingBoxX2: 200, BoundingBoxY2: 200}}},
},
ExifInfo: ExifInfo{
ExifImageWidth: 1000,
ExifImageHeight: 1000,
{Faces: []Face{{BoundingBoxX1: 100, BoundingBoxY1: 100, BoundingBoxX2: 200, BoundingBoxY2: 200, ImageWidth: 1000, ImageHeight: 1000}}},
},
UnassignedFaces: []Face{},
},
wantX: 15,
wantY: 15,
Expand All @@ -125,13 +113,10 @@ func TestFacesCenterPoint(t *testing.T) {
name: "Multiple faces",
asset: ImmichAsset{
People: []Person{
{Faces: []Face{{BoundingBoxX1: 100, BoundingBoxY1: 100, BoundingBoxX2: 200, BoundingBoxY2: 200}}},
{Faces: []Face{{BoundingBoxX1: 300, BoundingBoxY1: 300, BoundingBoxX2: 400, BoundingBoxY2: 400}}},
},
ExifInfo: ExifInfo{
ExifImageWidth: 1000,
ExifImageHeight: 1000,
{Faces: []Face{{BoundingBoxX1: 100, BoundingBoxY1: 100, BoundingBoxX2: 200, BoundingBoxY2: 200, ImageWidth: 1000, ImageHeight: 1000}}},
{Faces: []Face{{BoundingBoxX1: 300, BoundingBoxY1: 300, BoundingBoxX2: 400, BoundingBoxY2: 400, ImageWidth: 1000, ImageHeight: 1000}}},
},
UnassignedFaces: []Face{},
},
wantX: 25,
wantY: 25,
Expand All @@ -140,14 +125,11 @@ func TestFacesCenterPoint(t *testing.T) {
name: "Multiple faces but not on the first person",
asset: ImmichAsset{
People: []Person{
{Faces: []Face{{BoundingBoxX1: 0, BoundingBoxY1: 0, BoundingBoxX2: 0, BoundingBoxY2: 0}}},
{Faces: []Face{{BoundingBoxX1: 100, BoundingBoxY1: 100, BoundingBoxX2: 200, BoundingBoxY2: 200}}},
{Faces: []Face{{BoundingBoxX1: 300, BoundingBoxY1: 300, BoundingBoxX2: 400, BoundingBoxY2: 400}}},
},
ExifInfo: ExifInfo{
ExifImageWidth: 1000,
ExifImageHeight: 1000,
{Faces: []Face{{BoundingBoxX1: 0, BoundingBoxY1: 0, BoundingBoxX2: 0, BoundingBoxY2: 0, ImageWidth: 1000, ImageHeight: 1000}}},
{Faces: []Face{{BoundingBoxX1: 100, BoundingBoxY1: 100, BoundingBoxX2: 200, BoundingBoxY2: 200, ImageWidth: 1000, ImageHeight: 1000}}},
{Faces: []Face{{BoundingBoxX1: 300, BoundingBoxY1: 300, BoundingBoxX2: 400, BoundingBoxY2: 400, ImageWidth: 1000, ImageHeight: 1000}}},
},
UnassignedFaces: []Face{},
},
wantX: 25,
wantY: 25,
Expand All @@ -156,14 +138,11 @@ func TestFacesCenterPoint(t *testing.T) {
name: "Multiple faces but not on the second person",
asset: ImmichAsset{
People: []Person{
{Faces: []Face{{BoundingBoxX1: 100, BoundingBoxY1: 100, BoundingBoxX2: 200, BoundingBoxY2: 200}}},
{Faces: []Face{{BoundingBoxX1: 0, BoundingBoxY1: 0, BoundingBoxX2: 0, BoundingBoxY2: 0}}},
{Faces: []Face{{BoundingBoxX1: 300, BoundingBoxY1: 300, BoundingBoxX2: 400, BoundingBoxY2: 400}}},
},
ExifInfo: ExifInfo{
ExifImageWidth: 1000,
ExifImageHeight: 1000,
{Faces: []Face{{BoundingBoxX1: 100, BoundingBoxY1: 100, BoundingBoxX2: 200, BoundingBoxY2: 200, ImageWidth: 1000, ImageHeight: 1000}}},
{Faces: []Face{{BoundingBoxX1: 0, BoundingBoxY1: 0, BoundingBoxX2: 0, BoundingBoxY2: 0, ImageWidth: 1000, ImageHeight: 1000}}},
{Faces: []Face{{BoundingBoxX1: 300, BoundingBoxY1: 300, BoundingBoxX2: 400, BoundingBoxY2: 400, ImageWidth: 1000, ImageHeight: 1000}}},
},
UnassignedFaces: []Face{},
},
wantX: 25,
wantY: 25,
Expand Down

0 comments on commit c7e8b16

Please sign in to comment.