using sam; using System; using System.Collections.Generic; using UnityEngine; public class HeightDataSetOverlapChecker : MonoBehaviour { List altBottomList, altTopList; List durationList; struct QuadData { public float l, r, b, t; } public void OnProductSelected(ProductData data) { int n = data.dataPoints.Count; ProductUserData ud = data.profile.GetUserData("AltBottom"); altBottomList = (data.userData[ud.fieldIndex] as List); ud = data.profile.GetUserData("AltTop"); altTopList = (data.userData[ud.fieldIndex] as List); ud = data.profile.GetUserData("DeltaSeconds"); durationList = (data.userData[ud.fieldIndex] as List); QuadData[] quads = new QuadData[n]; DateTime firstTime = data.dataPoints[0].time; for (int i = 0; i < n; i++) { ProductDataPoint dp = data.dataPoints[i]; DateTime startTime = dp.time; float l = (float)(dp.time - firstTime).TotalSeconds; float r = l + durationList[i]; float b = altBottomList[i]; float t = altTopList[i]; quads[i] = new QuadData { l = l, r = r, b = b, t = t }; } for (int i = 0; i < n; i++) { QuadData q1 = quads[i]; for (int j = i + 1; j < n; j++) { QuadData q2 = quads[j]; if (QuadsIntersect(q1, q2)) { float a1 = (q1.r - q1.l) * (q1.t - q1.b); float a2 = (q2.r - q2.l) * (q2.t - q2.b); float il = Math.Max(q1.l, q2.l); float ir = Math.Min(q1.r, q2.r); float ib = Math.Max(q1.b, q2.b); float it = Math.Min(q1.t, q2.t); float ai = (ir - il) * (it - ib); float f1 = ai / a1; float f2 = ai / a2; if (f1 > 0.25f && f2 > 0.25f) Debug.LogWarning($"Quads {i} and {j} intersect with fractions: ({f1}, {f2})"); } } } } bool QuadsIntersect(QuadData q1, QuadData q2) { return !((q1.r < q2.l) || (q2.r < q1.l) || (q1.t < q2.b) || (q2.t < q1.b)); } }