You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MinOptMax.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.area;
  8. /**
  9. * This class holds the resolved (as mpoints) form of a LengthRange or
  10. * Space type Property value.
  11. * MinOptMax values are used during layout calculations. The instance
  12. * variables are package visible.
  13. */
  14. public class MinOptMax implements java.io.Serializable, Cloneable {
  15. /** Publicly visible min(imum), opt(imum) and max(imum) values.*/
  16. public int min;
  17. public int opt;
  18. public int max;
  19. public MinOptMax() {
  20. this(0);
  21. }
  22. public MinOptMax(int val) {
  23. this(val, val, val);
  24. }
  25. public MinOptMax(int min, int opt, int max) {
  26. this.min = min;
  27. this.opt = opt;
  28. this.max = max;
  29. }
  30. public Object clone() {
  31. try {
  32. return super.clone();
  33. } catch (CloneNotSupportedException ex) {
  34. // SHOULD NEVER OCCUR - all members are primitive types!
  35. return null;
  36. }
  37. }
  38. public static MinOptMax subtract(MinOptMax op1, MinOptMax op2) {
  39. return new MinOptMax(op1.min - op2.max, op1.opt - op2.opt,
  40. op1.max - op2.min);
  41. }
  42. public static MinOptMax add(MinOptMax op1, MinOptMax op2) {
  43. return new MinOptMax(op1.min + op2.min, op1.opt + op2.opt,
  44. op1.max + op2.max);
  45. }
  46. public static MinOptMax multiply(MinOptMax op1, double mult) {
  47. return new MinOptMax((int)(op1.min * mult),
  48. (int)(op1.opt * mult),
  49. (int)(op1.max * mult));
  50. }
  51. public void add(MinOptMax op) {
  52. min += op.min;
  53. opt += op.opt;
  54. max += op.max;
  55. }
  56. public void subtract(MinOptMax op) {
  57. min -= op.max;
  58. opt -= op.opt;
  59. max -= op.min;
  60. }
  61. }