Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cmd/trophy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ var (
bgColor string
)

const minTargetFPS = 1

func main() {
cmd := &cobra.Command{
Use: "trophy <model.obj|model.glb|model.stl>",
Expand Down Expand Up @@ -407,7 +409,18 @@ func parseBackgroundColor(input string) (color.RGBA, error) {
return color.RGBA{R: channels[0], G: channels[1], B: channels[2], A: 255}, nil
}

func validateTargetFPS(fps int) error {
if fps < minTargetFPS {
return fmt.Errorf("invalid fps %d: must be at least %d", fps, minTargetFPS)
}
return nil
}

func run(modelPath string) (err error) {
if err := validateTargetFPS(targetFPS); err != nil {
return err
}

bg, err := parseBackgroundColor(bgColor)
if err != nil {
return err
Expand Down
16 changes: 16 additions & 0 deletions cmd/trophy/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,22 @@ func TestParseBackgroundColorInvalid(t *testing.T) {
}
}

func TestValidateTargetFPS(t *testing.T) {
for _, testCase := range []int{1, 30, 60, 120} {
if err := validateTargetFPS(testCase); err != nil {
t.Fatalf("validateTargetFPS(%d) returned error: %v", testCase, err)
}
}
}

func TestValidateTargetFPSInvalid(t *testing.T) {
for _, testCase := range []int{0, -1, -60} {
if err := validateTargetFPS(testCase); err == nil {
t.Fatalf("expected error for fps %d", testCase)
}
}
}

func TestRunInfoUnsupportedFormat(t *testing.T) {
err := runInfo("test.xyz")
if err == nil {
Expand Down