private static bool ConstraintCheck(PointSymbol pt1, PointSymbol pt2,
                                            string constraint1, ShapeType constraint2, out object output)
        {
            output = null;
            Debug.Assert(constraint1 != null);

            var label = constraint1 as string;

            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)
            {
                if (constraint2 == ShapeType.LineSegment)
                {
                    if (constraint1 == LineSegmentAcronym.GeneralForm)
                    {
                        output = LineSegBinaryRelation.Unify(pt1, pt2);
                        if (output != null)
                        {
                            return(true);
                        }
                        output = LineSegmentGenerationRule.IdentityPoints;
                        return(false);
                    }
                    if (constraint1 == LineAcronym.GeneralForm1)
                    {
                        output = LineBinaryRelation.Unify(pt1, pt2);
                        if (output != null)
                        {
                            return(true);
                        }
                        output = LineGenerationRule.IdentityPoints;
                        return(false);
                    }
                }
            }

            bool condition1 = label1.Equals(str1) && label2.Equals(str2);
            bool condition2 = label1.Equals(str2) && label2.Equals(str1);

            if (condition1 || condition2)
            {
                if (constraint2 == ShapeType.Line)
                {
                    output = LineBinaryRelation.Unify(pt1, pt2);
                    if (output != null)
                    {
                        return(true);
                    }
                    output = LineGenerationRule.IdentityPoints;
                    return(false);
                }

                if (constraint2 == ShapeType.LineSegment)
                {
                    output = LineSegBinaryRelation.Unify(pt1, pt2);
                    if (output != null)
                    {
                        return(true);
                    }
                    output = LineSegmentGenerationRule.IdentityPoints;
                    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);
        }