intersect_classify_common.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Begin License:
  2. // Copyright (C) 2006-2014 Tobias Sargeant (tobias.sargeant@gmail.com).
  3. // All rights reserved.
  4. //
  5. // This file is part of the Carve CSG Library (http://carve-csg.com/)
  6. //
  7. // This file may be used under the terms of either the GNU General
  8. // Public License version 2 or 3 (at your option) as published by the
  9. // Free Software Foundation and appearing in the files LICENSE.GPL2
  10. // and LICENSE.GPL3 included in the packaging of this file.
  11. //
  12. // This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
  13. // INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
  14. // A PARTICULAR PURPOSE.
  15. // End:
  16. #pragma once
  17. #include "intersect_common.hpp"
  18. template<typename T>
  19. static int is_same(const std::vector<T> &a,
  20. const std::vector<T> &b) {
  21. if (a.size() != b.size()) return false;
  22. const size_t S = a.size();
  23. size_t i, j, p;
  24. for (p = 0; p < S; ++p) {
  25. if (a[0] == b[p]) break;
  26. }
  27. if (p == S) return 0;
  28. for (i = 1, j = p + 1; j < S; ++i, ++j) if (a[i] != b[j]) goto not_fwd;
  29. for ( j = 0; i < S; ++i, ++j) if (a[i] != b[j]) goto not_fwd;
  30. return +1;
  31. not_fwd:
  32. for (i = 1, j = p - 1; j != (size_t)-1; ++i, --j) if (a[i] != b[j]) goto not_rev;
  33. for ( j = S - 1; i < S; ++i, --j) if (a[i] != b[j]) goto not_rev;
  34. return -1;
  35. not_rev:
  36. return 0;
  37. }