Skip to content

Commit

Permalink
Add aliases for common geom types
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwilkes committed Aug 9, 2023
1 parent 2465404 commit 26ed363
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions xmath/geom/insets.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import (
"github.com/richardwilkes/toolbox/xmath"
)

// Insets32 is an alias for the float32 version of Insets.
type Insets32 = Insets[float32]

// Insets64 is an alias for the float64 version of Insets.
type Insets64 = Insets[float64]

// Insets defines margins on each side of a rectangle.
type Insets[T xmath.Numeric] struct {
Top T `json:"top"`
Expand Down
6 changes: 6 additions & 0 deletions xmath/geom/matrix2d.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
"golang.org/x/exp/constraints"
)

// Matrix2D32 is an alias for the float32 version of Matrix2D.
type Matrix2D32 = Matrix2D[float32]

// Matrix2D64 is an alias for the float64 version of Matrix2D.
type Matrix2D64 = Matrix2D[float64]

// Matrix2D provides a 2D matrix.
type Matrix2D[T constraints.Float] struct {
ScaleX T
Expand Down
6 changes: 6 additions & 0 deletions xmath/geom/point.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import (
"github.com/richardwilkes/toolbox/xmath"
)

// Pt32 is an alias for the float32 version of Point.
type Pt32 = Point[float32]

// Pt64 is an alias for the float64 version of Point.
type Pt64 = Point[float64]

// Point defines a location.
type Point[T xmath.Numeric] struct {
X T `json:"x"`
Expand Down
6 changes: 6 additions & 0 deletions xmath/geom/poly/contour.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import (
"golang.org/x/exp/constraints"
)

// Contour32 is an alias for the float32 version of Contour.
type Contour32 = Contour[float32]

// Contour64 is an alias for the float64 version of Contour.
type Contour64 = Contour[float64]

// Contour is a sequence of vertices connected by line segments, forming a closed shape.
type Contour[T constraints.Float] []geom.Point[T]

Expand Down
6 changes: 6 additions & 0 deletions xmath/geom/poly/polygon.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
"golang.org/x/exp/constraints"
)

// Polygon32 is an alias for the float32 version of Polygon.
type Polygon32 = Polygon[float32]

// Polygon64 is an alias for the float64 version of Polygon.
type Polygon64 = Polygon[float64]

// Polygon holds one or more contour lines. The polygon may contain holes and may be self-intersecting.
type Polygon[T constraints.Float] []Contour[T]

Expand Down
6 changes: 6 additions & 0 deletions xmath/geom/rect.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import (
"github.com/richardwilkes/toolbox/xmath"
)

// Rect32 is an alias for the float32 version of Rect.
type Rect32 = Rect[float32]

// Rect64 is an alias for the float64 version of Rect.
type Rect64 = Rect[float64]

// Rect defines a rectangle.
type Rect[T xmath.Numeric] struct {
Point[T] `json:",inline"`
Expand Down
6 changes: 6 additions & 0 deletions xmath/geom/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import (
"github.com/richardwilkes/toolbox/xmath"
)

// Size32 is an alias for the float32 version of Size.
type Size32 = Size[float32]

// Size64 is an alias for the float64 version of Size.
type Size64 = Size[float64]

// Size defines a width and height.
type Size[T xmath.Numeric] struct {
Width T `json:"w"`
Expand Down

0 comments on commit 26ed363

Please sign in to comment.