public static bool Unify(this LineSymbol shapeSymbol, object constraint, out object output) { output = shapeSymbol.Unify(constraint); return(output != null); }
/// <summary> /// construct a line through two points /// </summary> /// <param name="pt1"></param> /// <param name="pt2"></param> /// <returns></returns> public static object Unify(PointSymbol pt1, PointSymbol pt2, EqGoal goal = null) { //point identify check if (pt1.Equals(pt2)) { return(null); } //Line build process if (pt1.Shape.Concrete && pt2.Shape.Concrete) { var point1 = pt1.Shape as Point; var point2 = pt2.Shape as Point; Debug.Assert(point1 != null); Debug.Assert(point2 != null); var winPt1 = new System.Windows.Point((double)point1.XCoordinate, (double)point1.YCoordinate); var winPt2 = new System.Windows.Point((double)point2.XCoordinate, (double)point2.YCoordinate); var lineSymbol = LineGenerationRule.GenerateLine(point1, point2); if (lineSymbol == null) { return(null); } var line = lineSymbol.Shape as Line; Debug.Assert(line != null); line.Rel1 = winPt1; line.Rel2 = winPt2; TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, lineSymbol); return(lineSymbol); } else { //lazy evaluation //Constraint solving on Graph var line = new Line(null); //ghost line line.Rel1 = pt1.Shape; line.Rel2 = pt2.Shape; var ls = new LineSymbol(line); #region Reification Purpose if (pt1.Shape.Concrete && !pt2.Shape.Concrete) { var point1 = pt1.Shape as Point; if (pt2.CachedSymbols.Count != 0) { foreach (ShapeSymbol ss in pt2.CachedSymbols) { var ps = ss as PointSymbol; Debug.Assert(ps != null); Debug.Assert(ps.Shape.Concrete); var cachePoint = ps.Shape as Point; Debug.Assert(cachePoint != null); var gline = LineGenerationRule.GenerateLine(point1, cachePoint); gline.Traces.AddRange(ps.Traces); TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline); ls.CachedSymbols.Add(gline); } } } if (!pt1.Shape.Concrete && pt2.Shape.Concrete) { var point2 = pt2.Shape as Point; if (pt1.CachedSymbols.Count != 0) { foreach (ShapeSymbol ss in pt1.CachedSymbols) { var ps = ss as PointSymbol; Debug.Assert(ps != null); Debug.Assert(ps.Shape.Concrete); var cachePoint = ps.Shape as Point; Debug.Assert(cachePoint != null); var gline = LineGenerationRule.GenerateLine(cachePoint, point2); gline.Traces.AddRange(ps.Traces); TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline); ls.CachedSymbols.Add(gline); } } } if (!pt1.Shape.Concrete && !pt2.Shape.Concrete) { foreach (ShapeSymbol ss1 in pt1.CachedSymbols) { foreach (ShapeSymbol ss2 in pt2.CachedSymbols) { var ps1 = ss1 as PointSymbol; Debug.Assert(ps1 != null); Debug.Assert(ps1.Shape.Concrete); var cachePoint1 = ps1.Shape as Point; Debug.Assert(cachePoint1 != null); var ps2 = ss2 as PointSymbol; Debug.Assert(ps2 != null); Debug.Assert(ps2.Shape.Concrete); var cachePoint2 = ps2.Shape as Point; Debug.Assert(cachePoint2 != null); var gline = LineGenerationRule.GenerateLine(cachePoint1, cachePoint2); gline.Traces.AddRange(ps1.Traces); gline.Traces.AddRange(ps2.Traces); TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline); ls.CachedSymbols.Add(gline); } } } #endregion if (goal != null) { return(ls.Unify(goal)); } return(ls); } }
/// <summary> /// construct a line through two points /// </summary> /// <param name="pt1"></param> /// <param name="pt2"></param> /// <returns></returns> public static object Unify(PointSymbol pt1, PointSymbol pt2, EqGoal goal = null) { //point identify check if (pt1.Equals(pt2)) return null; //Line build process if (pt1.Shape.Concrete && pt2.Shape.Concrete) { var point1 = pt1.Shape as Point; var point2 = pt2.Shape as Point; Debug.Assert(point1 != null); Debug.Assert(point2 != null); var winPt1 = new System.Windows.Point((double) point1.XCoordinate, (double) point1.YCoordinate); var winPt2 = new System.Windows.Point((double) point2.XCoordinate, (double) point2.YCoordinate); var lineSymbol = LineGenerationRule.GenerateLine(point1, point2); if (lineSymbol == null) return null; var line = lineSymbol.Shape as Line; Debug.Assert(line != null); line.Rel1 = winPt1; line.Rel2 = winPt2; TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, lineSymbol); return lineSymbol; } else { //lazy evaluation //Constraint solving on Graph var line = new Line(null); //ghost line line.Rel1 = pt1.Shape; line.Rel2 = pt2.Shape; var ls = new LineSymbol(line); #region Reification Purpose if (pt1.Shape.Concrete && !pt2.Shape.Concrete) { var point1 = pt1.Shape as Point; if (pt2.CachedSymbols.Count != 0) { foreach (ShapeSymbol ss in pt2.CachedSymbols) { var ps = ss as PointSymbol; Debug.Assert(ps != null); Debug.Assert(ps.Shape.Concrete); var cachePoint = ps.Shape as Point; Debug.Assert(cachePoint != null); var gline = LineGenerationRule.GenerateLine(point1, cachePoint); gline.Traces.AddRange(ps.Traces); TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline); ls.CachedSymbols.Add(gline); } } } if (!pt1.Shape.Concrete && pt2.Shape.Concrete) { var point2 = pt2.Shape as Point; if (pt1.CachedSymbols.Count != 0) { foreach (ShapeSymbol ss in pt1.CachedSymbols) { var ps = ss as PointSymbol; Debug.Assert(ps != null); Debug.Assert(ps.Shape.Concrete); var cachePoint = ps.Shape as Point; Debug.Assert(cachePoint != null); var gline = LineGenerationRule.GenerateLine(cachePoint, point2); gline.Traces.AddRange(ps.Traces); TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline); ls.CachedSymbols.Add(gline); } } } if (!pt1.Shape.Concrete && !pt2.Shape.Concrete) { foreach (ShapeSymbol ss1 in pt1.CachedSymbols) { foreach (ShapeSymbol ss2 in pt2.CachedSymbols) { var ps1 = ss1 as PointSymbol; Debug.Assert(ps1 != null); Debug.Assert(ps1.Shape.Concrete); var cachePoint1 = ps1.Shape as Point; Debug.Assert(cachePoint1 != null); var ps2 = ss2 as PointSymbol; Debug.Assert(ps2 != null); Debug.Assert(ps2.Shape.Concrete); var cachePoint2 = ps2.Shape as Point; Debug.Assert(cachePoint2 != null); var gline = LineGenerationRule.GenerateLine(cachePoint1, cachePoint2); gline.Traces.AddRange(ps1.Traces); gline.Traces.AddRange(ps2.Traces); TraceInstructionalDesign.FromPointPointToLine(pt1, pt2, gline); ls.CachedSymbols.Add(gline); } } } #endregion if (goal != null) { return ls.Unify(goal); } return ls; } }