util_math_int2.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright 2011-2017 Blender Foundation
  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. #ifndef __UTIL_MATH_INT2_H__
  17. #define __UTIL_MATH_INT2_H__
  18. #ifndef __UTIL_MATH_H__
  19. # error "Do not include this file directly, include util_types.h instead."
  20. #endif
  21. CCL_NAMESPACE_BEGIN
  22. /*******************************************************************************
  23. * Declaration.
  24. */
  25. #ifndef __KERNEL_OPENCL__
  26. ccl_device_inline bool operator==(const int2 a, const int2 b);
  27. ccl_device_inline int2 operator+(const int2 &a, const int2 &b);
  28. ccl_device_inline int2 operator+=(int2 &a, const int2 &b);
  29. ccl_device_inline int2 operator-(const int2 &a, const int2 &b);
  30. ccl_device_inline int2 operator*(const int2 &a, const int2 &b);
  31. ccl_device_inline int2 operator/(const int2 &a, const int2 &b);
  32. #endif /* !__KERNEL_OPENCL__ */
  33. /*******************************************************************************
  34. * Definition.
  35. */
  36. #ifndef __KERNEL_OPENCL__
  37. ccl_device_inline bool operator==(const int2 a, const int2 b)
  38. {
  39. return (a.x == b.x && a.y == b.y);
  40. }
  41. ccl_device_inline int2 operator+(const int2 &a, const int2 &b)
  42. {
  43. return make_int2(a.x + b.x, a.y + b.y);
  44. }
  45. ccl_device_inline int2 operator+=(int2 &a, const int2 &b)
  46. {
  47. return a = a + b;
  48. }
  49. ccl_device_inline int2 operator-(const int2 &a, const int2 &b)
  50. {
  51. return make_int2(a.x - b.x, a.y - b.y);
  52. }
  53. ccl_device_inline int2 operator*(const int2 &a, const int2 &b)
  54. {
  55. return make_int2(a.x * b.x, a.y * b.y);
  56. }
  57. ccl_device_inline int2 operator/(const int2 &a, const int2 &b)
  58. {
  59. return make_int2(a.x / b.x, a.y / b.y);
  60. }
  61. #endif /* !__KERNEL_OPENCL__ */
  62. CCL_NAMESPACE_END
  63. #endif /* __UTIL_MATH_INT2_H__ */