Esempio n. 1
0
        //
        // Append subtraction to this current problem.
        //
        public static FigSynthProblem AppendAddition(FigSynthProblem that, FigSynthProblem toAppend)
        {
            BinarySynthOperation binaryAppend = toAppend as BinarySynthOperation;

            if (binaryAppend == null)
            {
                return(null);
            }

            if (that is AdditionSynth)
            {
                // Verify that the external form of that matches with the LHS of toAppend.
                Polygon testPoly = Polygon.MakePolygon(that.GetExteriorSegments());
                if (!testPoly.StructurallyEquals((binaryAppend.leftProblem as UnarySynth).figure))
                {
                    throw new ArgumentException("Exterior polygons do not match: " + (binaryAppend.leftProblem as UnarySynth).figure);
                }
            }
            // Create the new synth object
            AdditionSynth newSum = new AdditionSynth(that.Copy(), (binaryAppend.rightProblem as UnarySynth).figure);

            // The open regions that may be modified consist of a union of regions.
            List <AtomicRegion> newOpenRegions = new List <AtomicRegion>(that.openRegions);

            newOpenRegions.AddRange(toAppend.openRegions);

            newSum.SetOpenRegions(newOpenRegions);

            return(newSum);
        }
Esempio n. 2
0
        //
        // Append subtraction to this current problem; the subtraction occurs within the inner figure (shape).
        //
        public static FigSynthProblem AppendFigureSubtraction(FigSynthProblem that, FigSynthProblem toAppend)
        {
            BinarySynthOperation binaryAppend = toAppend as BinarySynthOperation;

            if (binaryAppend == null)
            {
                return(null);
            }

            if (that is SubtractionSynth)
            {
                // Verify that the outer part of toAppend is a figure in this problem.
                Figure          theShape         = (binaryAppend.leftProblem as UnarySynth).figure;
                FigSynthProblem leftShapeProblem = that.GetSynthByShape(theShape);

                if (leftShapeProblem == null)
                {
                    throw new ArgumentException("Shape is not in the given problem: " + theShape);
                }

                //
                // Create the new subtraction node and insert it into the copy.
                //
                // Since the 'left' expression was a shape, the 'right' is the actual shape we are appending.
                SubtractionSynth newSub = new SubtractionSynth(leftShapeProblem, binaryAppend.rightProblem);

                return(that.Copy().ReplaceUnary(theShape, newSub));
            }
            else if (that is AdditionSynth)
            {
                // Verify that the external form of that matches with the LHS of toAppend.
                Polygon outerPoly = Polygon.MakePolygon(that.GetExteriorSegments());
                if (!outerPoly.StructurallyEquals((binaryAppend.leftProblem as UnarySynth).figure))
                {
                    throw new ArgumentException("Exterior polygons do not match: " + (binaryAppend.leftProblem as UnarySynth).figure);
                }

                // Make a copy of that.
                return(new SubtractionSynth(that.Copy(), (binaryAppend.rightProblem as UnarySynth).figure));
            }
            else
            {
                throw new ArgumentException("Expected Addition or Subtraction; acquired neither.");
            }
        }
Esempio n. 3
0
        //
        // Append subtraction to this current problem; the subtraction occurs within one of the open atomic regions.
        //
        public static FigSynthProblem AppendAtomicSubtraction(FigSynthProblem that, FigSynthProblem toAppend)
        {
            BinarySynthOperation binaryAppend = toAppend as BinarySynthOperation;

            if (binaryAppend == null)
            {
                return(null);
            }

            // Verify that the outer part of toAppend is an open atomic region.
            if (!that.openRegions.Contains(new ShapeAtomicRegion((binaryAppend.leftProblem as UnarySynth).figure)))
            {
                throw new ArgumentException("Shape is not an open atomic region: " + (binaryAppend.leftProblem as UnarySynth).figure);
            }

            // Since the 'left' expression was an open region, the 'right' is the actual shape we are appending.
            SubtractionSynth newSub = new SubtractionSynth(that.Copy(), binaryAppend.rightProblem);

            // Update the open regions to the inner-most shape.
            newSub.SetOpenRegions(toAppend.openRegions);

            return(newSub);
        }
Esempio n. 4
0
        //
        // A symmetric scenario is one in which:
        //  1) The inner shapes are congruent
        //  2) The remaining atomic regions match 1-1.
        //
        public override bool IsSymmetricTo(FigSynthProblem that)
        {
            BinarySynthOperation binarySynth = that as BinarySynthOperation;

            if (binarySynth == null)
            {
                return(false);
            }

            // The outer shapes must be congruent.
            if (!this.leftProblem.IsSymmetricTo(binarySynth.leftProblem))
            {
                return(false);
            }

            // The outer shapes must be congruent.
            if (!this.rightProblem.IsSymmetricTo(binarySynth.rightProblem))
            {
                return(false);
            }

            // The atomic regions have to match 1-1 and onto.
            return(base.IsSymmetricTo(that));
        }