private static bool ConstraintCheck(GoalNode goalNode1, GoalNode goalNode2, object constraint, out object output) { Debug.Assert(constraint != null); var st = constraint as ShapeType?; var goal1 = goalNode1.Goal as EqGoal; var goal2 = goalNode2.Goal as EqGoal; Debug.Assert(goal1 != null); Debug.Assert(goal2 != null); output = null; if (st != null) { switch (st.Value) { case ShapeType.Line: output = LineBinaryRelation.Unify(goal1, goal2); break; } return(output != null); } var label = constraint as string; if (label != null) { //TODO if (LineAcronym.EqualGeneralFormLabels(label)) { output = LineBinaryRelation.Unify(goal1, goal2); var ls = output as LineSymbol; if (ls != null) { ls.OutputType = LineType.GeneralForm; TraceInstructionalDesign.FromLineSlopeIntercetpToLineGeneralForm(ls); return(true); } return(false); } if (LineAcronym.EqualSlopeInterceptFormLabels(label)) { output = LineBinaryRelation.Unify(goal1, goal2); var ls = output as LineSymbol; if (ls != null) { ls.OutputType = LineType.SlopeIntercept; return(true); } return(false); } } return(false); }
private static bool ConstraintCheck(PointSymbol pt1, PointSymbol pt2, object constraint, out object output) { output = null; Debug.Assert(constraint != null); var shapeType = constraint as ShapeType?; if (shapeType != null) { #region ShapeType Constraint Solving if (shapeType == ShapeType.Line) { output = LineBinaryRelation.Unify(pt1, pt2); if (output != null) { return(true); } output = LineGenerationRule.IdentityPoints; return(false); } if (shapeType == ShapeType.LineSegment) { output = LineSegBinaryRelation.Unify(pt1, pt2); if (output != null) { return(true); } output = LineSegmentGenerationRule.IdentityPoints; return(false); } return(false); #endregion } var label = constraint as string; if (label != null) { #region Label Constraint Solving if (PointAcronym.MidPoint.Equals(label)) { //Point output = PointBinaryRelation.Unify(pt1, pt2); var ps = output as PointSymbol; if (ps != null) { return(true); } return(false); } #region Line Inference //Case 2 if (LineAcronym.EqualGeneralFormLabels(label)) { output = LineBinaryRelation.Unify(pt1, pt2); var ls = output as LineSymbol; if (ls != null) { ls.OutputType = LineType.GeneralForm; return(true); } return(false); } if (LineAcronym.EqualSlopeLabels(label)) { output = LineBinaryRelation.Unify(pt1, pt2); if (output == null) { return(false); } var lss = output as LineSymbol; //TraceInstructionalDesign.FromPointsToLine(lss); var output1 = lss.Unify(label); output = output1; return(true); } if (LineAcronym.EqualInterceptLabels(label)) { output = LineBinaryRelation.Unify(pt1, pt2); if (output == null) { return(false); } var lss = output as LineSymbol; //TraceInstructionalDesign.FromPointsToLine(lss); var output1 = lss.Unify(label); output = output1; return(true); } if (LineAcronym.EqualSlopeInterceptFormLabels(label)) { output = LineBinaryRelation.Unify(pt1, pt2); var ls = output as LineSymbol; if (ls != null) { ls.OutputType = LineType.SlopeIntercept; return(true); } return(false); } #endregion #region Line Segment Inference if (LineSegmentAcronym.EqualDistanceLabel(label)) { output = LineSegBinaryRelation.Unify(pt1, pt2); if (output == null) { return(false); } var lss = output as LineSegmentSymbol; var output1 = lss.Unify(label); output = output1; #region Embed Line Segment(obsolete) /* * Debug.Assert(lss != null); * if (lss.CachedSymbols.Count == 0) * { * output = output1; * var lst = new List<object>() * { * output, output1 * }; * * output = lst; * } * else * { * var goalLst = output1 as List<EqGoal>; * Debug.Assert(goalLst != null); * var lst = new List<object>(); * for (int i = 0; i < lss.CachedSymbols.Count; i++) * { * var cachedSS = lss.CachedSymbols.ToList()[i]; * lst.Add(cachedSS); * lst.Add(goalLst[i]); * } * output = lst; * }*/ #endregion return(true); } #endregion #region ambiguious inference //Case 1 char[] charr = label.ToCharArray(); if (charr.Length != 2) { return(false); } string str1 = label.ToCharArray()[0].ToString(CultureInfo.InvariantCulture); string str2 = label.ToCharArray()[1].ToString(CultureInfo.InvariantCulture); string label1 = pt1.Shape.Label; string label2 = pt2.Shape.Label; if (label1 == null || label2 == null) { return(false); } bool condition1 = label1.Equals(str1) && label2.Equals(str2); bool condition2 = label1.Equals(str2) && label2.Equals(str1); if (condition1 || condition2) { var supportTypes = new List <ShapeType> { ShapeType.Line, ShapeType.LineSegment }; output = supportTypes; return(false); } #endregion #endregion } var eqGoal = constraint as EqGoal; if (eqGoal != null) { var goalLabel = eqGoal.Lhs.ToString(); #region Line Segment Inference if (LineSegmentAcronym.EqualDistanceLabel(goalLabel)) { output = LineSegBinaryRelation.Unify(pt1, pt2); if (output == null) { return(false); } var lss = output as LineSegmentSymbol; //TraceInstructionalDesign.FromPointsToLineSegment(lss); output = lss.Unify(eqGoal); if (output == null) { return(false); } return(true); } if (LineAcronym.EqualSlopeLabels(goalLabel)) { output = LineBinaryRelation.Unify(pt1, pt2, eqGoal); if (output == null) { return(false); } return(true); } #endregion } return(false); }
public static object Unify(this LineSymbol ls, object constraint) { var refObj = constraint as string; var eqGoal = constraint as EqGoal; if (refObj != null) { #region forward searching if (LineAcronym.EqualSlopeLabels(refObj)) { return(ls.InferSlope(refObj)); } if (LineAcronym.EqualInterceptLabels(refObj)) { return(ls.InferIntercept(refObj)); } if (LineAcronym.EqualGeneralFormLabels(refObj)) { return(ls.InferGeneralForm(refObj)); } if (LineAcronym.EqualSlopeInterceptFormLabels(refObj)) { return(ls.InferSlopeInterceptForm()); } if (LineAcronym.GraphLine.Equals(refObj)) { return(ls.InferGraph()); } #endregion } if (eqGoal != null) { var rhs = eqGoal.Rhs; double dNum; bool isDouble = LogicSharp.IsDouble(rhs, out dNum); if (!isDouble) { return(null); } var lhs = eqGoal.Lhs.ToString(); if (LineAcronym.EqualSlopeLabels(lhs)) { var obj = ls.InferSlope(dNum); var lstObj = obj as List <object>; Debug.Assert(lstObj != null); var eqGoal1 = lstObj[0] as EqGoal; if (eqGoal1 != null) { var newTraces = new List <Tuple <object, object> >(); newTraces.AddRange(eqGoal.Traces); newTraces.AddRange(eqGoal1.Traces); eqGoal1.Traces = newTraces; } return(obj); } } return(null); }