/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include "WhiteBox_precompiled.h" #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