private Thing AddAngleandRelationship(float greatestLength, Thing nextAreaCorner, Thing newShapeCorner, int refIndex, Thing theShape, Thing nextShapeCorner = null) { //find the angle Angle a; ModuleBoundarySegments.Arc seg1; ModuleBoundarySegments.Arc seg2; if (nextAreaCorner.References.Count == 1) { a = 0; seg1 = new ModuleBoundarySegments.Arc { p1 = (Point)nextAreaCorner.Children[0].V, p2 = (Point)nextAreaCorner.Children[0].V }; seg2 = new ModuleBoundarySegments.Arc { p1 = (Point)nextAreaCorner.Children[0].V, p2 = (Point)nextAreaCorner.Children[0].V }; } else { Point cnrPt = (Point)nextAreaCorner.Children[0].V; Point p1 = (Point)nextAreaCorner.References[0].T.Children[0].V; Point p2 = (Point)nextAreaCorner.References[1].T.Children[0].V; seg1 = new ModuleBoundarySegments.Arc { p1 = cnrPt, p2 = p1 }; seg2 = new ModuleBoundarySegments.Arc { p1 = cnrPt, p2 = p2 }; a = Angle.FromDegrees((float)Vector.AngleBetween(cnrPt - p1, cnrPt - p2)); a = Math.Abs(a); a = Angle.FromDegrees((float)(Math.Round(a.ToDegrees() / 15) * 15)); } string s = "Ang" + (int)a.ToDegrees(); Thing value = uks.GetOrAddThing("Value", "Thing"); newShapeCorner.AddReference(uks.GetOrAddThing(s, value)); float lenToNextCorner; if (refIndex == 0) { lenToNextCorner = seg1.Length / greatestLength; //normalize the lengths } else { lenToNextCorner = seg2.Length / greatestLength; //normalize the lengths } lenToNextCorner = (float)Math.Round(lenToNextCorner, 1); s = "Len" + lenToNextCorner.ToString("f1"); if (nextShapeCorner == null) { nextShapeCorner = uks.AddThing("Cnr*", theShape); } newShapeCorner.AddRelationship(nextShapeCorner, uks.GetOrAddThing(s, value)); return(nextShapeCorner); }
private void AddRelationshipsToUKS(Thing t1, Thing t2) { if (t1 == null || t2 == null) { return; } //DeletePreviousRelationships(t1, t2); var vals1 = uks.GetValues(t1); var vals2 = uks.GetValues(t2); foreach (var pair1 in vals1) { //if (!pair1.Key.Contains("Siz")) continue; var val2 = vals2[pair1.Key]; //hue is special because it is an angle which wraps around so < & > are not really defined if (pair1.Key == "Hue+") { Angle diff = (pair1.Value - val2) * 2 * Math.PI; diff = (diff.ToDegrees() + 180) % 360 - 180; diff = Angle.FromDegrees(diff); if (Math.Abs(diff) < Angle.FromDegrees(10)) { t1.AddRelationship(t2, uks.GetOrAddThing("=" + pair1.Key, "Relationship")); } else { t1.AddRelationship(t1, uks.GetOrAddThing("!" + pair1.Key, "Relationship")); } } else if (pair1.Key.EndsWith("+")) { //value comparison if (Math.Abs(pair1.Value - val2) == 0) //TODO make this tolerance a parameter { t1.AddRelationship(t2, uks.GetOrAddThing("=" + pair1.Key, "Relationship")); } else if (pair1.Value > val2) { t1.AddRelationship(t2, uks.GetOrAddThing("<" + pair1.Key, "Relationship")); } else { t1.AddRelationship(t2, uks.GetOrAddThing(">" + pair1.Key, "Relationship")); } } else { //equality comparison if (pair1.Value == val2) { t1.AddRelationship(t2, uks.GetOrAddThing("=" + pair1.Key.Replace("Saved", ""), "Relationship")); } else { t1.AddRelationship(t2, uks.GetOrAddThing("!" + pair1.Key.Replace("Saved", ""), "Relationship")); } } } }