1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package net.sourceforge.jeuclid.test.testsuite;
20  
21  import java.io.Serializable;
22  
23  
24  
25  
26  
27  
28  public class RenderInfo implements Serializable {
29      private static final float FUZZYNESS = 0.1f;
30  
31      
32  
33  
34      private static final long serialVersionUID = 1L;
35  
36      private final String elementName;
37  
38      private final float ascent;
39  
40      private final float descent;
41  
42      private final float width;
43  
44      private final float posx;
45  
46      private final float posy;
47  
48      
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64      public RenderInfo(final String element, final float asc, final float desc,
65              final float wid, final float x, final float y) {
66          super();
67          if (element == null) {
68              this.elementName = "";
69          } else {
70              this.elementName = element;
71          }
72          this.ascent = asc;
73          this.descent = desc;
74          this.width = wid;
75          this.posx = x;
76          this.posy = y;
77      }
78  
79      
80  
81  
82  
83  
84  
85  
86  
87      public String checkSimilar(final RenderInfo other) {
88          final StringBuilder b = new StringBuilder();
89          if (!this.elementName.equals(other.elementName)) {
90              b.append(" name was: " + other.elementName);
91          }
92          if (!this.isClose(this.ascent, other.ascent)) {
93              b.append(" ascent " + this.ascent + " vs. " + other.ascent);
94          }
95          if (!this.isClose(this.descent, other.descent)) {
96              b.append(" descent " + this.descent + " vs. " + other.descent);
97          }
98          if (!this.isClose(this.width, other.width)) {
99              b.append(" width " + this.width + " vs. " + other.width);
100         }
101         if (!this.isClose(this.posx, other.posx)) {
102             b.append(" posx " + this.posx + " vs. " + other.posx);
103         }
104         if (!this.isClose(this.posy, other.posy)) {
105             b.append(" posy " + this.posy + " vs. " + other.posy);
106         }
107         return b.toString();
108     }
109 
110     private boolean isClose(final float should, final float is) {
111         final float maxdelta = Math.max(
112                 Math.abs(should * RenderInfo.FUZZYNESS), 0.1f);
113         return Math.abs(should - is) <= maxdelta;
114     }
115 
116     
117 
118 
119     public String getElementName() {
120         return this.elementName;
121     }
122 
123 }