public static bool IsLineSegmentIntersection(IPoint a1, IPoint a2, IPoint b1, IPoint b2) { LogTool.AssertIsTrue(a1 != a2); LogTool.AssertIsTrue(b1 != b2); LogTool.AssertIsFalse(a1 == b1 && a2 == b2); var da = a2.Position - a1.Position; var db = b2.Position - b1.Position; var dc = b1.Position - a1.Position; if (math.dot(dc, math.cross(da, db)) != 0) { return(false); } var n2 = Norm2(math.cross(da, db)); var s = math.dot(math.cross(dc, db), math.cross(da, db)) / n2; var t = math.dot(math.cross(dc, da), math.cross(da, db)) / n2; if (s >= 0 && s <= 1 && t >= 0 && t <= 1) { return(true); } return(false); }
public void RunTest() { var p1 = new Point() { Position = new float3(0, 0, 0) }; var p2 = new Point() { Position = new float3(1, 1, 0) }; var p3 = new Point() { Position = new float3(0, 1, 0) }; var p4 = new Point() { Position = new float3(1, 0, 0) }; var p5 = new Point() { Position = new float3(1, 0, 0) }; var p6 = new Point() { Position = new float3(2, 0, 0) }; LogTool.AssertIsTrue(GeometryTools.IsLineSegmentIntersection(p1, p2, p3, p4)); LogTool.AssertIsFalse(GeometryTools.IsLineSegmentIntersection(p1, p2, p5, p6)); }
public ComputeShaderParameter(string name, T defaultValue = default(T)) { LogTool.AssertIsFalse(string.IsNullOrEmpty(name)); if (string.IsNullOrEmpty(name)) { Debug.LogWarningFormat("Name is null"); return; } this.VariableName = name; this.data = defaultValue; }
protected void TestNewGraph(NewGraph <IndexVertex, DefaultEdge, IndexGraphFactory> graph) { foreach (var e in Enumerable.Range(0, 20)) { graph.Add(graph.Factory.CreateVertex()); } var nodes = graph.Vertices.OrderBy(v => v.index).ToList(); var e01 = graph.AddEdge(nodes[0], nodes[1]); var e02 = graph.Factory.CreateEdge(nodes[3], nodes[4]); var e56 = graph.AddEdge(nodes[5], nodes[6]); graph.AddEdge(nodes[5], nodes[7]); graph.AddEdge(nodes[5], nodes[8]); graph.AddEdge(nodes[5], nodes[5]); graph.AddEdge(nodes[5], nodes[1]); graph.AddEdge(nodes[5], nodes[11], true); graph.AddEdge(nodes[1], nodes[15]); LogTool.AssertIsTrue(graph.Contains(e01)); LogTool.AssertIsFalse(graph.Contains(e02)); LogTool.AssertIsTrue(e56 == graph.GetEdge(nodes[5], nodes[6])); LogTool.AssertIsTrue(e56 == graph.GetEdge(nodes[6], nodes[5])); LogTool.AssertIsFalse(e56 == graph.GetEdge(nodes[5], nodes[5])); foreach (var e in graph.Edges) { LogTool.Log(e.ToString()); } LogTool.Log("Neighbor 5"); foreach (var e in graph.GetNeighborVertices(nodes[5])) { LogTool.Log(e.ToString()); } }
protected static void MergeVertexTo(INewGraph graph, IVertex from, IVertex to) { LogTool.AssertIsFalse(from.Equals(to)); var fromNeighbors = graph.GetNeighborVertices(from as Common.IVertex).ToList(); foreach (var n in fromNeighbors) { var e = graph.GetEdge(from as Common.IVertex, n); LogTool.AssertNotNull(e); graph.Remove(e); if (n.Equals(to)) { continue; } graph.AddEdge(n, to as Common.IVertex); } graph.Remove(from as Common.IVertex); foreach (var n in fromNeighbors) { UpdateEdgeCost(graph, n as IVertex); } }
static public T Read <T>(string filePath, SerializerType type = SerializerType.Binary) { var ret = default(T); #if UNITY_ANDROID && !UNITY_EDITOR if (true) #else if (File.Exists(filePath)) #endif { try { switch (type) { case SerializerType.XML: { #if UNITY_ANDROID && !UNITY_EDITOR var web = UnityEngine.Networking.UnityWebRequest.Get(filePath); web.SendWebRequest(); while (!web.isDone) { ; } LogTool.AssertIsFalse(web.isNetworkError); LogTool.AssertIsFalse(web.isHttpError); var text = web.downloadHandler.data; web.Dispose(); using (var fs = new MemoryStream(text)) #else using (var fs = new StreamReader(filePath, System.Text.Encoding.UTF8)) #endif { var serializer = new XmlSerializer(typeof(T)); ret = (T)serializer.Deserialize(fs); fs.Close(); } } break; case SerializerType.Json: { using (var fs = new StreamReader(filePath, System.Text.Encoding.UTF8)) { var json = fs.ReadToEnd(); ret = JsonUtility.FromJson <T>(json); fs.Close(); } } break; case SerializerType.Binary: { using (var fs = new FileStream(filePath, FileMode.Open)) { var serializer = new BinaryFormatter(); ret = (T)serializer.Deserialize(fs); fs.Flush(); fs.Close(); } } break; } } catch (Exception e) { LogTool.Log(e.Message + " " + filePath, LogLevel.Warning, LogChannel.IO); } } else { LogTool.Log(filePath + " not found", LogLevel.Warning, LogChannel.IO); } return(ret); }
public void AddController(FishController controller) { LogTool.AssertIsFalse(this.CurrentQueue.Contains(controller)); this.CurrentQueue.AddLast(controller); }