not exporting circle size comparisons
This commit is contained in:
parent
0d5ba92fbe
commit
a56f7fa422
16
geometry.go
16
geometry.go
|
@ -384,16 +384,16 @@ func (c Circle) Contains(u Vec) bool {
|
||||||
return c.Radius >= toCenter.Len()
|
return c.Radius >= toCenter.Len()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxCircle will return the larger circle based on the radius.
|
// maxCircle will return the larger circle based on the radius.
|
||||||
func MaxCircle(c, d Circle) Circle {
|
func maxCircle(c, d Circle) Circle {
|
||||||
if c.Radius < d.Radius {
|
if c.Radius < d.Radius {
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// MinCircle will return the smaller circle based on the radius.
|
// minCircle will return the smaller circle based on the radius.
|
||||||
func MinCircle(c, d Circle) Circle {
|
func minCircle(c, d Circle) Circle {
|
||||||
if c.Radius < d.Radius {
|
if c.Radius < d.Radius {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
@ -402,8 +402,8 @@ func MinCircle(c, d Circle) Circle {
|
||||||
|
|
||||||
// Union returns the minimal Circle which covers both `c` and `d`.
|
// Union returns the minimal Circle which covers both `c` and `d`.
|
||||||
func (c Circle) Union(d Circle) Circle {
|
func (c Circle) Union(d Circle) Circle {
|
||||||
biggerC := MaxCircle(c, d)
|
biggerC := maxCircle(c, d)
|
||||||
smallerC := MinCircle(c, d)
|
smallerC := minCircle(c, d)
|
||||||
|
|
||||||
// Get distance between centers
|
// Get distance between centers
|
||||||
dist := c.Center.To(d.Center).Len()
|
dist := c.Center.To(d.Center).Len()
|
||||||
|
@ -432,8 +432,8 @@ func (c Circle) Union(d Circle) Circle {
|
||||||
// centers.
|
// centers.
|
||||||
func (c Circle) Intersect(d Circle) Circle {
|
func (c Circle) Intersect(d Circle) Circle {
|
||||||
// Check if one of the circles encompasses the other; if so, return that one
|
// Check if one of the circles encompasses the other; if so, return that one
|
||||||
biggerC := MaxCircle(c, d)
|
biggerC := maxCircle(c, d)
|
||||||
smallerC := MinCircle(c, d)
|
smallerC := minCircle(c, d)
|
||||||
|
|
||||||
if biggerC.Radius >= biggerC.Center.To(smallerC.Center).Len()+smallerC.Radius {
|
if biggerC.Radius >= biggerC.Center.To(smallerC.Center).Len()+smallerC.Radius {
|
||||||
return biggerC
|
return biggerC
|
||||||
|
|
|
@ -493,79 +493,3 @@ func TestCircle_Intersect(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMaxCircle(t *testing.T) {
|
|
||||||
bigCircle := pixel.C(10, pixel.ZV)
|
|
||||||
smallCircle := pixel.C(1, pixel.ZV)
|
|
||||||
|
|
||||||
type args struct {
|
|
||||||
c pixel.Circle
|
|
||||||
d pixel.Circle
|
|
||||||
}
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
args args
|
|
||||||
want pixel.Circle
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "MaxCircle(): first bigger",
|
|
||||||
args: args{c: bigCircle, d: smallCircle},
|
|
||||||
want: bigCircle,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "MaxCircle(): first smaller",
|
|
||||||
args: args{c: smallCircle, d: bigCircle},
|
|
||||||
want: bigCircle,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "MaxCircle(): both same size",
|
|
||||||
args: args{c: smallCircle, d: smallCircle},
|
|
||||||
want: smallCircle,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
if got := pixel.MaxCircle(tt.args.c, tt.args.d); !reflect.DeepEqual(got, tt.want) {
|
|
||||||
t.Errorf("MaxCircle() = %v, want %v", got, tt.want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMinCircle(t *testing.T) {
|
|
||||||
bigCircle := pixel.C(10, pixel.ZV)
|
|
||||||
smallCircle := pixel.C(1, pixel.ZV)
|
|
||||||
|
|
||||||
type args struct {
|
|
||||||
c pixel.Circle
|
|
||||||
d pixel.Circle
|
|
||||||
}
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
args args
|
|
||||||
want pixel.Circle
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "MinCircle(): first bigger",
|
|
||||||
args: args{c: bigCircle, d: smallCircle},
|
|
||||||
want: smallCircle,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "MinCircle(): first smaller",
|
|
||||||
args: args{c: smallCircle, d: bigCircle},
|
|
||||||
want: smallCircle,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "MinCircle(): both same size",
|
|
||||||
args: args{c: smallCircle, d: smallCircle},
|
|
||||||
want: smallCircle,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
if got := pixel.MinCircle(tt.args.c, tt.args.d); !reflect.DeepEqual(got, tt.want) {
|
|
||||||
t.Errorf("MinCircle() = %v, want %v", got, tt.want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue