// Copyright (c) 2019 // GeometryFactory (France) // // This file is part of CGAL (www.cgal.org); you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 3 of the License, // or (at your option) any later version. // // Licensees holding a valid commercial license may use this file in // accordance with the commercial license agreement provided with the software. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // // $URL$ // $Id$ // SPDX-License-Identifier: LGPL-3.0+ // // // Author(s) : Simon Giraudot #ifndef CGAL_KERNEL_HASH_FUNCTIONS_H #define CGAL_KERNEL_HASH_FUNCTIONS_H #include #include namespace CGAL { using boost::hash_value; template inline std::enable_if_t::value, std::size_t> hash_value (const Aff_transformation_2& transform) { std::size_t result = hash_value(transform.cartesian(0,0)); for(int i=0; i < 3; ++i) for(int j = 0; j < 3; ++j) if (!(i == 0 && j == 0)) boost::hash_combine(result, hash_value(transform.cartesian(i,j))); return result; } inline std::size_t hash_value (const Bbox_2& bbox) { std::size_t result = hash_value(bbox.xmin()); boost::hash_combine(result, hash_value(bbox.xmax())); boost::hash_combine(result, hash_value(bbox.ymin())); boost::hash_combine(result, hash_value(bbox.ymax())); return result; } template inline std::enable_if_t::value, std::size_t> hash_value (const Circle_2& circle) { std::size_t result = hash_value(circle.center()); boost::hash_combine(result, hash_value(circle.squared_radius())); boost::hash_combine(result, hash_value(circle.orientation())); return result; } template inline std::enable_if_t::value, std::size_t> hash_value (const Iso_rectangle_2& iso_rectangle) { std::size_t result = hash_value(iso_rectangle.min()); boost::hash_combine(result, hash_value(iso_rectangle.max())); return result; } template inline std::enable_if_t::value, std::size_t> hash_value (const Point_2& point) { std::size_t result = hash_value(point.x()); boost::hash_combine(result, hash_value(point.y())); return result; } template inline std::enable_if_t::value, std::size_t> hash_value (const Segment_2& segment) { std::size_t result = hash_value(segment.source()); boost::hash_combine(result, hash_value(segment.target())); return result; } template inline std::enable_if_t::value, std::size_t> hash_value (const Vector_2& vector) { std::size_t result = hash_value(vector.x()); boost::hash_combine(result, hash_value(vector.y())); return result; } template inline std::enable_if_t::value, std::size_t> hash_value (const Weighted_point_2& weighed_point) { std::size_t result = hash_value(weighed_point.point()); boost::hash_combine(result, hash_value(weighed_point.weight())); return result; } template inline std::enable_if_t::value, std::size_t> hash_value (const Aff_transformation_3& transform) { std::size_t result = hash_value(transform.cartesian(0,0)); for(int i = 0; i < 3; ++i) for(int j = 0; j < 4; ++j) if (!(i == 0 && j == 0)) boost::hash_combine(result, hash_value(transform.cartesian(i,j))); return result; } inline std::size_t hash_value (const Bbox_3& bbox) { std::size_t result = hash_value(bbox.xmin()); boost::hash_combine(result, hash_value(bbox.xmax())); boost::hash_combine(result, hash_value(bbox.ymin())); boost::hash_combine(result, hash_value(bbox.ymax())); boost::hash_combine(result, hash_value(bbox.zmin())); boost::hash_combine(result, hash_value(bbox.zmax())); return result; } template inline std::enable_if_t::value, std::size_t> hash_value (const Iso_cuboid_3& iso_cuboid) { std::size_t result = hash_value(iso_cuboid.min()); boost::hash_combine(result, hash_value(iso_cuboid.max())); return result; } template inline std::enable_if_t::value, std::size_t> hash_value (const Point_3& point) { std::size_t result = hash_value(point.x()); boost::hash_combine(result, hash_value(point.y())); boost::hash_combine(result, hash_value(point.z())); return result; } template inline std::enable_if_t::value, std::size_t> hash_value (const Segment_3& segment) { std::size_t result = hash_value(segment.source()); boost::hash_combine(result, hash_value(segment.target())); return result; } template inline std::enable_if_t::value, std::size_t> hash_value (const Sphere_3& sphere) { std::size_t result = hash_value(sphere.center()); boost::hash_combine(result, hash_value(sphere.squared_radius())); boost::hash_combine(result, hash_value(sphere.orientation())); return result; } template inline std::enable_if_t::value, std::size_t> hash_value (const Vector_3& vector) { std::size_t result = hash_value(vector.x()); boost::hash_combine(result, hash_value(vector.y())); boost::hash_combine(result, hash_value(vector.z())); return result; } template inline std::enable_if_t::value, std::size_t> hash_value (const Weighted_point_3& weighed_point) { std::size_t result = hash_value(weighed_point.point()); boost::hash_combine(result, hash_value(weighed_point.weight())); return result; } } //namespace CGAL // overloads of std::hash used for using std::unordered_[set/map] on CGAL Kernel objects namespace std { template struct hash > { std::size_t operator() (const CGAL::Aff_transformation_2& transform) const { return CGAL::hash_value (transform); } }; template <> struct hash { std::size_t operator() (const CGAL::Bbox_2& bbox) const { return CGAL::hash_value (bbox); } }; template struct hash > { std::size_t operator() (const CGAL::Circle_2& circle) const { return CGAL::hash_value (circle); } }; template struct hash > { std::size_t operator() (const CGAL::Iso_rectangle_2& iso_rectangle) const { return CGAL::hash_value (iso_rectangle); } }; template struct hash > { std::size_t operator() (const CGAL::Point_2& point) const { return CGAL::hash_value (point); } }; template struct hash > { std::size_t operator() (const CGAL::Segment_2& segment) const { return CGAL::hash_value (segment); } }; template struct hash > { std::size_t operator() (const CGAL::Vector_2& vector) const { return CGAL::hash_value (vector); } }; template struct hash > { std::size_t operator() (const CGAL::Weighted_point_2& weighted_point) const { return CGAL::hash_value (weighted_point); } }; template struct hash > { std::size_t operator() (const CGAL::Aff_transformation_3& transform) const { return CGAL::hash_value (transform); } }; template <> struct hash { std::size_t operator() (const CGAL::Bbox_3& bbox) const { return CGAL::hash_value (bbox); } }; template struct hash > { std::size_t operator() (const CGAL::Iso_cuboid_3& iso_cuboid) const { return CGAL::hash_value (iso_cuboid); } }; template struct hash > { std::size_t operator() (const CGAL::Point_3& point) const { return CGAL::hash_value (point); } }; template struct hash > { std::size_t operator() (const CGAL::Segment_3& segment) const { return CGAL::hash_value (segment); } }; template struct hash > { std::size_t operator() (const CGAL::Sphere_3& sphere) const { return CGAL::hash_value (sphere); } }; template struct hash > { std::size_t operator() (const CGAL::Vector_3& vector) const { return CGAL::hash_value (vector); } }; template struct hash > { std::size_t operator() (const CGAL::Weighted_point_3& weighted_point) const { return CGAL::hash_value (weighted_point); } }; } #endif // CGAL_KERNEL_HASH_FUNCTIONS_H