-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.go
More file actions
67 lines (53 loc) · 1.68 KB
/
validate.go
File metadata and controls
67 lines (53 loc) · 1.68 KB
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
package constdp
import (
"github.com/TopoSimplify/constrain"
"github.com/TopoSimplify/ctx"
"github.com/TopoSimplify/hdb"
"github.com/TopoSimplify/knn"
"github.com/TopoSimplify/node"
)
func (self *ConstDP) ValidateMerge(hull *node.Node, hulldb *hdb.Hdb) bool {
var bln = true
var sideEffects []*node.Node
// self intersection constraint
if self.Opts.AvoidNewSelfIntersects {
bln = constrain.BySelfIntersection(
self.Opts, hull, hulldb, &sideEffects,
)
}
if len(sideEffects) != 0 || !bln {
return false
}
// context geometry constraint
bln = self.ValidateContextRelation(hull, &sideEffects)
return bln && (len(sideEffects) == 0)
}
//Constrain for context neighbours
// finds the collapsibility of hull with respect to context hull neighbours
// if hull is deformable, its added to selections
func (self *ConstDP) ValidateContextRelation(hull *node.Node, selections *[]*node.Node) bool {
var bln = true
if !(self.Opts.GeomRelation || self.Opts.DistRelation || self.Opts.DirRelation) {
return bln
}
// find context neighbours - if valid
var boxObjs = knn.ContextNeighbours(self.ContextDB, hull.Geom, self.Opts.MinDist)
var neighbours = make([]*ctx.ContextGeometry, len(boxObjs))
for i, o := range boxObjs {
neighbours[i] = o.Geom.(*ctx.ContextGeometry)
}
var ctxtgeoms = (&ctx.ContextGeometries{}).SetData(neighbours)
if bln && self.Opts.GeomRelation {
bln = constrain.ByGeometricRelation(hull, ctxtgeoms)
}
if bln && self.Opts.DistRelation {
bln = constrain.ByMinDistRelation(self.Options(), hull, ctxtgeoms)
}
if bln && self.Opts.DirRelation {
bln = constrain.BySideRelation(hull, ctxtgeoms)
}
if !bln {
*selections = append(*selections, hull)
}
return bln
}