Example #1
0
        public LeafLayout(View view, LayoutDimensions desiredDimensions)
        {
            this.view = view;
            List <LayoutDimensions> dimensionOptions = new List <LayoutDimensions>();

            dimensionOptions.Add(desiredDimensions);
            dimensionOptions.Add(new LayoutDimensions(0, 0, LayoutScore.Get_CutOff_LayoutScore(1)));
            this.dimensionOptions = dimensionOptions;
        }
Example #2
0
        public LayoutDimensions Clone()
        {
            LayoutDimensions clone = new LayoutDimensions();

            clone.Width  = this.Width;
            clone.Height = this.Height;
            clone.Score  = this.Score;
            return(clone);
        }
        public override LayoutQuery OptimizedPastDimensions(LayoutDimensions example)
        {
            MinWidth_LayoutQuery result = this;
            double newWidth             = example.Width * 0.9999999999;

            if (this.MaxWidth > newWidth)
            {
                result = this.Clone((MinWidth_LayoutQuery)null);
                result.setMaxWidth(newWidth);
                if (!result.Accepts(result.ProposedSolution_ForDebugging))
                {
                    result.ProposedSolution_ForDebugging = null;
                }
            }
            return(result);
        }
        public override LayoutQuery OptimizedPastDimensions(LayoutDimensions example)
        {
            MinHeight_LayoutQuery result = this;
            double newHeight             = example.Height * 0.9999999999;

            if (this.MaxHeight > newHeight)
            {
                result = this.Clone((MinHeight_LayoutQuery)null);
                result.setMaxHeight(newHeight);
                if (!result.Accepts(result.ProposedSolution_ForDebugging))
                {
                    result.ProposedSolution_ForDebugging = null;
                }
            }
            return(result);
        }
        public override LayoutQuery OptimizedPastDimensions(LayoutDimensions example)
        {
            MaxScore_LayoutQuery result   = this;
            LayoutScore          minScore = example.Score.Plus(LayoutScore.Tiny);

            if (this.MinScore.CompareTo(minScore) < 0)
            {
                result = this.Clone((MaxScore_LayoutQuery)null);
                result.setMinScore(minScore);
                if (!result.Accepts(result.ProposedSolution_ForDebugging))
                {
                    result.ProposedSolution_ForDebugging = null;
                }
            }
            return(result);
        }
Example #6
0
        public override SpecificLayout GetBestLayout(LayoutQuery layoutQuery)
        {
            IEnumerable <LayoutDimensions> options = this.getLayoutOptions(layoutQuery);

            LayoutDimensions dimensions = null;

            foreach (LayoutDimensions candidate in options)
            {
                dimensions = layoutQuery.PreferredLayout(candidate, dimensions);
            }

            Specific_LeafLayout result = null;

            if (dimensions != null)
            {
                result = new Specific_LeafLayout(this.view, dimensions);
            }
            return(result);
        }
 public override LayoutDimensions PreferredLayout(LayoutDimensions choice1, LayoutDimensions choice2)
 {
     if (!this.Accepts(choice1))
     {
         if (this.Accepts(choice2))
         {
             return(choice2);
         }
         return(null);
     }
     if (!this.Accepts(choice2))
     {
         return(choice1);
     }
     if (choice1.Width <= choice2.Width)
     {
         return(choice1);
     }
     return(choice2);
 }
Example #8
0
 public bool Accepts(LayoutDimensions dimensions)
 {
     if (dimensions == null)
     {
         return(false);
     }
     if (dimensions.Width > this.MaxWidth)
     {
         return(false);
     }
     if (dimensions.Height > this.MaxHeight)
     {
         return(false);
     }
     if (dimensions.Score.CompareTo(this.MinScore) < 0)
     {
         return(false);
     }
     return(true);
 }
 public override LayoutDimensions PreferredLayout(LayoutDimensions choice1, LayoutDimensions choice2)
 {
     if (!this.Accepts(choice1))
     {
         if (this.Accepts(choice2))
         {
             return(choice2);
         }
         return(null);
     }
     if (!this.Accepts(choice2))
     {
         return(choice1);
     }
     if (choice1.Score.CompareTo(choice2.Score) >= 0)
     {
         return(choice1);
     }
     return(choice2);
 }
