From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XMainClient/XPieceWiseDataMgr.cs | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XPieceWiseDataMgr.cs (limited to 'Client/Assets/Scripts/XMainClient/XPieceWiseDataMgr.cs') diff --git a/Client/Assets/Scripts/XMainClient/XPieceWiseDataMgr.cs b/Client/Assets/Scripts/XMainClient/XPieceWiseDataMgr.cs new file mode 100644 index 00000000..e122f71f --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XPieceWiseDataMgr.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XPieceWiseDataMgr + { + private List> m_Datas = new List>(); + + private bool bRangeIsSet = false; + + private bool bDataIsSet = false; + + private XOrderData m_Min; + + private XOrderData m_Max; + + public void SetRange(double xmin, double ymin, double xmax, double ymax) + { + this.m_Min.x = xmin; + this.m_Min.y = ymin; + this.m_Max.x = xmax; + this.m_Max.y = ymax; + this.bRangeIsSet = true; + bool flag = this.bDataIsSet; + if (flag) + { + this.m_Datas.Add(this.m_Min); + this.m_Datas.Add(this.m_Max); + this.m_Datas.Sort(); + } + } + + public void Init(ref SeqListRef datas) + { + bool flag = false; + bool flag2 = false; + this.m_Datas.Clear(); + for (int i = 0; i < datas.Count; i++) + { + XOrderData xorderData; + xorderData.x = (double)datas[i, 0]; + xorderData.y = (double)datas[i, 1]; + this.m_Datas.Add(xorderData); + bool flag3 = this.bRangeIsSet; + if (flag3) + { + bool flag4 = xorderData.x == this.m_Min.x; + if (flag4) + { + flag = true; + } + else + { + bool flag5 = xorderData.x == this.m_Max.x; + if (flag5) + { + flag2 = true; + } + } + } + } + bool flag6 = this.bRangeIsSet; + if (flag6) + { + bool flag7 = !flag; + if (flag7) + { + this.m_Datas.Add(this.m_Min); + } + bool flag8 = !flag2; + if (flag8) + { + this.m_Datas.Add(this.m_Max); + } + } + this.m_Datas.Sort(); + this.bDataIsSet = true; + } + + public double GetData(double x) + { + for (int i = 1; i < this.m_Datas.Count; i++) + { + bool flag = this.m_Datas[i].x >= x; + if (flag) + { + XOrderData xorderData = this.m_Datas[i - 1]; + XOrderData xorderData2 = this.m_Datas[i]; + double num = xorderData2.x - xorderData.x; + bool flag2 = num == 0.0; + if (flag2) + { + num = 1.0; + } + return xorderData.y + (xorderData2.y - xorderData.y) * (x - xorderData.x) / num; + } + } + return 0.0; + } + } +} -- cgit v1.1-26-g67d0