- clampTo's doc justified itself by stopping hexCenters "looping forever", which stopped being true when hexCenters became count-bounded. Say what it actually does now, and note the inversion the new guard relies on. - Trim the changelog prose from hexCenters' doc down to the one line that earns its keep: don't re-anchor at the min corner, and why. - Rename a test local from `max` so it stops shadowing the builtin. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01H3zbym8Doka2d7D48maSgZ
This commit is contained in:
@@ -29,7 +29,10 @@ type Region struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// clampTo intersects the region with an object's local bounds (±halfW, ±halfH),
|
// clampTo intersects the region with an object's local bounds (±halfW, ±halfH),
|
||||||
// so an oversized caller-supplied region can't make hexCenters loop forever.
|
// so a fill can't plant outside the object it was aimed at.
|
||||||
|
//
|
||||||
|
// Note this INVERTS (Max ends up below Min) rather than empties a region that
|
||||||
|
// misses the object altogether — hexCenters treats that as "nothing to plant".
|
||||||
func (r Region) clampTo(halfW, halfH float64) Region {
|
func (r Region) clampTo(halfW, halfH float64) Region {
|
||||||
return Region{
|
return Region{
|
||||||
MinX: math.Max(r.MinX, -halfW), MinY: math.Max(r.MinY, -halfH),
|
MinX: math.Max(r.MinX, -halfW), MinY: math.Max(r.MinY, -halfH),
|
||||||
@@ -187,10 +190,9 @@ type localPoint struct{ x, y float64 }
|
|||||||
// the edge that the rule asks for. Overhang is capped there and nowhere near the
|
// the edge that the rule asks for. Overhang is capped there and nowhere near the
|
||||||
// full radius: a clump mostly outside the bed is a drawing of plants in the path.
|
// full radius: a clump mostly outside the bed is a drawing of plants in the path.
|
||||||
//
|
//
|
||||||
// Anchoring at the min corner instead (what this did originally) was wrong twice
|
// Do not "simplify" this back to anchoring at the region's min corner. That is
|
||||||
// over: staggered rows started a FULL pitch in, leaving a clump-sized bare strip
|
// what #75 was: staggered rows start a full pitch in, and the leftover all lands
|
||||||
// down one side of every other row, while the far edge had clumps hanging off it
|
// on the far edge, where clumps hang outside a bed that nothing clips them to.
|
||||||
// by 13cm — and nothing clips them, so they drew outside the bed.
|
|
||||||
func hexCenters(r Region, radius, spacing float64) []localPoint {
|
func hexCenters(r Region, radius, spacing float64) []localPoint {
|
||||||
if radius <= 0 {
|
if radius <= 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -103,14 +103,14 @@ func TestHexCentersEdgeInset(t *testing.T) {
|
|||||||
|
|
||||||
// A clump may cross the edge, but only by the half-spacing the rule
|
// A clump may cross the edge, but only by the half-spacing the rule
|
||||||
// allows — never enough to be mostly out in the path.
|
// allows — never enough to be mostly out in the path.
|
||||||
max := tc.spacing / 2
|
budget := tc.spacing / 2
|
||||||
for _, p := range pts {
|
for _, p := range pts {
|
||||||
over := math.Max(
|
over := math.Max(
|
||||||
math.Max(r.MinX-(p.x-tc.radius), (p.x+tc.radius)-r.MaxX),
|
math.Max(r.MinX-(p.x-tc.radius), (p.x+tc.radius)-r.MaxX),
|
||||||
math.Max(r.MinY-(p.y-tc.radius), (p.y+tc.radius)-r.MaxY),
|
math.Max(r.MinY-(p.y-tc.radius), (p.y+tc.radius)-r.MaxY),
|
||||||
)
|
)
|
||||||
if over > max+1e-6 {
|
if over > budget+1e-6 {
|
||||||
t.Errorf("plop at (%.1f,%.1f) overhangs by %.2f, max %.2f", p.x, p.y, over, max)
|
t.Errorf("plop at (%.1f,%.1f) overhangs by %.2f, budget %.2f", p.x, p.y, over, budget)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user