namespace Yw.WinFrmUI.Hydro
{
///
/// 包围盒缓存辅助类
///
internal class BoundingBox3CacheHelper
{
///
///
///
public BoundingBox3CacheHelper(NetworkL3d nw, Vector3CacheHelper vc)
{
_nw = nw;
_vc = vc;
Initial();
}
private NetworkL3d _nw = null;
private Vector3CacheHelper _vc = null;
private Dictionary _dict = new();
///
/// 是否初始化
///
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)(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);
}
}));
}
///
/// 通过 Id 获取
///
public BoundingBox3 GetById(string Id)
{
if (!Initialized)
{
return default;
}
if (_dict.ContainsKey(Id))
{
return _dict[Id];
}
return default;
}
}
}