// Copyright (c) 2006-2008 Fernando Luis Cacciola Carballal. All rights reserved. // // This file is part of CGAL (www.cgal.org). // // $URL: https://github.com/CGAL/cgal/blob/v5.1/Straight_skeleton_2/include/CGAL/compute_outer_frame_margin.h $ // $Id: compute_outer_frame_margin.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : Fernando Cacciola // #ifndef CGAL_COMPUTE_OUTER_FRAME_MARGIN_H #define CGAL_COMPUTE_OUTER_FRAME_MARGIN_H #include #include #include #include #include #include #include namespace CGAL { template boost::optional< typename Traits::FT > compute_outer_frame_margin ( ForwardPointIterator aBegin , ForwardPointIterator aEnd , typename Traits::FT aOffset , Traits const& aTraits ) { typedef typename Traits::Kernel Kernel ; typedef typename Traits::FT FT ; typedef typename Traits::Point_2 Point_2 ; typedef typename Traits::Segment_2 Segment_2 ; typedef typename Traits::Trisegment_2_ptr Trisegment_2_ptr ; Kernel kernel ; typename Kernel::Equal_2 equal = kernel.equal_2_object(); typename Kernel::Collinear_2 collinear = kernel.collinear_2_object(); typename Kernel::Compute_squared_distance_2 squared_distance = kernel.compute_squared_distance_2_object(); typename Kernel::Construct_segment_2 construct_segment = kernel.construct_segment_2_object(); typedef boost::optional OptionalPoint_2 ; FT lMaxSDist(0.0) ; ForwardPointIterator lLast = std::prev(aEnd) ; bool lOverflow = false ; for ( ForwardPointIterator lCurr = aBegin ; lCurr != aEnd ; ++ lCurr ) { ForwardPointIterator lPrev = ( lCurr == aBegin ? lLast : std::prev (lCurr) ) ; ForwardPointIterator lNext = ( lCurr == lLast ? aBegin : std::next (lCurr) ) ; if ( !equal(*lPrev,*lCurr) && !equal(*lCurr,*lNext) && !collinear(*lPrev,*lCurr,*lNext) ) { Segment_2 lLEdge = construct_segment(*lPrev,*lCurr); Segment_2 lREdge = construct_segment(*lCurr,*lNext); OptionalPoint_2 lP = Construct_offset_point_2(aTraits)(aOffset,lLEdge,lREdge, Trisegment_2_ptr() ); if ( !lP ) { lOverflow = true ; break ; } FT lSDist = squared_distance(*lCurr,*lP); if ( ! CGAL_NTS is_valid ( lSDist ) || ! CGAL_NTS is_finite( lSDist ) ) { lOverflow = true ; break ; } if ( lSDist > lMaxSDist ) lMaxSDist = lSDist ; } } if ( ! lOverflow ) { FT lDist = CGAL_SS_i::inexact_sqrt(lMaxSDist) ; return boost::optional( lDist + ( aOffset * FT(1.05) ) ) ; // Add a %5 gap } else return boost::optional(); } template boost::optional compute_outer_frame_margin ( ForwardPointIterator aBegin, ForwardPointIterator aEnd, FT aOffset ) { typedef typename std::iterator_traits::value_type Point_2 ; typedef typename Kernel_traits::Kernel K; Polygon_offset_builder_traits_2 traits ; return compute_outer_frame_margin(aBegin,aEnd,aOffset,traits); } } // end namespace CGAL #endif // CGAL_COMPUTE_OUTER_FRAME_MARGIN_H // // EOF //