-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCandidate.swift
54 lines (45 loc) · 1.39 KB
/
Candidate.swift
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
//
// Candidate.swift
// AdministrativeSphereBuilder
//
// Created by Lucka on 17/10/2024.
//
import SphereGeometry
struct Candidate {
let cell: Cell
let identifier: CellIdentifier
let intersectedChildren: [ Cell ]
let containedChildren: [ Cell ]
init(cell: Cell, for geometry: CellAlgebra) {
self.cell = cell
self.identifier = cell.identifier
var intersectedChildren: [ Cell ] = [ ]
var containedChildren: [ Cell ] = [ ]
for child in cell.children {
switch geometry.relation(with: child) {
case .intersect:
intersectedChildren.append(child)
case .contain:
containedChildren.append(child)
default:
break
}
}
self.intersectedChildren = intersectedChildren
self.containedChildren = containedChildren
}
}
extension Candidate {
static func prior(lhs: Self, rhs: Self) -> Bool {
lhs.priority < rhs.priority
}
var availableChildrenCount: Int {
intersectedChildren.count + containedChildren.count
}
var coveringMoreThanHalf: Bool {
intersectedChildren.count + containedChildren.count * 2 >= 4
}
var priority: Int {
(Int(cell.level.rawValue) << 6) + (intersectedChildren.count << 3) + (containedChildren.count)
}
}