SkIPoint16.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2018 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkIPoint16_DEFINED
  8. #define SkIPoint16_DEFINED
  9. #include "include/core/SkTypes.h"
  10. #include "include/private/SkTo.h"
  11. /** \struct SkIPoint16
  12. SkIPoint16 holds two 16 bit integer coordinates.
  13. */
  14. struct SkIPoint16 {
  15. int16_t fX; //!< x-axis value used by SkIPoint16
  16. int16_t fY; //!< y-axis value used by SkIPoint16
  17. /** Sets fX to x, fY to y. If SK_DEBUG is defined, asserts
  18. if x or y does not fit in 16 bits.
  19. @param x integer x-axis value of constructed SkIPoint
  20. @param y integer y-axis value of constructed SkIPoint
  21. @return SkIPoint16 (x, y)
  22. */
  23. static constexpr SkIPoint16 Make(int x, int y) {
  24. return {SkToS16(x), SkToS16(y)};
  25. }
  26. /** Returns x-axis value of SkIPoint16.
  27. @return fX
  28. */
  29. int16_t x() const { return fX; }
  30. /** Returns y-axis value of SkIPoint.
  31. @return fY
  32. */
  33. int16_t y() const { return fY; }
  34. /** Sets fX to x and fY to y.
  35. @param x new value for fX
  36. @param y new value for fY
  37. */
  38. void set(int x, int y) {
  39. fX = SkToS16(x);
  40. fY = SkToS16(y);
  41. }
  42. };
  43. #endif