Example #10
0
        // returns whichever layout it likes better
        public SpecificLayout PreferredLayout(SpecificLayout tieWinner, SpecificLayout tieLoser)
        {
            if (!this.Accepts(tieWinner))
            {
                if (this.Accepts(tieLoser))
                {
                    return(tieLoser);
                }
                else
                {
                    return(null);
                }
            }
            if (!this.Accepts(tieLoser))
            {
                return(tieWinner);
            }
            LayoutDimensions dimensions1 = new LayoutDimensions();

            dimensions1.Width  = tieWinner.Width;
            dimensions1.Height = tieWinner.Height;
            dimensions1.Score  = tieWinner.Score;
            LayoutDimensions dimensions2 = new LayoutDimensions();

            dimensions2.Width  = tieLoser.Width;
            dimensions2.Height = tieLoser.Height;
            dimensions2.Score  = tieLoser.Score;
            // TODO: when asking a MaxScore_LayoutQuery which layout it likes better, consider calling isScoreAtLeast instead of computing all the scores
            if (this.PreferredLayout(dimensions1, dimensions2) == dimensions1)
            {
                return(tieWinner);
            }
            else
            {
                return(tieLoser);
            }
        }
Example #11
0
        // tests that the layout satisfies all of the queries consistently
        public void DebugCheck(LayoutChoice_Set layout)
        {
            int i, j;
            int maxWidth, maxHeight;

            maxWidth  = 127;
            maxHeight = 127;
            LayoutDimensions[,] maxScore_dimensions  = new LayoutDimensions[maxWidth, maxHeight];
            LayoutDimensions[,] minWidth_dimensions  = new LayoutDimensions[maxWidth, maxHeight];
            LayoutDimensions[,] minHeight_dimensions = new LayoutDimensions[maxWidth, maxHeight];
            for (i = 0; i < maxWidth; i++)
            {
                System.Diagnostics.Debug.WriteLine(i.ToString() + " of " + maxWidth.ToString());
                for (j = 0; j < maxHeight; j++)
                {
                    int width  = i + 29;
                    int height = j;

                    // find the maximum score of all layouts that fit in these dimensions
                    LayoutQuery    maxScoreQuery   = new MaxScore_LayoutQuery(width, height, LayoutScore.Minimum, this.visualDefaults.LayoutDefaults);
                    SpecificLayout maxScore_layout = layout.GetBestLayout(maxScoreQuery);
                    maxScore_dimensions[i, j] = maxScore_layout.Dimensions;


                    // find the layout of minimum width having at least this score
                    LayoutQuery    minWidthQuery   = new MinWidth_LayoutQuery(width, height, maxScore_layout.Score, this.visualDefaults.LayoutDefaults);
                    SpecificLayout minWidth_layout = layout.GetBestLayout(minWidthQuery);
                    if (minWidth_layout != null)
                    {
                        minWidth_dimensions[i, j] = minWidth_layout.Dimensions;
                    }

                    // find the layout of minimum height having at least this score
                    LayoutQuery    minHeightQuery   = new MinHeight_LayoutQuery(width, height, maxScore_layout.Score, this.visualDefaults.LayoutDefaults);
                    SpecificLayout minHeight_layout = layout.GetBestLayout(minHeightQuery);
                    if (minHeight_layout != null)
                    {
                        minHeight_dimensions[i, j] = minHeight_layout.Dimensions;
                    }
                    if (i > 0)
                    {
                        if (maxScore_dimensions[i, j].Score.CompareTo(maxScore_dimensions[i - 1, j].Score) < 0)
                        {
                            System.Diagnostics.Debug.WriteLine("Error: inconsistency between (" + i.ToString() + ", " + j.ToString() + ") and (" + (i - 1).ToString() + ", " + j.ToString() + ")");
                        }
                    }
                    if (j > 0)
                    {
                        if (maxScore_dimensions[i, j].Score.CompareTo(maxScore_dimensions[i, j - 1].Score) < 0)
                        {
                            System.Diagnostics.Debug.WriteLine("Error: inconsistency between (" + i.ToString() + ", " + j.ToString() + ") and (" + i.ToString() + ", " + (j - 1).ToString() + ")");
                        }
                    }
                    if ((width == 0 || height == 0) && maxScore_dimensions[i, j].Score.CompareTo(LayoutScore.Zero) > 0)
                    {
                        System.Diagnostics.Debug.WriteLine("Error: clipping not noticed at (" + i.ToString() + ", " + j.ToString() + ")");
                    }
                    if (minWidth_dimensions[i, j] == null)
                    {
                        System.Diagnostics.Debug.WriteLine("Error: minWidth query for (" + i.ToString() + ", " + j.ToString() + ") returned null");
                        minWidthQuery.Debug = true;
                        layout.GetBestLayout(minWidthQuery.Clone());
                    }
                    if (minHeight_dimensions[i, j] == null)
                    {
                        System.Diagnostics.Debug.WriteLine("Error: minHeight query for (" + i.ToString() + ", " + j.ToString() + ") returned null");
                    }
                    if (i > 0 && minWidth_dimensions[i, j] != null && minWidth_dimensions[i, j] != null)
                    {
                        if (minWidth_dimensions[i, j].Score.CompareTo(minWidth_dimensions[i - 1, j].Score) == 0)
                        {
                            if (minWidth_dimensions[i, j].Width != minWidth_dimensions[i - 1, j].Width)
                            {
                                System.Diagnostics.Debug.WriteLine("Error: width is wrong in minWidth query between (" + i.ToString() + ", " + j.ToString() + ") and (" + (i - 1).ToString() + ", " + j.ToString() + ")");
                            }
                        }
                    }
                    if (j > 0 && minHeight_dimensions[i, j] != null && minHeight_dimensions[i, j] != null)
                    {
                        if (minHeight_dimensions[i, j].Score.CompareTo(minHeight_dimensions[i, j - 1].Score) == 0)
                        {
                            if (minHeight_dimensions[i, j].Height != minHeight_dimensions[i, j - 1].Height)
                            {
                                System.Diagnostics.Debug.WriteLine("Error: height is wrong in minHeight query between (" + i.ToString() + ", " + j.ToString() + ") and (" + i.ToString() + ", " + (j - 1).ToString() + ")");
                                minHeightQuery.Debug = true;
                                layout.GetBestLayout(minHeightQuery.Clone());
                            }
                        }
                    }
                }
            }
            System.Diagnostics.Debug.WriteLine("done with debugCheck");

            /*
             * System.Diagnostics.Debug.WriteLine("checking minWidth queries");
             * for (i = 1; i < maxWidth; i++)
             * {
             *  for (j = 1; j < maxHeight; j++)
             *  {
             *      if (maxScore_dimensions[i, j].Score.CompareTo(maxScore_dimensions[i - 1, j] < 0))
             *          System.Diagnostics.Debug.WriteLine("Error: inconsistency between (" + i.ToString() + ", " + j.ToString() + ") and (" + (i - 1).ToString() + ", " + j.ToString());
             *      if (maxScore_dimensions[i, j].Score.CompareTo(maxScore_dimensions[i, j - 1] < 0))
             *          System.Diagnostics.Debug.WriteLine("Error: inconsistency between (" + i.ToString() + ", " + j.ToString() + ") and (" + i.ToString() + ", " + (j - 1).ToString());
             *  }
             * }*/
        }
Example #12
0
 public Specific_LeafLayout(View view, LayoutDimensions dimensions)
 {
     this.view       = view;
     this.dimensions = dimensions;
 }
Example #13
0
 protected virtual void CopyFrom(LayoutDimensions original)
 {
     this.Width  = original.Width;
     this.Height = original.Height;
     this.Score  = original.Score;
 }
Example #14
0
 public LayoutDimensions(LayoutDimensions original)
 {
     this.CopyFrom(original);
 }
Example #15
0
 // returns whichever layout it likes better
 public abstract LayoutDimensions PreferredLayout(LayoutDimensions tieWinner, LayoutDimensions tieLoser);
Example #16
0
 // returns a stricter query that won't even be satisfied by this example
 public abstract LayoutQuery OptimizedPastDimensions(LayoutDimensions dimensions);