Skip to content

Commit 784ac8c

Browse files
committed
Standardize naming
1 parent 553dd19 commit 784ac8c

File tree

12 files changed

+99
-98
lines changed

12 files changed

+99
-98
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ func (s Size[T]) AspectRatio() float64
121121

122122

123123
// Dimension operations
124-
func (s Size[T]) Scaled(factor float64) Size[T]
125-
func (s Size[T]) ScaledXY(scaleX, scaleY float64) Size[T]
126-
func (s Size[T]) Expand(deltaWidth, deltaHeight T) Size[T]
127-
func (s Size[T]) Shrunk(deltaWidth, deltaHeight T) Size[T]
124+
func (s Size[T]) Scale(factor float64) Size[T]
125+
func (s Size[T]) ScaleXY(factorX, factorY float64) Size[T]
126+
func (s Size[T]) Grow(amount T) Size[T]
127+
func (s Size[T]) GrowXY(amountX, amountY T) Size[T]
128+
func (s Size[T]) Shrink(amountX, amountY T) Size[T]
128129

129130
// Utilities
130131
func (s Size[T]) Equal(other Size[T]) bool

circle.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ func (c Circle[T]) MoveTo(point Point[T]) Circle[T] {
2727
}
2828

2929
// Multiple creates a new Circle with radius scaled by the given factor.
30-
func (c Circle[T]) Scale(scale float64) Circle[T] {
31-
return Circle[T]{c.Center, Multiple(c.Radius, scale)}
30+
func (c Circle[T]) Scale(factor float64) Circle[T] {
31+
return Circle[T]{c.Center, Multiple(c.Radius, factor)}
3232
}
3333

3434
// Resize creates a new Circle with the given radius.
3535
func (c Circle[T]) Resize(radius T) Circle[T] {
3636
return Circle[T]{c.Center, radius}
3737
}
3838

39-
// Expand creates a new Circle with radius increased by amount.
40-
func (c Circle[T]) Expand(amount T) Circle[T] {
39+
// Grow creates a new Circle with radius increased by amount.
40+
func (c Circle[T]) Grow(amount T) Circle[T] {
4141
return Circle[T]{c.Center, c.Radius + amount}
4242
}
4343

44-
// Shrunk creates a new Circle with radius decreased by amount.
45-
func (c Circle[T]) Shrunk(amount T) Circle[T] {
44+
// Shrink creates a new Circle with radius decreased by amount.
45+
func (c Circle[T]) Shrink(amount T) Circle[T] {
4646
return Circle[T]{c.Center, c.Radius - amount}
4747
}
4848

circle_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ func TestCircle_Resize(t *testing.T) {
3434
}
3535

3636
func TestCircle_Expand(t *testing.T) {
37-
testCircle(t, C(P(1, 2), 10).Expand(8), 1, 2, 18)
38-
testCircle(t, C(P(0.4, -0.25), 1.2).Expand(3.1), 0.4, -0.25, 4.3)
37+
testCircle(t, C(P(1, 2), 10).Grow(8), 1, 2, 18)
38+
testCircle(t, C(P(0.4, -0.25), 1.2).Grow(3.1), 0.4, -0.25, 4.3)
3939
}
4040

4141
func TestCircle_Shrunk(t *testing.T) {
42-
testCircle(t, C(P(1, 2), 10).Shrunk(8), 1, 2, 2)
43-
testCircle(t, C(P(0.4, -0.25), 1.2).Shrunk(0.3), 0.4, -0.25, 0.9)
42+
testCircle(t, C(P(1, 2), 10).Shrink(8), 1, 2, 2)
43+
testCircle(t, C(P(0.4, -0.25), 1.2).Shrink(0.3), 0.4, -0.25, 0.9)
4444
}
4545

4646
func TestCircle_Area(t *testing.T) {
@@ -107,8 +107,8 @@ func TestCircle_Immutable(t *testing.T) {
107107
c1.MoveTo(P(4, 3))
108108
c1.Scale(2)
109109
c1.Resize(15)
110-
c1.Expand(1)
111-
c1.Shrunk(2)
110+
c1.Grow(1)
111+
c1.Shrink(2)
112112

113113
testCircle(t, c1, 1, 2, 10)
114114
}

math.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ func ToDegrees(radians float64) float64 {
2525
}
2626

2727
// Multiple multiple number by scale factor
28-
func Multiple[T Number](a T, scale float64) T {
29-
return Cast[T](float64(a) * scale)
28+
func Multiple[T Number](a T, factor float64) T {
29+
return Cast[T](float64(a) * factor)
3030
}
3131

3232
// Divide divide number by scale factor

point.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ func (p Point[T]) Subtract(point Point[T]) Vector[T] {
3131
}
3232

3333
// Multiply creates a new Point by multiplying the given value to the current point.
34-
func (p Point[T]) Multiply(scale float64) Point[T] {
35-
return Point[T]{Multiple(p.X, scale), Multiple(p.Y, scale)}
34+
func (p Point[T]) Multiply(factor float64) Point[T] {
35+
return Point[T]{Multiple(p.X, factor), Multiple(p.Y, factor)}
3636
}
3737

3838
// MultiplyXY creates a new Point by multiplying the given values to the current point.
39-
func (p Point[T]) MultiplyXY(scaleX, scaleY float64) Point[T] {
40-
return Point[T]{Multiple(p.X, scaleX), Multiple(p.Y, scaleY)}
39+
func (p Point[T]) MultiplyXY(factorX, factorY float64) Point[T] {
40+
return Point[T]{Multiple(p.X, factorX), Multiple(p.Y, factorY)}
4141
}
4242

4343
// Divide creates a new Point by dividing the given value to the current point.
44-
func (p Point[T]) Divide(scale float64) Point[T] {
45-
return Point[T]{Divide(p.X, scale), Divide(p.Y, scale)}
44+
func (p Point[T]) Divide(factor float64) Point[T] {
45+
return Point[T]{Divide(p.X, factor), Divide(p.Y, factor)}
4646
}
4747

4848
// DivideXY creates a new Point by dividing the given values to the current point.
49-
func (p Point[T]) DivideXY(scaleX, scaleY float64) Point[T] {
50-
return Point[T]{Divide(p.X, scaleX), Divide(p.Y, scaleY)}
49+
func (p Point[T]) DivideXY(factorX, factorY float64) Point[T] {
50+
return Point[T]{Divide(p.X, factorX), Divide(p.Y, factorY)}
5151
}
5252

5353
// DistanceTo return euclidean distance from the current point to the given point.

polygon.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ func (p Polygon[T]) MoveTo(point Point[T]) Polygon[T] {
2929
}
3030

3131
// Scale creates a new Polygon uniformly scaled about its centroid by the factor.
32-
func (p Polygon[T]) Scale(scale float64) Polygon[T] {
32+
func (p Polygon[T]) Scale(factor float64) Polygon[T] {
3333
center := p.Center()
3434
return Polygon[T]{Transform(p.Vertices, func(point Point[T]) Point[T] {
35-
return center.Add(point.Subtract(center).Multiply(scale))
35+
return center.Add(point.Subtract(center).Multiply(factor))
3636
})}
3737
}
3838

3939
// ScaleXY creates a new Polygon scaled about its centroid by the factors.
40-
func (p Polygon[T]) ScaleXY(scaleX, scaleY float64) Polygon[T] {
40+
func (p Polygon[T]) ScaleXY(factorX, factorY float64) Polygon[T] {
4141
center := p.Center()
4242
return Polygon[T]{Transform(p.Vertices, func(point Point[T]) Point[T] {
43-
return center.Add(point.Subtract(center).MultiplyXY(scaleX, scaleY))
43+
return center.Add(point.Subtract(center).MultiplyXY(factorX, factorY))
4444
})}
4545
}

rectangle.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,38 @@ func (r Rectangle[T]) MoveTo(point Point[T]) Rectangle[T] {
3939
}
4040

4141
// Multiple creates a new Rectangle with size uniformly scaled by the factor.
42-
func (r Rectangle[T]) Scale(scale float64) Rectangle[T] {
43-
return Rectangle[T]{r.Center, r.Size.Scale(scale)}
42+
func (r Rectangle[T]) Scale(factor float64) Rectangle[T] {
43+
return Rectangle[T]{r.Center, r.Size.Scale(factor)}
4444
}
4545

4646
// ScaleXY creates a new Rectangle with size scaled by the given factors.
47-
func (r Rectangle[T]) ScaleXY(scaleX, scaleY float64) Rectangle[T] {
48-
return Rectangle[T]{r.Center, r.Size.ScaleXY(scaleX, scaleY)}
47+
func (r Rectangle[T]) ScaleXY(factorX, factorY float64) Rectangle[T] {
48+
return Rectangle[T]{r.Center, r.Size.ScaleXY(factorX, factorY)}
4949
}
5050

5151
// Resize creates a new Rectangle with the given size.
5252
func (r Rectangle[T]) Resize(size Size[T]) Rectangle[T] {
5353
return Rectangle[T]{r.Center, size}
5454
}
5555

56-
// Shrunk creates a new Rectangle with size expanded by the same delta in both dimensions.
57-
func (r Rectangle[T]) Expand(delta T) Rectangle[T] {
58-
return Rectangle[T]{r.Center, r.Size.Expand(delta)}
56+
// Grow creates a new Rectangle with size expanded by the same amount in both dimensions.
57+
func (r Rectangle[T]) Grow(amount T) Rectangle[T] {
58+
return Rectangle[T]{r.Center, r.Size.Grow(amount)}
5959
}
6060

61-
// Shrunk creates a new Rectangle with size expanded by the given deltas along X and Y.
62-
func (r Rectangle[T]) ExpandXY(deltaWidth, deltaHeight T) Rectangle[T] {
63-
return Rectangle[T]{r.Center, r.Size.ExpandXY(deltaWidth, deltaHeight)}
61+
// GrowXY creates a new Rectangle with size expanded by the given amounts along X and Y.
62+
func (r Rectangle[T]) GrowXY(amountX, amountY T) Rectangle[T] {
63+
return Rectangle[T]{r.Center, r.Size.GrowXY(amountX, amountY)}
6464
}
6565

66-
// Shrunk creates a new Rectangle with size reduced by the same delta in both dimensions.
67-
func (r Rectangle[T]) Shrunk(delta T) Rectangle[T] {
68-
return Rectangle[T]{r.Center, r.Size.Shrunk(delta)}
66+
// Shrink creates a new Rectangle with size reduced by the same amount in both dimensions.
67+
func (r Rectangle[T]) Shrink(amount T) Rectangle[T] {
68+
return Rectangle[T]{r.Center, r.Size.Shrink(amount)}
6969
}
7070

71-
// Shrunk creates a new Rectangle with size reduced by the given deltas along X and Y.
72-
func (r Rectangle[T]) ShrunkXY(deltaWidth, deltaHeight T) Rectangle[T] {
73-
return Rectangle[T]{r.Center, r.Size.ShrunkXY(deltaWidth, deltaHeight)}
71+
// Shrink creates a new Rectangle with size reduced by the given amounts along X and Y.
72+
func (r Rectangle[T]) ShrinkXY(amountX, amountY T) Rectangle[T] {
73+
return Rectangle[T]{r.Center, r.Size.ShrinkXY(amountX, amountY)}
7474
}
7575

7676
// Width returns the rectangle width.

rectangle_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ func TestRectangle_Resize(t *testing.T) {
4343
}
4444

4545
func TestRectangle_Expand(t *testing.T) {
46-
testRect(t, R(P(1, 2), S(3, 4)).Expand(2), 1, 2, 5, 6)
47-
testRect(t, R(P(1, 2), S(3, 4)).ExpandXY(2, 3), 1, 2, 5, 7)
48-
testRect(t, R(P(0.4, -0.25), S(1.2, 3.4)).Expand(0.1), 0.4, -0.25, 1.3, 3.5)
49-
testRect(t, R(P(0.4, -0.25), S(1.2, 3.4)).ExpandXY(0.1, 0.2), 0.4, -0.25, 1.3, 3.6)
46+
testRect(t, R(P(1, 2), S(3, 4)).Grow(2), 1, 2, 5, 6)
47+
testRect(t, R(P(1, 2), S(3, 4)).GrowXY(2, 3), 1, 2, 5, 7)
48+
testRect(t, R(P(0.4, -0.25), S(1.2, 3.4)).Grow(0.1), 0.4, -0.25, 1.3, 3.5)
49+
testRect(t, R(P(0.4, -0.25), S(1.2, 3.4)).GrowXY(0.1, 0.2), 0.4, -0.25, 1.3, 3.6)
5050
}
5151

5252
func TestRectangle_Shrunk(t *testing.T) {
53-
testRect(t, R(P(1, 2), S(3, 4)).Shrunk(1), 1, 2, 2, 3)
54-
testRect(t, R(P(1, 2), S(3, 4)).ShrunkXY(1, 2), 1, 2, 2, 2)
55-
testRect(t, R(P(0.4, -0.25), S(1.2, 3.4)).Shrunk(0.1), 0.4, -0.25, 1.1, 3.3)
56-
testRect(t, R(P(0.4, -0.25), S(1.2, 3.4)).ShrunkXY(0.1, 0.2), 0.4, -0.25, 1.1, 3.2)
53+
testRect(t, R(P(1, 2), S(3, 4)).Shrink(1), 1, 2, 2, 3)
54+
testRect(t, R(P(1, 2), S(3, 4)).ShrinkXY(1, 2), 1, 2, 2, 2)
55+
testRect(t, R(P(0.4, -0.25), S(1.2, 3.4)).Shrink(0.1), 0.4, -0.25, 1.1, 3.3)
56+
testRect(t, R(P(0.4, -0.25), S(1.2, 3.4)).ShrinkXY(0.1, 0.2), 0.4, -0.25, 1.1, 3.2)
5757
}
5858

5959
func TestRectangle_Width(t *testing.T) {
@@ -146,10 +146,10 @@ func TestRectangle_Immutable(t *testing.T) {
146146
r.Scale(2)
147147
r.ScaleXY(3, 4)
148148
r.Resize(S(5, 6))
149-
r.Expand(1)
150-
r.ExpandXY(1, 2)
151-
r.Shrunk(2)
152-
r.ShrunkXY(2, 3)
149+
r.Grow(1)
150+
r.GrowXY(1, 2)
151+
r.Shrink(2)
152+
r.ShrinkXY(2, 3)
153153

154154
testRect(t, r, 1, 2, 3, 4)
155155
}

regular_polygon.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ func (rp RegularPolygon[T]) MoveTo(point Point[T]) RegularPolygon[T] {
4242
}
4343

4444
// Multiple creates a new RegularPolygon with size scaled by the given factor.
45-
func (rp RegularPolygon[T]) Scale(scale float64) RegularPolygon[T] {
46-
return RegularPolygon[T]{rp.Center, rp.Size.Scale(scale), rp.N}
45+
func (rp RegularPolygon[T]) Scale(factor float64) RegularPolygon[T] {
46+
return RegularPolygon[T]{rp.Center, rp.Size.Scale(factor), rp.N}
4747
}
4848

4949
// Multiple creates a new RegularPolygon with size scaled by the given factors.
50-
func (rp RegularPolygon[T]) ScaleXY(scaleX, scaleY float64) RegularPolygon[T] {
51-
return RegularPolygon[T]{rp.Center, rp.Size.ScaleXY(scaleX, scaleY), rp.N}
50+
func (rp RegularPolygon[T]) ScaleXY(factorX, factorY float64) RegularPolygon[T] {
51+
return RegularPolygon[T]{rp.Center, rp.Size.ScaleXY(factorX, factorY), rp.N}
5252
}
5353

5454
// Vertices returns the polygon vertices in order starting from angle 0, counter-clockwise.

size.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,33 @@ func S[T Number](width, height T) Size[T] {
1414
}
1515

1616
// Scale creates a new Size scaled by the given factor in both dimensions.
17-
func (s Size[T]) Scale(scale float64) Size[T] {
18-
return Size[T]{Multiple(s.Width, scale), Multiple(s.Height, scale)}
17+
func (s Size[T]) Scale(factor float64) Size[T] {
18+
return Size[T]{Multiple(s.Width, factor), Multiple(s.Height, factor)}
1919
}
2020

2121
// ScaleXY creates a new Size scaled by the given factors along X and Y.
22-
func (s Size[T]) ScaleXY(scaleX, scaleY float64) Size[T] {
23-
return Size[T]{Multiple(s.Width, scaleX), Multiple(s.Height, scaleY)}
22+
func (s Size[T]) ScaleXY(factorX, factorY float64) Size[T] {
23+
return Size[T]{Multiple(s.Width, factorX), Multiple(s.Height, factorY)}
2424
}
2525

26-
// Expand creates a new Size expanded by the same delta in both dimensions.
27-
func (s Size[T]) Expand(delta T) Size[T] {
28-
return Size[T]{s.Width + delta, s.Height + delta}
26+
// Grow creates a new Size expanded by the same delta in both dimensions.
27+
func (s Size[T]) Grow(amount T) Size[T] {
28+
return Size[T]{s.Width + amount, s.Height + amount}
2929
}
3030

31-
// ExpandXY creates a new Size expanded by the given deltas along X and Y.
32-
func (s Size[T]) ExpandXY(deltaWidth, deltaHeight T) Size[T] {
33-
return Size[T]{s.Width + deltaWidth, s.Height + deltaHeight}
31+
// GrowXY creates a new Size expanded by the given amounts along X and Y.
32+
func (s Size[T]) GrowXY(amountX, amountY T) Size[T] {
33+
return Size[T]{s.Width + amountX, s.Height + amountY}
3434
}
3535

36-
// Shrunk creates a new Size reduced by the same delta in both dimensions.
37-
func (s Size[T]) Shrunk(delta T) Size[T] {
38-
return Size[T]{s.Width - delta, s.Height - delta}
36+
// Shrink creates a new Size reduced by the same delta in both dimensions.
37+
func (s Size[T]) Shrink(amount T) Size[T] {
38+
return Size[T]{s.Width - amount, s.Height - amount}
3939
}
4040

41-
// ShrunkXY creates a new Size reduced by the given deltas along X and Y.
42-
func (s Size[T]) ShrunkXY(deltaWidth, deltaHeight T) Size[T] {
43-
return Size[T]{s.Width - deltaWidth, s.Height - deltaHeight}
41+
// ShrinkXY creates a new Size reduced by the given amounts along X and Y.
42+
func (s Size[T]) ShrinkXY(amountX, amountY T) Size[T] {
43+
return Size[T]{s.Width - amountX, s.Height - amountY}
4444
}
4545

4646
// Area returns the size's area (width * height).

0 commit comments

Comments
 (0)