public static object Unify(PointSymbol pt1, PointSymbol pt2, EqGoal goal = null)
        {
            //point identify check
            if (pt1.Equals(pt2)) return null;

            //Mid-point 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 midPoint = PointGenerationRule.GenerateMidPoint(point1, point2);
                TraceInstructionalDesign.FromPointsToMidPoint(pt1, pt2, midPoint);
                return midPoint;
            }
            return null;
        }
Exemple #2
0
        public static object Unify(PointSymbol pt1, PointSymbol pt2, EqGoal goal = null)
        {
            //point identify check
            if (pt1.Equals(pt2))
            {
                return(null);
            }

            //Mid-point 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 midPoint = PointGenerationRule.GenerateMidPoint(point1, point2);
                TraceInstructionalDesign.FromPointsToMidPoint(pt1, pt2, midPoint);
                return(midPoint);
            }
            return(null);
        }
Exemple #3
0
        /// <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;
            }
        }
        public static LineSegmentSymbol Unify(PointSymbol pt1, PointSymbol pt2)
        {
            //point identify check
            if (pt1.Equals(pt2))
            {
                return(null);
            }
            var point1 = pt1.Shape as Point;
            var point2 = pt2.Shape as Point;

            Debug.Assert(point1 != null);
            Debug.Assert(point2 != null);

            //lazy evaluation
            //Constraint solving on Graph
            var lineSeg = new LineSegment(null); //Ghost Line Segment

            lineSeg.Pt1 = point1;
            lineSeg.Pt2 = point2;
            var lss = new LineSegmentSymbol(lineSeg);

            //Line build process
            if (pt1.Shape.Concrete)
            {
                if (pt2.Shape.Concrete)
                {
                    return(LineSegmentGenerationRule.GenerateLineSegment(point1, point2));
                }

                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 gLss = LineSegmentGenerationRule.GenerateLineSegment(point1, cachePoint);
                        gLss.Traces.AddRange(ps.Traces);
                        lss.CachedSymbols.Add(gLss);
                    }
                }
                return(lss);
            }
            Debug.Assert(!pt1.Shape.Concrete);
            if (pt2.Shape.Concrete)
            {
                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 gLss = LineSegmentGenerationRule.GenerateLineSegment(cachePoint, point2);
                        gLss.Traces.AddRange(ps.Traces);
                        lss.CachedSymbols.Add(gLss);
                    }
                }
                return(lss);
            }
            Debug.Assert(!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 gLss = LineSegmentGenerationRule.GenerateLineSegment(cachePoint1, cachePoint2);
                    gLss.Traces.AddRange(ps1.Traces);
                    gLss.Traces.AddRange(ps2.Traces);
                    lss.CachedSymbols.Add(gLss);
                }
            }
            return(lss);
        }