public static LayoutScore Max(LayoutScore a, LayoutScore b) { if (a.CompareTo(b) > 0) { return(a); } else { return(b); } }
public override SpecificLayout GetBestLayout(LayoutQuery query) { if (query.MaxWidth <= 0 || query.MaxHeight <= 0) { double width = 0; double height = 0; if (this.ComputeScore(width, height).CompareTo(query.MinScore) < 0) { return(null); } return(this.MakeLayout(width, height, query)); } LayoutScore score = this.ComputeScore(query.MaxWidth, query.MaxHeight); if (score.CompareTo(query.MinScore) < 0) { return(null); } double ratio = query.MinScore.DividedBy(score); if (query.MinimizesWidth()) { double width = Math.Ceiling(query.MaxWidth * ratio / this.pixelSize) * this.pixelSize; if (this.ComputeScore(width, query.MaxHeight).CompareTo(query.MinScore) < 0) { // the score has some additional components that the division didn't catch, so we have to add another pixel width += this.pixelSize; } if (width > query.MaxWidth) { // We had to round up past the max height, so there is no solution return(null); } return(this.MakeLayout(width, query.MaxHeight, query)); } if (query.MinimizesHeight()) { double height = Math.Ceiling(query.MaxHeight * ratio / this.pixelSize) * this.pixelSize; if (this.ComputeScore(query.MaxWidth, height).CompareTo(query.MinScore) < 0) { // the score has some additional components that the division didn't catch, so we have to add another pixel height += this.pixelSize; } if (height > query.MaxHeight) { // We had to round up past the max height, so there is no solution return(null); } return(this.MakeLayout(query.MaxWidth, height, query)); } return(MakeLayout(query.MaxWidth, query.MaxHeight, query)); }