lixiaojun
2025-03-21 d03e8c5d165426f820c10e0c876e5c6af14d270b
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
namespace Yw.WinFrmUI.Hydro
{
    /// <summary>
    /// 包围盒缓存辅助类
    /// </summary>
    internal class BoundingBox3CacheHelper
    {
 
        /// <summary>
        /// 
        /// </summary>
        public BoundingBox3CacheHelper(NetworkL3d nw, Vector3CacheHelper vc)
        {
            _nw = nw;
            _vc = vc;
            Initial();
        }
 
        private NetworkL3d _nw = null;
        private Vector3CacheHelper _vc = null;
        private Dictionary<string, BoundingBox3> _dict = new();
 
        /// <summary>
        /// 是否初始化
        /// </summary>
        public bool Initialized
        {
            get
            {
                if (_nw == null)
                {
                    return false;
                }
                if (_vc == null)
                {
                    return false;
                }
                if (_dict.Count < 1)
                {
                    return false;
                }
                return true;
            }
        }
 
        //初始化
        private void Initial()
        {
            if (_nw == null)
            {
                return;
            }
            if (_vc == null)
            {
                return;
            }
            _dict.Clear();
            _nw.Nodes.ForEach(x =>
            {
                var pts = _vc.GetById(x.Id);
                if (pts != null && pts.Count > 0)
                {
                    var bx = BoundingBox3Helper.CalcuPointBoundingBox(pts[0], x.Style2d.Normal.Radiu);
                    _dict.Add(x.Id, bx);
                }
            });
            _nw.Links.ForEach((Action<LinkL3d>)(x =>
            {
                var pts = _vc.GetById(x.Id);
                if (pts != null && pts.Count > 1)
                {
                    var bx = BoundingBox3Helper.CalcuLineBoundingBox(pts[0], pts[1], x.Style2d.Normal.Width);
                    _dict.Add(x.Id, bx);
                }
            }));
        }
 
        /// <summary>
        /// 通过 Id 获取
        /// </summary>
        public BoundingBox3 GetById(string Id)
        {
            if (!Initialized)
            {
                return default;
            }
            if (_dict.ContainsKey(Id))
            {
                return _dict[Id];
            }
            return default;
        }
 
 
    }
}