Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r7164 r7165 209 209 210 210 /** 211 * Returns the minimum of the given numbers, or NaN if no number is given. 212 * @see Math#min(float, float) 213 */ 214 public static float min(float... args) { 215 if (args.length == 0) { 216 return Float.NaN; 217 } else if (args.length == 1) { 218 return args[0]; 219 } else { 220 float min = Math.min(args[0], args[1]); 221 for (int i = 2; i < args.length; i++) { 222 min = Math.min(min, args[i]); 223 } 224 return min; 225 } 226 } 227 228 /** 229 * Returns the maximum of the given numbers, or NaN if no number is given. 230 * @see Math#max(float, float) 231 */ 232 public static float max(float... args) { 233 if (args.length == 0) { 234 return Float.NaN; 235 } else if (args.length == 1) { 236 return args[0]; 237 } else { 238 float max = Math.max(args[0], args[1]); 239 for (int i = 2; i < args.length; i++) { 240 max = Math.max(max, args[i]); 241 } 242 return max; 243 } 244 } 245 246 /** 211 247 * Splits string {@code toSplit} at occurrences of the separator string {@code sep} and returns a list of matches. 212 248 * @see String#split(String) -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy
r7124 r7165 318 318 assert css.getErrors().iterator().next().toString().contains("Unknown MapCSS base selector invalid_base") 319 319 } 320 321 @Test 322 public void testMinMaxFunctions() throws Exception { 323 def sheet = new MapCSSStyleSource("* {" + 324 "min_value: min(tag(x), tag(y), tag(z)); " + 325 "max_value: max(tag(x), tag(y), tag(z)); " + 326 "}") 327 sheet.loadStyleSource() 328 def mc = new MultiCascade() 329 330 sheet.apply(mc, TestUtils.createPrimitive("way x=4 y=6 z=8 u=100"), 20, null, false) 331 assert mc.getCascade(Environment.DEFAULT_LAYER).get("min_value", Float.NaN, Float.class) == 4.0f 332 assert mc.getCascade(Environment.DEFAULT_LAYER).get("max_value", Float.NaN, Float.class) == 8.0f 333 334 sheet.apply(mc, TestUtils.createPrimitive("way x=4 y=6"), 20, null, false) 335 assert mc.getCascade(Environment.DEFAULT_LAYER).get("min_value", -777f, Float.class) == -777f 336 assert mc.getCascade(Environment.DEFAULT_LAYER).get("max_value", -777f, Float.class) == -777f 337 } 320 338 }
Note:
See TracChangeset
for help on using the changeset viewer.