// Copyright (c) 2019 // GeometryFactory (France) // // This file is part of CGAL (www.cgal.org) // // $URL: https://github.com/CGAL/cgal/blob/v5.1/Kernel_23/include/CGAL/Kernel/hash_functions.h $ // $Id: hash_functions.h 9bf61b7 2020-04-22T11:02:16+02:00 Maxime Gimeno // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // // // 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