Skip to content

Commit ebef5e7

Browse files
committed
Use utility package
1 parent 562c1a7 commit ebef5e7

File tree

7 files changed

+19
-21
lines changed

7 files changed

+19
-21
lines changed

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module github.com/gravitton/geometry
22

33
go 1.25
44

5-
require github.com/gravitton/assert v0.5.0
5+
require (
6+
github.com/gravitton/assert v0.5.0
7+
github.com/gravitton/x v0.2.0
8+
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
github.com/gravitton/assert v0.5.0 h1:7HW4+nagmtDEI7ZMBjeZo/sBJTNnxtWGoVw/Vxe1VUU=
22
github.com/gravitton/assert v0.5.0/go.mod h1:wQGHJvwsxQQ7qdX++NLofrI2cJvYIdJJtAo7A15qcAY=
3+
github.com/gravitton/x v0.2.0 h1:NZ1uyyHz/uyj2kO0JASCUfMsuIFZdAfiACV9DPJaUqE=
4+
github.com/gravitton/x v0.2.0/go.mod h1:ycNMdiA3TtMQmAZDgZ0pNeOl84eEKQ/coKyAdjCG8kQ=

internal/slices.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

polygon.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package geom
22

3-
import "github.com/gravitton/geometry/internal"
3+
import (
4+
"github.com/gravitton/x/slices"
5+
)
46

57
// Polygon is a 2D polygon with 3+ vertices.
68
type Polygon[T Number] struct {
@@ -25,7 +27,7 @@ func (p Polygon[T]) Center() Point[T] {
2527

2628
// Translate creates a new Polygon translated by the given vector (applied to all vertices).
2729
func (p Polygon[T]) Translate(vector Vector[T]) Polygon[T] {
28-
return Polygon[T]{internal.Map(p.Vertices, func(e Point[T]) Point[T] {
30+
return Polygon[T]{slices.Map(p.Vertices, func(e Point[T]) Point[T] {
2931
return e.Add(vector)
3032
})}
3133
}
@@ -38,15 +40,15 @@ func (p Polygon[T]) MoveTo(point Point[T]) Polygon[T] {
3840
// Scale creates a new Polygon uniformly scaled about its centroid by the factor.
3941
func (p Polygon[T]) Scale(factor float64) Polygon[T] {
4042
center := p.Center()
41-
return Polygon[T]{internal.Map(p.Vertices, func(point Point[T]) Point[T] {
43+
return Polygon[T]{slices.Map(p.Vertices, func(point Point[T]) Point[T] {
4244
return center.Add(point.Subtract(center).Multiply(factor))
4345
})}
4446
}
4547

4648
// ScaleXY creates a new Polygon scaled about its centroid by the factors.
4749
func (p Polygon[T]) ScaleXY(factorX, factorY float64) Polygon[T] {
4850
center := p.Center()
49-
return Polygon[T]{internal.Map(p.Vertices, func(point Point[T]) Point[T] {
51+
return Polygon[T]{slices.Map(p.Vertices, func(point Point[T]) Point[T] {
5052
return center.Add(point.Subtract(center).MultiplyXY(factorX, factorY))
5153
})}
5254
}

rectangle.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package geom
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
)
46

57
// Rectangle is a 2D axis-aligned rectangle represented by its center and size.
68
type Rectangle[T Number] struct {

types/floats/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package floats
22

33
import (
44
geom "github.com/gravitton/geometry"
5-
"github.com/gravitton/geometry/internal"
5+
"github.com/gravitton/x/slices"
66
)
77

88
type Point = geom.Point[float64]
@@ -61,7 +61,7 @@ func ToRectangle[T geom.Number](rectangle geom.Rectangle[T]) Rectangle {
6161
}
6262

6363
func Pol[T geom.Number](Vertices []geom.Point[T]) Polygon {
64-
return Polygon{Vertices: internal.Map(Vertices, func(point geom.Point[T]) Point {
64+
return Polygon{Vertices: slices.Map(Vertices, func(point geom.Point[T]) Point {
6565
return ToPoint(point)
6666
})}
6767
}

types/ints/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package ints
22

33
import (
44
geom "github.com/gravitton/geometry"
5-
"github.com/gravitton/geometry/internal"
5+
"github.com/gravitton/x/slices"
66
)
77

88
type Point = geom.Point[int]
@@ -64,7 +64,7 @@ func ToRectangle[T geom.Number](rectangle geom.Rectangle[T]) Rectangle {
6464
}
6565

6666
func Pol[T geom.Number](Vertices []geom.Point[T]) Polygon {
67-
return Polygon{Vertices: internal.Map(Vertices, func(point geom.Point[T]) Point {
67+
return Polygon{Vertices: slices.Map(Vertices, func(point geom.Point[T]) Point {
6868
return ToPoint(point)
6969
})}
7070
}

0 commit comments

Comments
 (0)