|
BWAPI
|
00001 // Copyright (c) 2006 Fernando Luis Cacciola Carballal. All rights reserved. 00002 // 00003 // This file is part of CGAL (www.cgal.org); you may redistribute it under 00004 // the terms of the Q Public License version 1.0. 00005 // See the file LICENSE.QPL distributed with CGAL. 00006 // 00007 // Licensees holding a valid commercial license may use this file in 00008 // accordance with the commercial license agreement provided with the software. 00009 // 00010 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00011 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00012 // 00013 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Straight_skeleton_2/include/CGAL/constructions/Polygon_offset_cons_ftC2.h $ 00014 // $Id: Polygon_offset_cons_ftC2.h 46517 2008-10-28 13:35:18Z afabri $ 00015 // 00016 // Author(s) : Fernando Cacciola <fernando_cacciola@ciudad.com.ar> 00017 // 00018 #ifndef CGAL_POLYGON_OFFSET_CONS_FTC2_H 00019 #define CGAL_POLYGON_OFFSET_CONS_FTC2_H 1 00020 00021 #include <CGAL/constructions/Straight_skeleton_cons_ftC2.h> 00022 00023 CGAL_BEGIN_NAMESPACE 00024 00025 namespace CGAL_SS_i 00026 { 00027 00028 // Given an offset distance 't' and 2 oriented line segments e0 and e1, returns the coordinates (x,y) 00029 // of the intersection of their offsets at the given distance. 00030 // 00031 // PRECONDITIONS: 00032 // The line coefficients must be normalized: a�+b�==1 and (a,b) being the leftward normal vector 00033 // The offsets at the given distance do intersect in a single point. 00034 // 00035 // POSTCONDITION: In case of overflow an empty optional is returned. 00036 // 00037 template<class K> 00038 optional< Point_2<K> > construct_offset_pointC2 ( typename K::FT const& t 00039 , Segment_2<K> const& e0 00040 , Segment_2<K> const& e1 00041 , intrusive_ptr< Trisegment_2<K> > const& tri 00042 ) 00043 { 00044 typedef typename K::FT FT ; 00045 00046 typedef Point_2<K> Point_2 ; 00047 typedef Line_2<K> Line_2 ; 00048 00049 typedef optional<Point_2> Optional_point_2 ; 00050 typedef optional<Line_2> Optional_line_2 ; 00051 00052 FT x(0.0),y(0.0) ; 00053 00054 CGAL_STSKEL_TRAITS_TRACE("Constructing offset point for t=" << t << " e0=" << s2str(e0) << " e1=" << s2str(e1) << " tri=" << tri ) ; 00055 00056 Optional_line_2 l0 = compute_normalized_line_ceoffC2(e0) ; 00057 Optional_line_2 l1 = compute_normalized_line_ceoffC2(e1) ; 00058 00059 bool ok = false ; 00060 00061 if ( l0 && l1 ) 00062 { 00063 FT den = l1->a() * l0->b() - l0->a() * l1->b() ; 00064 00065 if ( CGAL_NTS is_finite(den) ) 00066 { 00067 if ( ! CGAL_NTS is_zero(den) ) 00068 { 00069 FT numX = t * l1->b() - t * l0->b() + l0->b() * l1->c() - l1->b() * l0->c() ; 00070 FT numY = t * l1->a() - t * l0->a() + l0->a() * l1->c() - l1->a() * l0->c() ; 00071 00072 x = -numX / den ; 00073 y = numY / den ; 00074 00075 ok = CGAL_NTS is_finite(x) && CGAL_NTS is_finite(y) ; 00076 } 00077 else 00078 { 00079 CGAL_STSKEL_TRAITS_TRACE(" DEGENERATE case: Collinear segments involved. Seed event " << ( !tri ? " ABSENT" : " exists." ) ) ; 00080 00081 Optional_point_2 q = tri ? construct_offset_lines_isecC2(tri) : compute_oriented_midpoint(e0,e1) ; 00082 00083 if ( q ) 00084 { 00085 CGAL_STSKEL_TRAITS_TRACE(" Seed point: " << p2str(*q) ) ; 00086 00087 FT px, py ; 00088 line_project_pointC2(l0->a(),l0->b(),l0->c(),q->x(),q->y(),px,py); 00089 00090 CGAL_STSKEL_TRAITS_TRACE(" Projected seed point: (" << px << "," << py << ")" ) ; 00091 00092 x = px + l0->a() * t ; 00093 y = py + l0->b() * t ; 00094 00095 ok = CGAL_NTS is_finite(x) && CGAL_NTS is_finite(y) ; 00096 } 00097 } 00098 } 00099 } 00100 00101 CGAL_STSKEL_TRAITS_TRACE(" RESULT: (" << x << "," << y << ")" << ( ok ? "" : " NONE really" ) ) ; 00102 00103 return cgal_make_optional(ok,K().construct_point_2_object()(x,y)) ; 00104 } 00105 00106 } // namespace CGAL_SS_i 00107 00108 CGAL_END_NAMESPACE 00109 00110 #endif // CGAL_POLYGON_OFFSET_CONS_FTC2_H // 00111 // EOF // 00112
1.7.6.1