MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / propagate

Method propagate

src/main/java/trace/simulation/Boids.kt:50–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48 var W = 1.0
49
50 private fun propagate(a: Boid, all: MutableList<Boid>, speed: Double): Boid {
51
52 val all2 = mutableListOf<Boid>()
53 all2.addAll(all)
54
55 all2.sortBy { it.at.distanceSquared(a.at) }
56 all.sortBy { it.at.distanceSquared(a.at) }
57
58 all2.addAll(0, important)
59 val n = Math.min(7 + important.size, all2.size - 1)
60
61 val center = Vec2(a.at)
62 val heading = Vec2(a.heading) * W // LPF
63
64 for (x in 1 until n) {
65 center %= center + all2[x].at
66 heading %= heading + all2[x].heading
67 }
68
69 center %= center * (1.0 / (1.0 + n))
70 heading %= heading * (1.0 / (W + n))
71
72 if (heading.length() == 0.0) heading %= Vec2(0.0, 0.0).noise(1.0F).safeNormalize()
73 else heading.normalize()
74
75 // other behaviors
76
77 if (all.size > 1) {
78 tweakHeading(heading, a, all[1], center, tooFar)
79 for(i in important.size-1 downTo 0)
80 {
81 tweakHeading(heading, a, all2[i], all2[i].at, tooFar*5)
82 }
83 }
84 return Boid(a.at + heading * a.speed * speed, heading, a.speed, a.misc)
85 }
86
87 private fun tweakHeading(heading: Vec2, a: Boid, all: Boid, center : Vec2, tooFar : Double) {
88 val Z = all.at.distance(a.at)

Callers 14

infer.jsFile · 0.80
setFunctionInstantiatedFunction · 0.80
joinFunction · 0.80
inferClassFunction · 0.80
arrayLiteralTypeFunction · 0.80
retFunction · 0.80
generatorResultFunction · 0.80
resolveFileFunction · 0.80
extractPropFunction · 0.80
computedUnionFunction · 0.80
def.jsFile · 0.80
addArgCallEffectFunction · 0.80

Calls 8

BoidClass · 0.85
Vec2Class · 0.50
addAllMethod · 0.45
distanceSquaredMethod · 0.45
minMethod · 0.45
lengthMethod · 0.45
noiseMethod · 0.45
normalizeMethod · 0.45

Tested by

no test coverage detected