fix: cr, validateNear outside connection

This commit is contained in:
donglixiaoche 2023-03-28 21:10:37 +08:00
parent d85bb2d16f
commit b9dd247c75
No known key found for this signature in database
GPG key ID: 3190E65EBAD6D6E2

View file

@ -736,12 +736,14 @@ func (c *compiler) validateNear(g *d2graph.Graph) {
continue
}
descendantsMap := getNearDescendants(obj)
connectToOutside := false
for _, edge := range g.Edges {
if (descendantsMap[edge.Src] && !descendantsMap[edge.Dst]) ||
(!descendantsMap[edge.Src] && descendantsMap[edge.Dst]) {
srcNearContainer := edge.Src.OuterNearContainer()
dstNearContainer := edge.Dst.OuterNearContainer()
if srcNearContainer != dstNearContainer {
connectToOutside = true
break
}
}
@ -757,24 +759,6 @@ func (c *compiler) validateNear(g *d2graph.Graph) {
}
}
func getNearDescendants(nearObj *d2graph.Object) map[*d2graph.Object]bool {
descendantsMap := make(map[*d2graph.Object]bool)
var helper func(obj *d2graph.Object)
helper = func(obj *d2graph.Object) {
if obj.ChildrenArray != nil {
for _, child := range obj.ChildrenArray {
descendantsMap[child] = true
helper(child)
}
}
}
helper(nearObj)
return descendantsMap
}
func (c *compiler) validateBoardLinks(g *d2graph.Graph) {
for _, obj := range g.Objects {
if obj.Attributes.Link == nil {