22 lines
463 B
Go
22 lines
463 B
Go
package utilities
|
|
|
|
import "fmt"
|
|
|
|
type Ratio struct {
|
|
Numerator int
|
|
Denominator int
|
|
}
|
|
|
|
func (r Ratio) Float64() float64 {
|
|
return float64(r.Numerator) / float64(r.Denominator)
|
|
}
|
|
|
|
func (r Ratio) String() string {
|
|
return fmt.Sprintf("%d:%d", r.Numerator, r.Denominator)
|
|
}
|
|
|
|
// Reciprocal get the reciprocal, for example, to convert frame rate into time base
|
|
func (r Ratio) Reciprocal() Ratio {
|
|
return Ratio{Numerator: r.Denominator, Denominator: r.Numerator}
|
|
}
|