-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconcentric.go
81 lines (68 loc) · 1.83 KB
/
concentric.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package slice
type Concentric struct {
Spacing float64
}
func (in *Concentric) Fill(r *Region) {
// each concentric circle is generated generated based on the previous.
// start with the Region's exterior.
lastRound := r.Exterior
for round := 0; round < 1; round++ {
dprintf("starting concentric infill round %d", round)
roundStart := len(r.Infill)
// shift everything inwards
for _, s := range lastRound {
shift := s.Normal.Mul(in.Spacing)
infillSegment := *s
infillSegment.ShiftBy(shift)
r.Infill = append(r.Infill, &infillSegment)
}
roundEnd := len(r.Infill)
if roundEnd == roundStart {
// no new segments, we're done.
break
}
dprintf("added %d segments in round %d", roundEnd-roundStart, round)
lastRound = r.Infill[roundStart:roundEnd]
// join and trim newly shifted segments.
// there will be some overlapping, which we will eliminate in the next phase.
in.connect(lastRound)
// eliminate overlapping segments
in.trim(lastRound)
// regroup into regions
// TODO
}
}
func (in *Concentric) connect(segments []*Segment) {
for i := 0; i < len(segments); i++ {
a := segments[i]
j := (i + 1) % len(segments)
b := segments[j]
aLine := a.getLine()
bLine := b.getLine()
intersection, err := aLine.intersect(bLine)
if err == errNoIntersections {
wprintf("can't connect: no intersections!")
} else {
a.To = intersection
b.From = intersection
}
}
}
func (in *Concentric) trim(segments []*Segment) {
// for i := 0; i < len(segments); i++ {
// current := segments[i]
// for {
// ss, vv := current.getIntersections(segments)
// if len(ss) == 0 {
// break
// }
// if vv[0].distFrom(current.From) < vv[0].distFrom(current.To) {
// ss[0].To = vv[0]
// current.From = vv[0]
// } else {
// current.To = vv[0]
// ss[0].From = vv[0]
// }
// }
// }
}