/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include "EditorWhiteBoxComponentModeTypes.h" #include "WhiteBoxModifierUtil.h" #include namespace WhiteBox { template static float IntersectionDistance(const AZStd::optional& intersection) { return intersection.has_value() ? intersection->m_intersection.m_closestDistance : std::numeric_limits::max(); } GeometryIntersection FindClosestGeometryIntersection( const AZStd::optional& edgeIntersection, const AZStd::optional& polygonIntersection, const AZStd::optional& vertexIntersection) { if (!edgeIntersection.has_value() && !polygonIntersection.has_value() && !vertexIntersection.has_value()) { return GeometryIntersection::None; } // simple wrapper type to help sort values struct IntersectionType { float m_distance; GeometryIntersection m_type; }; AZStd::array intersections{ IntersectionType{IntersectionDistance(edgeIntersection), GeometryIntersection::Edge}, IntersectionType{IntersectionDistance(polygonIntersection), GeometryIntersection::Polygon}, IntersectionType{IntersectionDistance(vertexIntersection), GeometryIntersection::Vertex}}; AZStd::sort( AZStd::begin(intersections), AZStd::end(intersections), [](const IntersectionType& lhs, const IntersectionType& rhs) { return lhs.m_distance < rhs.m_distance; }); return intersections.front().m_type; } } // namespace WhiteBox