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.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001-2002 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), (int)(op1.max * mult));
  49. }
  50. public void add(MinOptMax op) {
  51. min += op.min;
  52. opt += op.opt;
  53. max += op.max;
  54. }
  55. public void subtract(MinOptMax op) {
  56. min -= op.max;
  57. opt -= op.opt;
  58. max -= op.min;
  59. }
  60. }