Dimension.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2009 ZXing authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import IllegalArgumentException from './IllegalArgumentException';
  17. /*namespace com.google.zxing {*/
  18. /**
  19. * Simply encapsulates a width and height.
  20. */
  21. export default class Dimension {
  22. constructor(width /*int*/, height /*int*/) {
  23. this.width = width;
  24. this.height = height;
  25. if (width < 0 || height < 0) {
  26. throw new IllegalArgumentException();
  27. }
  28. }
  29. getWidth() {
  30. return this.width;
  31. }
  32. getHeight() {
  33. return this.height;
  34. }
  35. /*@Override*/
  36. equals(other) {
  37. if (other instanceof Dimension) {
  38. const d = other;
  39. return this.width === d.width && this.height === d.height;
  40. }
  41. return false;
  42. }
  43. /*@Override*/
  44. hashCode() {
  45. return this.width * 32713 + this.height;
  46. }
  47. /*@Override*/
  48. toString() {
  49. return this.width + 'x' + this.height;
  50. }
  51. }