1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.png;
18
19
20
21
22 public final class PhysicalScale {
23 private static final int METER_UNITS = 1;
24 private static final int RADIAN_UNITS = 2;
25 public static final PhysicalScale UNDEFINED = createFromMeters(-1.0, -1.0);
26
27 public static PhysicalScale createFromMeters(final double x, final double y) {
28 return new PhysicalScale(METER_UNITS, x, y);
29 }
30
31 public static PhysicalScale createFromRadians(final double x, final double y) {
32 return new PhysicalScale(RADIAN_UNITS, x, y);
33 }
34
35 private final int units;
36
37 private final double horizontalUnitsPerPixel;
38
39 private final double verticalUnitsPerPixel;
40
41 private PhysicalScale(final int units, final double horizontalUnitsPerPixel, final double verticalUnitsPerPixel) {
42 this.units = units;
43 this.horizontalUnitsPerPixel = horizontalUnitsPerPixel;
44 this.verticalUnitsPerPixel = verticalUnitsPerPixel;
45 }
46
47 public double getHorizontalUnitsPerPixel() {
48 return horizontalUnitsPerPixel;
49 }
50
51 public double getVerticalUnitsPerPixel() {
52 return verticalUnitsPerPixel;
53 }
54
55 public boolean isInMeters() {
56 return METER_UNITS == units;
57 }
58
59 public boolean isInRadians() {
60 return RADIAN_UNITS == units;
61 }
62 }