Math-Clipper-1.29000755001750001750 013467455703 13005 5ustar00mikemike000000000000Math-Clipper-1.29/Build.PL000444001750001750 136313467455703 14441 0ustar00mikemike000000000000#!/usr/bin/perl -w use strict; use Module::Build::WithXSpp; my $build = Module::Build::WithXSpp->new( module_name => 'Math::Clipper', license => 'perl', configure_requires => { 'Module::Build' => '0.38', }, build_requires => { 'Test::Deep' => '0', }, # _GLIBCXX_USE_C99 : to get the long long type for g++ # HAS_BOOL : stops Perl/lib/CORE/handy.h from doing "# define bool char" for MSVC extra_compiler_flags => [qw(-D_GLIBCXX_USE_C99 -DHAS_BOOL)], # Provides extra C typemaps that are auto-merged extra_typemap_modules => { 'ExtUtils::Typemaps::Default' => '0.05', }, #for MSVC builds early_includes => [qw( cstring cstdlib ostream )] ); $build->create_build_script; Math-Clipper-1.29/Changes000444001750001750 1160113467455703 14454 0ustar00mikemike000000000000Revision history for Perl extension Math::Clipper. 1.29 Thursday May 16 23:51:00 2019 - Fix build error under clang and pre-5.18 Perls. 1.28 Sat May 11 03:42:00 2019 - Avoid use of ** in calculating scaling factors in integerize_coordinate_sets() to avoid inconsistent behavior of underlying pow() function between BSD + clang and other systems. 1.27 Sun May 13 17:46:00 2018 - Fix integerize bug introduced in 1.26 for 32 bit Perl (ivsize < 8) 1.26 Tue May 1 02:47:00 2018 - Harmonize differences in float multiplication results found on FreeBSD + clang systems in integerize_coordinate_sets() 1.25 Mon April 30 11:44:00 2018 - Fix Integerize.t to support Perls with long doubles - More explicit rounding and truncating in integerize_coordinate_sets() 1.24 Fri April 20 15:19:00 2018 - Fix Integerize.t to handle '-0' from sprintf("%.0f") in Perl 5.27.8. 1.23 Thu May 22 20:30:00 2014 - Fix 5.20 compatibility: av_extend is now using unsigned lengths. 1.22 Sun May 19 17:14:00 2013 - Fixed some memory leaks. 1.21 Fri May 10 14:43:00 2013 - New pt_execute() method exposing PolyTree. - New int_offset2() - Upgraded the Clipper library to the newest available version 5.1.5. 1.20 Sun Apr 28 15:43:00 2013 - Fix compilation on Windows. 1.19 Mon Apr 22 13:54:00 2013 - Upgraded the Clipper library to the newest available version 5.1.4. 1.18 Sun Mar 31 12:46:00 2013 - new int_offset() - new ex_int_offset() - new ex_int_offset2() 1.17 Tue Jan 15 14:07:00 2013 - Expose PFT_POSITIVE and PFT_NEGATIVE constants. - Upgraded the Clipper library to the newest available version 5.0.3. 1.16 Wed Dec 26 15:29:00 2012 - Upgraded the Clipper library to the newest available version 4.10.0. 1.15 Sat Nov 09 17:16:00 2012 - Upgraded the Clipper library to the newest available version 4.9.6. 1.14 Sat Nov 03 02:00:00 2012 - Upgraded the Clipper library to the newest available version 4.9.4. 1.13 Wed Nov 01 01:19:00 2012 - Upgraded the Clipper library to the newest available version 4.9.3. 1.12 Tue Oct 30 01:09:00 2012 - Fixed Int128 comparison operators in Clipper library, which could cause wrong orientations. 1.11 Mon Oct 22 14:33:00 2012 - Reduced 32 bit and 64 bit max integer limits introduced in 4.8.6. 1.10 Tue Oct 16 17:39:00 2012 - Upgraded the Clipper library to the newest available version 4.8.8. 1.08 Mon May 28 19:16:00 2012 - Upgraded the Clipper library to the newest available version 4.8.3. 1.07 Tue May 01 12:30:00 2012 - Upgraded the Clipper library to the newest available version 4.8.0. - Upgraded the Clipper library to the newest available version 4.7.5. 1.06 Mon Apr 02 18:36:00 2012 - new simplify_polygon() and simplify_polygons() functions - Renamed is_counter_clockwise() to orientation() (the former is still exported for backwards compatibility). 1.05 Sun Mar 11 19:06:00 2012 - Releasing again, since the 1.04 release got out broken probably. 1.04 Sun Mar 11 19:01:00 2012 - Upgraded the Clipper library to the newest available version 4.7.3. 1.03 Sat Jan 28 16:39:43 2012 - Added a sub CLONE_SKIP { 1 } to make the module thread-safe in its basic form 1.02 Tue Oct 11 16:36:00 2011 - Upgraded the Clipper library to the newest available version 4.5.5. use_full_coordinate_range is always enabled by default, so we now provide this method for legacy purposes but it's actually a no-op. - Removed warning from integerize_coordinate_sets(). - Added Test::Deep to prerequisites. 1.01 Mon Oct 03 09:15:00 2011 - Upgraded the Clipper library to the newest available version 4.4.4. - New jointype and miterlimit arguments supported for OffsetPolygons 1.00 Mon Sep 19 08:48:00 2011 * WARNING * This release contains incompatible changes! - Upgraded the Clipper library to the newest available version 4.3.0. - Clipper 4.3.0 has various interface changes, see the documentation for details. Most importantly, the coordinates are now 64bit integers instead of floating point numbers. - Clipper 4.3.0 now works with large integers internally instead of floats. Thus, this release adds support and tests for Clipper's int/double conversions. - Add ex_execute() for ExPolygons. - Add use_full_coordinate_range() method. - Remove broken is_clockwise() function and replace with is_counter_clockwise(), which is what the C++ function IsClockwise() has been doing all along. - area() is now a function instead of a method. - Exposes polygon_offset function. - force_orientation related functions are gone. - Compilation fixes for Windows perls and compilers. - Internals: => Use ExtUtils::Typemaps instead of the deprecated ExtUtils::Typemap. => Moved all XS++ types to the clipper:: C++ namespace to avoid collisions on Win32. 0.01 Thu Aug 19 19:00:00 2010 - original version Math-Clipper-1.29/MANIFEST000444001750001750 65313467455703 14257 0ustar00mikemike000000000000Build.PL Changes lib/Math/Clipper.pm MANIFEST This list of files MANIFEST.SKIP META.yml src/clipper.cpp src/clipper.hpp src/myinit.h src/offset.h src/poly2av.h src/ppport.h t/001compile.t t/002basic.t t/003boolops.t t/004filltype.t t/005offset.t t/006winding.t t/007usefullrange.t t/008integerize.t t/009expolygon.t t/010simplify.t t/011Int128Comparison.t t/012_polytree.t xsp/Clipper.xsp xsp/my.map xsp/types.xspt META.json Math-Clipper-1.29/MANIFEST.SKIP000444001750001750 124513467455703 15042 0ustar00mikemike000000000000# Avoid archives of this distribution \bMath-Clipper-\d+\.\d+(?:_\d+)?\.tar\.gz$ # Avoid version control files. \bRCS\b \bCVS\b ,v$ \B\.svn\b \B\.cvsignore$ \B\.git\b \B\.gitignore$ # Avoid Makemaker generated and utility files. \bMakefile$ \bblib \bMakeMaker-\d \bpm_to_blib$ \bblibdirs$ # Avoid Module::Build generated and utility files. \bBuild$ \bBuild.bat$ \b_build # Avoid Devel::Cover generated files \bcover_db # Avoid temp and backup files. ~$ \.tmp$ \.old$ \.bak$ \#$ \.# \.rej$ \.swp$ \.swo$ # Avoid OS-specific files/dirs # Mac OSX metadata \B\.DS_Store # Mac OSX SMB mount metadata files \B\._ ^MYMETA.yml$ \.o$ \bbuildtmp\b \bclipper/ ^MYMETA\.json$ Math-Clipper-1.29/META.json000444001750001750 213313467455703 14562 0ustar00mikemike000000000000{ "abstract" : "Polygon clipping in 2D", "author" : [ "Steffen Mueller (Esmueller@cpan.orgE)," ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4224", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Math-Clipper", "prereqs" : { "build" : { "requires" : { "ExtUtils::Typemaps::Default" : "0.05", "ExtUtils::XSpp" : "0.18", "Test::Deep" : "0" } }, "configure" : { "requires" : { "ExtUtils::CppGuess" : "0.12", "Module::Build" : "0.38", "Module::Build::WithXSpp" : "0.14" } } }, "provides" : { "Math::Clipper" : { "file" : "lib/Math/Clipper.pm", "version" : "1.29" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ] }, "version" : "1.29", "x_serialization_backend" : "JSON::PP version 2.27400_02" } Math-Clipper-1.29/META.yml000444001750001750 133613467455703 14416 0ustar00mikemike000000000000--- abstract: 'Polygon clipping in 2D' author: - 'Steffen Mueller (Esmueller@cpan.orgE),' build_requires: ExtUtils::Typemaps::Default: '0.05' ExtUtils::XSpp: '0.18' Test::Deep: '0' configure_requires: ExtUtils::CppGuess: '0.12' Module::Build: '0.38' Module::Build::WithXSpp: '0.14' dynamic_config: 1 generated_by: 'Module::Build version 0.4224, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Math-Clipper provides: Math::Clipper: file: lib/Math/Clipper.pm version: '1.29' resources: license: http://dev.perl.org/licenses/ version: '1.29' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Math-Clipper-1.29/lib000755001750001750 013467455703 13553 5ustar00mikemike000000000000Math-Clipper-1.29/lib/Math000755001750001750 013467455703 14444 5ustar00mikemike000000000000Math-Clipper-1.29/lib/Math/Clipper.pm000444001750001750 6652513467455703 16573 0ustar00mikemike000000000000package Math::Clipper; use 5.008; use strict; use warnings; use Carp qw(croak carp); use Config; use Exporter(); our $VERSION; our @ISA = qw(Exporter); BEGIN { use XSLoader; $VERSION = '1.29'; XSLoader::load('Math::Clipper', $VERSION); } # TODO: keep in sync with docs below and xsp/Clipper.xsp our %EXPORT_TAGS = ( cliptypes => [qw/CT_INTERSECTION CT_UNION CT_DIFFERENCE CT_XOR/], #polytypes => [qw/PT_SUBJECT PT_CLIP/], polyfilltypes => [qw/PFT_EVENODD PFT_NONZERO PFT_POSITIVE PFT_NEGATIVE/], jointypes => [qw/JT_MITER JT_ROUND JT_SQUARE/], utilities => [qw/area offset is_counter_clockwise orientation integerize_coordinate_sets unscale_coordinate_sets simplify_polygon simplify_polygons int_offset ex_int_offset ex_int_offset2/], ); $EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ]; our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw(); my %intspecs = ( '64' => { maxint => 4611686018427387902, # Clipper-imposed max when using 64 bit integer math maxdigits => 19 }, '53' => { maxint => 9007199254740992, # signed 53 bit integer max, for integers stored in double precision floats maxdigits => 16 }, '32' => { maxint => 1073741822, # Clipper-imposed max to avoid calculations with large integer types maxdigits => 10 }, ); my $is64safe = ((defined($Config{use64bitint}) && $Config{use64bitint} eq 'define') || $Config{longsize} >= 8 ) && ((defined($Config{uselongdouble}) && $Config{uselongdouble} eq 'define') || $Config{doublesize} >= 10); sub offset { my ($polygons, $delta, $scale, $jointype, $miterlimit) = @_; $scale ||= 100; $jointype = JT_MITER if !defined $jointype; $miterlimit ||= 2; my $scalevec=[$scale,$scale]; my $polyscopy=[(map {[(map {[(map {$_*$scalevec->[0]} @{$_})]} @{$_})]} @{$polygons})]; my $ret = _offset($polyscopy,$delta*$scale, $jointype, $miterlimit); unscale_coordinate_sets($scalevec , $ret) if @$ret; return $ret; } *is_counter_clockwise = *orientation; sub unscale_coordinate_sets { # to undo what integerize_coordinate_sets() does my $scale_vector=shift; my $coord_sets=shift; my $coord_count=scalar(@{$coord_sets->[0]->[0]}); if (!ref($scale_vector)) {$scale_vector=[(map {$scale_vector} (0..$coord_count-1))];} foreach my $set (@{$coord_sets}) { foreach my $vector (@{$set}) { for (my $ci=0;$ci<$coord_count;$ci++) { $vector->[$ci] /= $scale_vector->[$ci] if $scale_vector->[$ci]; # avoid divide by zero } } } } sub integerize_coordinate_sets { my %opts=(); if (ref($_[0]) =~ /HASH/) {%opts=%{(shift)};} $opts{constrain} = 1 if !defined($opts{constrain}); $opts{bits} = ($is64safe ? 64 : 53) if !defined($opts{bits}); if ($opts{bits} == 64 && !$is64safe) {$opts{bits} = 53; carp "Integerize to 64 bits requires both long long and long double underlying Perl's default integer and double types. Using 53 bits instead.";} $opts{margin} = 0 if !defined($opts{margin}); # assume all coordinate vectors (points) have same number of coordinates; get that count from first one my $coord_count=scalar(@{$_[0]->[0]}); # return this array of each column's calculated scale factor, so users can "unscale" Clipper results my @scale_vector; # deal with each coordinate column (eg. x column, y column, ... possibly more) for (my $ci=0;$ci<$coord_count;$ci++) { my $maxc=$_[0]->[0]->[$ci]; my $max_exp; # go through all the coordinate sets, looking just at the current column foreach my $set (@_) { # for each "point" foreach my $vector (@{$set}) { # possibly update the the maximum magnitude seen in the column if ($maxc[$ci]) + $opts{margin}) {$maxc=abs($vector->[$ci]) + $opts{margin};} # look for the maximum exponent, when coords are in scientific notation if (sprintf("%.20e",$vector->[$ci] + ($vector->[$ci]<0?-1:1)*$opts{margin}) =~ /[eE]([+-])0*(\d+)$/) { my $exp1 = eval($1.$2); if (defined $vector->[$ci] && (!defined($max_exp) || $max_exp<$exp1)) {$max_exp=$exp1;} } else {croak "some coordinate didn't look like a number: ",$vector->[$ci];} } } # Set scale for this coordinate column to the largest value that will convert the # largest coordinate in the set to near the top of the available integer range. # There's never any question of how much precision the user wants - # we just always give as much as possible, within the integer limit in effect (53 bit or 64 bit) $scale_vector[$ci] = 1; my $power = -$max_exp + ($intspecs{$opts{bits}}->{maxdigits} - 1); # We explicitly calculate the equivalent to 1**$power because # the results of the system's pow() function underlying # Perl's ** operator are sometimes inconsistent between # BSD/clang and other systems. for (my $pi = 0; $pi < abs($power); $pi++) { if ($power > 0) { $scale_vector[$ci] *= 10; } elsif ($power < 0) { $scale_vector[$ci] /= 10; } } if ($maxc * $scale_vector[$ci] > $intspecs{$opts{bits}}->{maxint}) { # Both 53 bit and 64 bit integers # have max values near 9*10**(16 or 19). # So usually you have 16 or 19 digits to use. # But if your scaled-up max values enter the # zone just beyond the integer max, we'll only # scale up to 15 or 18 digit integers instead. $scale_vector[$ci] /= 10; } } # If the "constrain" option is set false, # scaling is independent for each # coordinate column - all the Xs get one scale # all the Ys something else - to take the greatest # advantage of the available integer domain. # But if the "constrain" option is set true, we use # the minimum scale from all the coordinate columns. # The minimum scale is the one that will work # for all columns, without overflowing our integer limits. if ($opts{constrain}) { my $min_scale=(sort {$a<=>$b} @scale_vector)[0]; @scale_vector = map {$min_scale} @scale_vector; } # Scale the original data foreach my $set (@_) { foreach my $vector (@{$set}) { for (my $ci=0;$ci<$coord_count;$ci++) { $vector->[$ci] *= $scale_vector[$ci]; if (abs($vector->[$ci]) < 0.5) { $vector->[$ci] = 0; } elsif (abs($vector->[$ci]) < 1) { $vector->[$ci] = $vector->[$ci] < 0 ? -1:1; } $vector->[$ci] = _floor($vector->[$ci]); } } } return \@scale_vector; } # keep this method as a no-op, as it was removed in Clipper 4.5.5 sub use_full_coordinate_range {} sub CLONE_SKIP { 1 } 1; __END__ =head1 NAME Math::Clipper - Polygon clipping in 2D =head1 SYNOPSIS use Math::Clipper ':all'; my $clipper = Math::Clipper->new; $clipper->add_subject_polygon( [ [-100, 100], [ 0, -200], [100, 100] ] ); $clipper->add_clip_polygon( [ [-100, -100], [100, -100], [ 0, 200] ] ); my $result = $clipper->execute(CT_DIFFERENCE); # $result is now a reference to an array of three triangles $clipper->clear(); # all data from previous operation cleared # object ready for reuse # Example with floating point coordinates: # Clipper requires integer input. # These polygons won't work. my $poly_1 = [ [-0.001, 0.001], [0, -0.002], [0.001, 0.001] ]; my $poly_2 = [ [-0.001, -0.001], [0.001, -0.001], [0, 0.002] ]; # But we can have them automatically scaled up (in place) to a safe integer range my $scale = integerize_coordinate_sets( $poly_1 , $poly_2 ); $clipper->add_subject_polygon( $poly_1 ); $clipper->add_clip_polygon( $poly_2 ); my $result = $clipper->execute(CT_DIFFERENCE); # to convert the results (in place) back to the original scale: unscale_coordinate_sets( $scale, $result ); # Example using 32 bit integer math instead of the default 53 or 64 # (less precision, a bit faster) my $clipper32 = Math::Clipper->new; my $scale32 = integerize_coordinate_sets( { bits=>32 } , $poly_1 , $poly_2 ); $clipper32->add_subject_polygon( $poly_1 ); $clipper32->add_clip_polygon( $poly_2 ); my $result32 = $clipper->execute(CT_DIFFERENCE); unscale_coordinate_sets( $scale32, $result32 ); =head1 DESCRIPTION C is a C++ (and Delphi) library that implements polygon clipping. =head2 Exports The module optionally exports a few constants to your namespace. Standard L semantics apply (including the C<:all> tag). The list of exportable constants is comprised of the clip operation types (which should be self-explanatory): CT_INTERSECTION CT_UNION CT_DIFFERENCE CT_XOR Additionally, there are constants that set the polygon fill type during the clipping operation: PFT_EVENODD PFT_NONZERO PFT_POSITIVE PFT_NEGATIVE =head1 CONVENTIONS I: Clipper 4.x works with polygons with integer coordinates. Data in floating point format will need to be scaled appropriately to be converted to the available integer range before polygons are added to a clipper object. (Scaling utilities are provided here.) A I is represented by a reference to an array of 2D points. A I is, in turn, represented by a reference to an array containing two numbers: The I and I coordinates. A 1x1 square polygon example: [ [0, 0], [1, 0], [1, 1], [0, 1] ] Sets of polygons, as returned by the C method, are represented by an array reference containing 0 or more polygons. Clipper also has a polygon type that explicitly associates an outer polygon with any additional polygons that describe "holes" in the filled region of the outer polygon. This is called an I. The data structure for an I is as follows,: { outer => [ ], holes => [ [ ], [ ], ... ] } Clipper additionally offers an export type named I which represents several nested polygons by assigning each one to its parent. The I structure is an arrayref looking like this one: [ { outer => [ ..points.. ], children => [] }, { outer => [ ..points.. ], children => [ { hole => [ ..points.. ], children => [] }, { hole => [ ..points.. ], children => [] }, ], } ] Each item is a hashref which may contain either the I or the I key, containing the polygon points. It also contains a I key containing an arrayref of hashrefs itself, and so on. The Clipper documentation reports that it's more computationally expensive to process (roughly 5-10% slower), it should only be used when parent-child polygon relationships are needed and not just polygon coordinates. The "fill type" of a polygon refers to the strategy used to determine which side of a polygon is the inside, and whether a polygon represents a filled region, or a hole. You may optionally specify the fill type of your subject and clip polygons when you call the C method. When you specify the NONZERO fill type, the winding order of polygon points determines whether a polygon is filled, or represents a hole. Clipper uses the convention that counter clockwise wound polygons are filled, while clockwise wound polygons represent holes. This strategy is more explicit, but requires that you manage winding order of all polygons. The EVENODD fill type strategy uses a test segment, with it's start point inside a polygon, and it's end point out beyond the bounding box of all polygons in question. All intersections between the segment and all polygons are calculated. If the intersection count is odd, the inner-most (if nested) polygon containing the segment's start point is considered to be filled. When the intersection count is even, that polygon is considered to be a hole. For an example case in which NONZERO and EVENODD produce different results see L section below. =head1 METHODS =head2 new Constructor that takes no arguments returns a new C object. =head2 add_subject_polygon Adds a(nother) polygon to the set of polygons that will be clipped. =head2 add_clip_polygon Adds a(nother) polygon to the set of polygons that define the clipping operation. =head2 add_subject_polygons Works the same as C but adds a whole set of polygons. =head2 add_clip_polygons Works the same as C but adds a whole set of polygons. =head2 execute Performs the actual clipping operation. Returns the result as a reference to an array of polygons. my $result = $clipper->execute( CT_UNION ); Parameters: the type of the clipping operation defined by one of the constants (C). Additionally, you may define the polygon fill types (C) of the subject and clipping polygons as second and third parameters respectively. By default, even-odd filling (C) will be used. my $result = $clipper->execute( CT_UNION, PFT_EVENODD, PFT_EVENODD ); =head2 ex_execute Like C, performs the actual clipping operation, but returns a reference to an array of ExPolygons. (see L) =head2 pt_execute Like C, performs the actual clipping operation, but returns a PolyTree structure. (see L) =head2 clear For reuse of a C object, you can call the C method to remove all polygons and internal data from previous clipping operations. =head1 UTILITY FUNCTIONS =head2 integerize_coordinate_sets Takes an array of polygons and scales all point coordinates so that the values will fit in the integer range available. Returns an array reference containing the scaling factors used for each coordinate column. The polygon data will be scaled in-place. The scaling vector is returned so you can "unscale" the data when you're done, using C. my $scale_vector = integerize_coordinate_sets( $poly1 , $poly2 , $poly3 ); The main purpose of this function is to convert floating point coordinate data to integers. As of Clipper version 4, only integer coordinate data is allowed. This helps make the intersection algorithm robust, but it's a bit inconvenient if your data is in floating point format. This utility function is meant to make it easy to convert your data to Clipper-friendly integers, while retaining as much precision as possible. When you're done with your clipping operations, you can use the C function to scale results back to your original scale. Convert all your polygons at once, with one call to C, before loading the polygons into your clipper object. The scaling factors need to be calculated so that all polygons involved fit in the available integer space. By default, the scaling is uniform between coordinate columns (e.g., the X values are scaled by the same factor as the Y values) making all the scaling factors returned the same. In other words, by default, the aspect ratio between X and Y is constrained. Options may be passed in an anonymous hash, as the first argument, to override defaults. If the first argument is not a hash reference, it is taken instead as the first polygon to be scaled. my $scale_vector = integerize_coordinate_sets( { constrain => 0, # don't do uniform scaling bits => 32 # use the +/-1,073,741,822 integer range }, $poly1 , $poly2 , $poly3 ); The C option can be 32, 53, or 64. The default will be 53 or 64, depending on whether your Perl uses 64 bit integers AND long doubles by default. (The scaling involves math with native doubles, so it's not enough to just have 64 bit integers.) Setting the C option to 32 may provide a modest speed boost, by allowing Clipper to avoid calculations with large integer types. The C option is a boolean. Default is true. When set to false, each column of coordinates (X, Y) will be scaled independently. This may be useful when the domain of the X values is very much larger or smaller than the domain of the Y values, to get better resolution for the smaller domain. The different scaling factors will be available in the returned scaling vector (array reference). This utility will also operate on coordinates with three or more dimensions. Though the context here is 2D, be aware of this if you happen to feed it 3D data. Large domains in the higher dimensions could squeeze the 2D data to nothing if scaling is uniform. =head2 unscale_coordinate_sets This undoes the scaling done by C. Use this on the polygons returned by the C method. Pass the scaling vector returned by C, and the polygons to "unscale". The polygon coordinates will be updated in place. unscale_coordinate_sets($scale,$clipper_result); =head2 offset my $offset_polygons = offset($polygons, $distance); my $offset_polygons = offset($polygons, $distance, $scale, $jointype, $miterlimit); Takes a reference to an array of polygons (C<$polygons>), a positive or negative offset dimension (C<$distance>), and, optionally, a scaling factor (C<$scale>), a join type (C<$jointype>) and a numeric angle limit for the C join type. The polygons will use the NONZERO fill strategy, so filled areas and holes can be specified by polygon winding order. A positive offset dimension makes filled polygons grow outward, and their holes shrink. A negative offset makes polygons shrink and their holes grow. Coordinates will be multiplied by the scaling factor before the offset operation and the results divided by the scaling factor. The default scaling factor is 100. Setting the scaling factor higher will result in more points and smoother contours in the offset results. Returns a new set of polygons, offset by the given dimension. my $offset_polygons = offset($polygons, 5.5); # offset by 5.5 or my $offset_polygons = offset($polygons, 5.5, 1000); # smoother results, proliferation of points BAs you increase the scaling factor, the number of points grows quickly, and will happily consume all of your RAM. Large offset dimensions also contribute to a proliferation of points. Floating point data in the input is acceptable - in that case, the scaling factor also determines how many decimal digits you'll get in the results. It is not necessary, and generally not desirable to use C to prepare data for this function. When doing negative offsets, you may find the winding order of the results to be the opposite of what you expect, although this seems to be fixed in recent Clipper versions. Check the order and change it if it is important in your application. Join type can be one of C, C or C. =head2 int_offset my $offset_polygons = int_offset($polygons, $distance, $scale, $jointype, $miterlimit); This function is a faster replacement for offset() when input coordinates are integers. If floats are supplied to it, their decimal digits will be truncated so the offset might work on invalid geometry (truncation can lead to self-intersecting polygons). Be sure to only use this one if your input polygons only have integer coordinates. =head2 int_offset2 my $offset_polygons = int_offset($polygons, $distance1, $distance2, $scale, $jointype, $miterlimit); This function works like int_offset() but it does two consecutive offsets with the given distances. The purpose of the I<*offset2> functions is to avoid overhead when two consecutive offsets are needed (scaling/unscaling only happens once, and no conversion to Perl variables happens in between). =head2 ex_int_offset my $offset_expolygons = ex_int_offset($polygons, $distance, $scale, $jointype, $miterlimit); This function works like int_offset() but it does a UNION operation on the resulting polygons and returns an arrayref of ExPolygons. =head2 ex_int_offset2 my $offset_expolygons = ex_int_offset2($polygons, $distance1, $distance2, $scale, $jointype, $miterlimit); This function works like ex_int_offset() but it does two consecutive offsets with the given distances before performing the UNION operation. =head2 area Returns the signed area of a single polygon. A counter clockwise wound polygon area will be positive. A clockwise wound polygon area will be negative. Coordinate data should be integers. $area = area($polygon); =head2 orientation Determine the winding order of a polygon. It returns a true value if the polygon is counter-clockwise B you're assuming a display where the Y-axis coordinates are positive I, or if the polygon is clockwise and you're assuming a positive-downward Y-axis. Coordinate data should be integers. The majority of 2D graphic display libraries have their origin (0,0) at the top left corner, thus Y increases downward; however some libraries (Quartz, OpenGL) as well as non-display applications (CNC) assume Y increases upward. my $poly = [ [0, 0] , [2, 0] , [1, 1] ]; # a counter clockwise wound polygon (assuming Y upward) my $direction = orientation($poly); # now $direction == 1 This function was previously named C. This symbol is still exported for backwards compatibility; however you're encouraged to switch it to C as the underlying Clipper library switched to it too to clarify the Y axis convention issue. =head2 simplify_polygon =head2 simplify_polygons These functions convert self-intersecting polygons (known as I polygons) to I polygons. C takes a single polygon as first argument, while C takes multiple polygons in a single arrayref. The second argument must be a polyfilltype constant (PFT_*, see above). Both return an arrayref of polygons. =head1 MAXIMUM COORDINATE VALUES AND 64 BIT SUPPORT Clipper accepts 64 bit integer input, but limits the domain of input coordinate values to +/-4,611,686,018,427,387,902, to allow enough overhead for certain calculations. Coordinate values up to these limits are possible with Perls built to support 64 bit integers. A typical Perl that supports 32 bit integers can alternatively store 53 bit integers as floating point numbers. In this case, the coordinate domain is limited to +/-9,007,199,254,740,992. When optionally constraining coordinate values to 32 bit integers, the domain is +/-1,073,741,822. The C utility function automatically respects whichever limit applies to your Perl build. =head1 NONZERO vs. EVENODD Consider the following example: my $p1 = [ [0,0], [200000,0], [200000,200000] ]; # CCW my $p2 = [ [0,200000], [0,0], [200000,200000] ]; # CCW my $p3 = [ [0,0], [200000,0], [200000,200000], [0,200000] ]; # CCW my $clipper = Math::Clipper->new; $clipper->add_subject_polygon($p1); $clipper->add_clip_polygons([$p2, $p3]); my $result = $clipper->execute(CT_UNION, PFT_EVENODD, PFT_EVENODD); C<$p3> is a square, and C<$p1> and C<$p2> are triangles covering two halves of the C<$p3> area. The C operation will produce different results, depending on whether C or C is used. These are the two different strategies used by Clipper to identify filled vs. empty regions. Let's see the thing in detail: C<$p2> and C<$p3> are the clip polygons. C<$p2> overlaps half of C<$p3>. With the C fill strategy, the number of polygons that overlap in a given area determines whether that area is a hole or a filled region. If an odd number of polygons overlap there, it's a filled region. If an even number, it's a hole/empty region. So with C, winding order doesn't matter. What matters is where areas overlap. So, using C, and considering C<$p2> and C<$p3> as the set of clipping polygons, the fact that C<$p2> overlaps half of C<$p3> means that the region where they overlap is empty. In effect, in this example, the set of clipping polygons ends up defining the same shape as the subject polygon C<$p1>. So the union is just the union of two identical polygons, and the result is a triangle equivalent to C<$p1>. If, instead, the C strategy is specified, the set of clipping polygons is understood as two filled polygons, because of the winding order. The area where they overlap is considered filled, because there is at least one filled polygon in that area. The set of clipping polygons in this case is equivalent to the square C<$p3>, and the result of the C operation is also equivalent to the square C<$p3>. This is a good example of how C is more explicit, and perhaps more intuitive. =head1 SEE ALSO The SourceForge project page of Clipper: L =head1 VERSION This module was built around, and includes, Clipper version 5.1.5. =head1 AUTHOR The Perl module was written by: Steffen Mueller (Esmueller@cpan.orgE), Mike Sheldrake and Alessandro Ranellucci (aar/alexrj) But the underlying library C was written by Angus Johnson. Check the SourceForge project page for contact information. =head1 COPYRIGHT AND LICENSE The C module is Copyright (C) 2010, 2011, 2014 by Steffen Mueller Copyright (C) 2011, 2018, 2019 by Mike Sheldrake Copyright (C) 2012, 2013 by Alessandro Ranellucci and Mike Sheldrake but we are shipping a copy of the C C++ library, which is Copyright (C) 2010, 2011, 2012 by Angus Johnson. C is available under the same license as C itself. This is the C license: Boost Software License - Version 1.0 - August 17th, 2003 http://www.boost.org/LICENSE_1_0.txt Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =cut Math-Clipper-1.29/src000755001750001750 013467455703 13574 5ustar00mikemike000000000000Math-Clipper-1.29/src/clipper.cpp000555001750001750 32627613467455703 16156 0ustar00mikemike000000000000/******************************************************************************* * * * Author : Angus Johnson * * Version : 5.1.5 * * Date : 4 May 2013 * * Website : http://www.angusj.com * * Copyright : Angus Johnson 2010-2013 * * * * License: * * Use, modification & distribution is subject to Boost Software License Ver 1. * * http://www.boost.org/LICENSE_1_0.txt * * * * Attributions: * * The code in this library is an extension of Bala Vatti's clipping algorithm: * * "A generic solution to polygon clipping" * * Communications of the ACM, Vol 35, Issue 7 (July 1992) pp 56-63. * * http://portal.acm.org/citation.cfm?id=129906 * * * * Computer graphics and geometric modeling: implementation and algorithms * * By Max K. Agoston * * Springer; 1 edition (January 4, 2005) * * http://books.google.com/books?q=vatti+clipping+agoston * * * * See also: * * "Polygon Offsetting by Computing Winding Numbers" * * Paper no. DETC2005-85513 pp. 565-575 * * ASME 2005 International Design Engineering Technical Conferences * * and Computers and Information in Engineering Conference (IDETC/CIE2005) * * September 24-28, 2005 , Long Beach, California, USA * * http://www.me.berkeley.edu/~mcmains/pubs/DAC05OffsetPolygon.pdf * * * *******************************************************************************/ /******************************************************************************* * * * This is a translation of the Delphi Clipper library and the naming style * * used has retained a Delphi flavour. * * * *******************************************************************************/ #include "clipper.hpp" #include #include #include #include #include #include #include namespace ClipperLib { static long64 const loRange = 0x3FFFFFFF; static long64 const hiRange = 0x3FFFFFFFFFFFFFFFLL; static double const pi = 3.141592653589793238; enum Direction { dRightToLeft, dLeftToRight }; #define HORIZONTAL (-1.0E+40) #define TOLERANCE (1.0e-20) #define NEAR_ZERO(val) (((val) > -TOLERANCE) && ((val) < TOLERANCE)) #define NEAR_EQUAL(a, b) NEAR_ZERO((a) - (b)) inline long64 Abs(long64 val) { return val < 0 ? -val : val; } //------------------------------------------------------------------------------ // PolyTree methods ... //------------------------------------------------------------------------------ void PolyTree::Clear() { for (PolyNodes::size_type i = 0; i < AllNodes.size(); ++i) delete AllNodes[i]; AllNodes.resize(0); Childs.resize(0); } //------------------------------------------------------------------------------ PolyNode* PolyTree::GetFirst() const { if (!Childs.empty()) return Childs[0]; else return 0; } //------------------------------------------------------------------------------ int PolyTree::Total() const { return AllNodes.size(); } //------------------------------------------------------------------------------ // PolyNode methods ... //------------------------------------------------------------------------------ PolyNode::PolyNode(): Childs(), Parent(0), Index(0) { } //------------------------------------------------------------------------------ int PolyNode::ChildCount() const { return Childs.size(); } //------------------------------------------------------------------------------ void PolyNode::AddChild(PolyNode& child) { unsigned cnt = Childs.size(); Childs.push_back(&child); child.Parent = this; child.Index = cnt; } //------------------------------------------------------------------------------ PolyNode* PolyNode::GetNext() const { if (!Childs.empty()) return Childs[0]; else return GetNextSiblingUp(); } //------------------------------------------------------------------------------ PolyNode* PolyNode::GetNextSiblingUp() const { if (!Parent) //protects against PolyTree.GetNextSiblingUp() return 0; else if (Index == Parent->Childs.size() - 1) return Parent->GetNextSiblingUp(); else return Parent->Childs[Index + 1]; } //------------------------------------------------------------------------------ bool PolyNode::IsHole() const { bool result = true; PolyNode* node = Parent; while (node) { result = !result; node = node->Parent; } return result; } //------------------------------------------------------------------------------ // Int128 class (enables safe math on signed 64bit integers) // eg Int128 val1((long64)9223372036854775807); //ie 2^63 -1 // Int128 val2((long64)9223372036854775807); // Int128 val3 = val1 * val2; // val3.AsString => "85070591730234615847396907784232501249" (8.5e+37) //------------------------------------------------------------------------------ class Int128 { public: ulong64 lo; long64 hi; Int128(long64 _lo = 0) { lo = (ulong64)_lo; if (_lo < 0) hi = -1; else hi = 0; } Int128(const Int128 &val): lo(val.lo), hi(val.hi){} Int128(const long64& _hi, const ulong64& _lo): lo(_lo), hi(_hi){} long64 operator = (const long64 &val) { lo = (ulong64)val; if (val < 0) hi = -1; else hi = 0; return val; } bool operator == (const Int128 &val) const {return (hi == val.hi && lo == val.lo);} bool operator != (const Int128 &val) const { return !(*this == val);} bool operator > (const Int128 &val) const { if (hi != val.hi) return hi > val.hi; else return lo > val.lo; } bool operator < (const Int128 &val) const { if (hi != val.hi) return hi < val.hi; else return lo < val.lo; } bool operator >= (const Int128 &val) const { return !(*this < val);} bool operator <= (const Int128 &val) const { return !(*this > val);} Int128& operator += (const Int128 &rhs) { hi += rhs.hi; lo += rhs.lo; if (lo < rhs.lo) hi++; return *this; } Int128 operator + (const Int128 &rhs) const { Int128 result(*this); result+= rhs; return result; } Int128& operator -= (const Int128 &rhs) { *this += -rhs; return *this; } Int128 operator - (const Int128 &rhs) const { Int128 result(*this); result -= rhs; return result; } Int128 operator-() const //unary negation { if (lo == 0) return Int128(-hi,0); else return Int128(~hi,~lo +1); } Int128 operator/ (const Int128 &rhs) const { if (rhs.lo == 0 && rhs.hi == 0) throw "Int128 operator/: divide by zero"; bool negate = (rhs.hi < 0) != (hi < 0); Int128 dividend = *this; Int128 divisor = rhs; if (dividend.hi < 0) dividend = -dividend; if (divisor.hi < 0) divisor = -divisor; if (divisor < dividend) { Int128 result = Int128(0); Int128 cntr = Int128(1); while (divisor.hi >= 0 && !(divisor > dividend)) { divisor.hi <<= 1; if ((long64)divisor.lo < 0) divisor.hi++; divisor.lo <<= 1; cntr.hi <<= 1; if ((long64)cntr.lo < 0) cntr.hi++; cntr.lo <<= 1; } divisor.lo >>= 1; if ((divisor.hi & 1) == 1) divisor.lo |= 0x8000000000000000LL; divisor.hi = (ulong64)divisor.hi >> 1; cntr.lo >>= 1; if ((cntr.hi & 1) == 1) cntr.lo |= 0x8000000000000000LL; cntr.hi >>= 1; while (cntr.hi != 0 || cntr.lo != 0) { if (!(dividend < divisor)) { dividend -= divisor; result.hi |= cntr.hi; result.lo |= cntr.lo; } divisor.lo >>= 1; if ((divisor.hi & 1) == 1) divisor.lo |= 0x8000000000000000LL; divisor.hi >>= 1; cntr.lo >>= 1; if ((cntr.hi & 1) == 1) cntr.lo |= 0x8000000000000000LL; cntr.hi >>= 1; } if (negate) result = -result; return result; } else if (rhs.hi == this->hi && rhs.lo == this->lo) return Int128(1); else return Int128(0); } double AsDouble() const { const double shift64 = 18446744073709551616.0; //2^64 if (hi < 0) { if (lo == 0) return (double)hi * shift64; else return -(double)(~lo + ~hi * shift64); } else return (double)(lo + hi * shift64); } }; Int128 Int128Mul (long64 lhs, long64 rhs) { bool negate = (lhs < 0) != (rhs < 0); if (lhs < 0) lhs = -lhs; ulong64 int1Hi = ulong64(lhs) >> 32; ulong64 int1Lo = ulong64(lhs & 0xFFFFFFFF); if (rhs < 0) rhs = -rhs; ulong64 int2Hi = ulong64(rhs) >> 32; ulong64 int2Lo = ulong64(rhs & 0xFFFFFFFF); //nb: see comments in clipper.pas ulong64 a = int1Hi * int2Hi; ulong64 b = int1Lo * int2Lo; ulong64 c = int1Hi * int2Lo + int1Lo * int2Hi; Int128 tmp; tmp.hi = long64(a + (c >> 32)); tmp.lo = long64(c << 32); tmp.lo += long64(b); if (tmp.lo < b) tmp.hi++; if (negate) tmp = -tmp; return tmp; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ bool FullRangeNeeded(const Polygon &pts) { bool result = false; for (Polygon::size_type i = 0; i < pts.size(); ++i) { if (Abs(pts[i].X) > hiRange || Abs(pts[i].Y) > hiRange) throw "Coordinate exceeds range bounds."; else if (Abs(pts[i].X) > loRange || Abs(pts[i].Y) > loRange) result = true; } return result; } //------------------------------------------------------------------------------ bool Orientation(const Polygon &poly) { return Area(poly) >= 0; } //------------------------------------------------------------------------------ inline bool PointsEqual( const IntPoint &pt1, const IntPoint &pt2) { return ( pt1.X == pt2.X && pt1.Y == pt2.Y ); } //------------------------------------------------------------------------------ double Area(const Polygon &poly) { int highI = (int)poly.size() -1; if (highI < 2) return 0; if (FullRangeNeeded(poly)) { Int128 a; a = Int128Mul(poly[highI].X + poly[0].X, poly[0].Y - poly[highI].Y); for (int i = 1; i <= highI; ++i) a += Int128Mul(poly[i - 1].X + poly[i].X, poly[i].Y - poly[i -1].Y); return a.AsDouble() / 2; } else { double a; a = ((double)poly[highI].X + poly[0].X) * ((double)poly[0].Y - poly[highI].Y); for (int i = 1; i <= highI; ++i) a += ((double)poly[i - 1].X + poly[i].X) * ((double)poly[i].Y - poly[i - 1].Y); return a / 2; } } //------------------------------------------------------------------------------ double Area(const OutRec &outRec, bool UseFullInt64Range) { OutPt *op = outRec.pts; if (!op) return 0; if (UseFullInt64Range) { Int128 a(0); do { a += Int128Mul(op->pt.X + op->prev->pt.X, op->prev->pt.Y - op->pt.Y); op = op->next; } while (op != outRec.pts); return a.AsDouble() / 2; } else { double a = 0; do { a = a + (op->pt.X + op->prev->pt.X) * (op->prev->pt.Y - op->pt.Y); op = op->next; } while (op != outRec.pts); return a / 2; } } //------------------------------------------------------------------------------ bool PointIsVertex(const IntPoint &pt, OutPt *pp) { OutPt *pp2 = pp; do { if (PointsEqual(pp2->pt, pt)) return true; pp2 = pp2->next; } while (pp2 != pp); return false; } //------------------------------------------------------------------------------ bool PointOnLineSegment(const IntPoint pt, const IntPoint linePt1, const IntPoint linePt2, bool UseFullInt64Range) { if (UseFullInt64Range) return ((pt.X == linePt1.X) && (pt.Y == linePt1.Y)) || ((pt.X == linePt2.X) && (pt.Y == linePt2.Y)) || (((pt.X > linePt1.X) == (pt.X < linePt2.X)) && ((pt.Y > linePt1.Y) == (pt.Y < linePt2.Y)) && ((Int128Mul((pt.X - linePt1.X), (linePt2.Y - linePt1.Y)) == Int128Mul((linePt2.X - linePt1.X), (pt.Y - linePt1.Y))))); else return ((pt.X == linePt1.X) && (pt.Y == linePt1.Y)) || ((pt.X == linePt2.X) && (pt.Y == linePt2.Y)) || (((pt.X > linePt1.X) == (pt.X < linePt2.X)) && ((pt.Y > linePt1.Y) == (pt.Y < linePt2.Y)) && ((pt.X - linePt1.X) * (linePt2.Y - linePt1.Y) == (linePt2.X - linePt1.X) * (pt.Y - linePt1.Y))); } //------------------------------------------------------------------------------ bool PointOnPolygon(const IntPoint pt, OutPt *pp, bool UseFullInt64Range) { OutPt *pp2 = pp; for (;;) { if (PointOnLineSegment(pt, pp2->pt, pp2->next->pt, UseFullInt64Range)) return true; pp2 = pp2->next; if (pp2 == pp) return false; } } //------------------------------------------------------------------------------ bool PointInPolygon(const IntPoint &pt, OutPt *pp, bool UseFullInt64Range) { OutPt *pp2 = pp; bool result = false; if (UseFullInt64Range) { do { if ((((pp2->pt.Y <= pt.Y) && (pt.Y < pp2->prev->pt.Y)) || ((pp2->prev->pt.Y <= pt.Y) && (pt.Y < pp2->pt.Y))) && Int128(pt.X - pp2->pt.X) < Int128Mul(pp2->prev->pt.X - pp2->pt.X, pt.Y - pp2->pt.Y) / Int128(pp2->prev->pt.Y - pp2->pt.Y)) result = !result; pp2 = pp2->next; } while (pp2 != pp); } else { do { if ((((pp2->pt.Y <= pt.Y) && (pt.Y < pp2->prev->pt.Y)) || ((pp2->prev->pt.Y <= pt.Y) && (pt.Y < pp2->pt.Y))) && (pt.X < (pp2->prev->pt.X - pp2->pt.X) * (pt.Y - pp2->pt.Y) / (pp2->prev->pt.Y - pp2->pt.Y) + pp2->pt.X )) result = !result; pp2 = pp2->next; } while (pp2 != pp); } return result; } //------------------------------------------------------------------------------ bool SlopesEqual(TEdge &e1, TEdge &e2, bool UseFullInt64Range) { if (UseFullInt64Range) return Int128Mul(e1.deltaY, e2.deltaX) == Int128Mul(e1.deltaX, e2.deltaY); else return e1.deltaY * e2.deltaX == e1.deltaX * e2.deltaY; } //------------------------------------------------------------------------------ bool SlopesEqual(const IntPoint pt1, const IntPoint pt2, const IntPoint pt3, bool UseFullInt64Range) { if (UseFullInt64Range) return Int128Mul(pt1.Y-pt2.Y, pt2.X-pt3.X) == Int128Mul(pt1.X-pt2.X, pt2.Y-pt3.Y); else return (pt1.Y-pt2.Y)*(pt2.X-pt3.X) == (pt1.X-pt2.X)*(pt2.Y-pt3.Y); } //------------------------------------------------------------------------------ bool SlopesEqual(const IntPoint pt1, const IntPoint pt2, const IntPoint pt3, const IntPoint pt4, bool UseFullInt64Range) { if (UseFullInt64Range) return Int128Mul(pt1.Y-pt2.Y, pt3.X-pt4.X) == Int128Mul(pt1.X-pt2.X, pt3.Y-pt4.Y); else return (pt1.Y-pt2.Y)*(pt3.X-pt4.X) == (pt1.X-pt2.X)*(pt3.Y-pt4.Y); } //------------------------------------------------------------------------------ double GetDx(const IntPoint pt1, const IntPoint pt2) { return (pt1.Y == pt2.Y) ? HORIZONTAL : (double)(pt2.X - pt1.X) / (pt2.Y - pt1.Y); } //--------------------------------------------------------------------------- void SetDx(TEdge &e) { e.deltaX = (e.xtop - e.xbot); e.deltaY = (e.ytop - e.ybot); if (e.deltaY == 0) e.dx = HORIZONTAL; else e.dx = (double)(e.deltaX) / e.deltaY; } //--------------------------------------------------------------------------- void SwapSides(TEdge &edge1, TEdge &edge2) { EdgeSide side = edge1.side; edge1.side = edge2.side; edge2.side = side; } //------------------------------------------------------------------------------ void SwapPolyIndexes(TEdge &edge1, TEdge &edge2) { int outIdx = edge1.outIdx; edge1.outIdx = edge2.outIdx; edge2.outIdx = outIdx; } //------------------------------------------------------------------------------ inline long64 Round(double val) { return (val < 0) ? static_cast(val - 0.5) : static_cast(val + 0.5); } //------------------------------------------------------------------------------ long64 TopX(TEdge &edge, const long64 currentY) { return ( currentY == edge.ytop ) ? edge.xtop : edge.xbot + Round(edge.dx *(currentY - edge.ybot)); } //------------------------------------------------------------------------------ bool IntersectPoint(TEdge &edge1, TEdge &edge2, IntPoint &ip, bool UseFullInt64Range) { double b1, b2; if (SlopesEqual(edge1, edge2, UseFullInt64Range)) { if (edge2.ybot > edge1.ybot) ip.Y = edge2.ybot; else ip.Y = edge1.ybot; return false; } else if (NEAR_ZERO(edge1.dx)) { ip.X = edge1.xbot; if (NEAR_EQUAL(edge2.dx, HORIZONTAL)) ip.Y = edge2.ybot; else { b2 = edge2.ybot - (edge2.xbot / edge2.dx); ip.Y = Round(ip.X / edge2.dx + b2); } } else if (NEAR_ZERO(edge2.dx)) { ip.X = edge2.xbot; if (NEAR_EQUAL(edge1.dx, HORIZONTAL)) ip.Y = edge1.ybot; else { b1 = edge1.ybot - (edge1.xbot / edge1.dx); ip.Y = Round(ip.X / edge1.dx + b1); } } else { b1 = edge1.xbot - edge1.ybot * edge1.dx; b2 = edge2.xbot - edge2.ybot * edge2.dx; double q = (b2-b1) / (edge1.dx - edge2.dx); ip.Y = Round(q); if (std::fabs(edge1.dx) < std::fabs(edge2.dx)) ip.X = Round(edge1.dx * q + b1); else ip.X = Round(edge2.dx * q + b2); } if (ip.Y < edge1.ytop || ip.Y < edge2.ytop) { if (edge1.ytop > edge2.ytop) { ip.X = edge1.xtop; ip.Y = edge1.ytop; return TopX(edge2, edge1.ytop) < edge1.xtop; } else { ip.X = edge2.xtop; ip.Y = edge2.ytop; return TopX(edge1, edge2.ytop) > edge2.xtop; } } else return true; } //------------------------------------------------------------------------------ void ReversePolyPtLinks(OutPt *pp) { if (!pp) return; OutPt *pp1, *pp2; pp1 = pp; do { pp2 = pp1->next; pp1->next = pp1->prev; pp1->prev = pp2; pp1 = pp2; } while( pp1 != pp ); } //------------------------------------------------------------------------------ void DisposeOutPts(OutPt*& pp) { if (pp == 0) return; pp->prev->next = 0; while( pp ) { OutPt *tmpPp = pp; pp = pp->next; delete tmpPp; } } //------------------------------------------------------------------------------ void InitEdge(TEdge *e, TEdge *eNext, TEdge *ePrev, const IntPoint &pt, PolyType polyType) { std::memset( e, 0, sizeof( TEdge )); e->next = eNext; e->prev = ePrev; e->xcurr = pt.X; e->ycurr = pt.Y; if (e->ycurr >= e->next->ycurr) { e->xbot = e->xcurr; e->ybot = e->ycurr; e->xtop = e->next->xcurr; e->ytop = e->next->ycurr; e->windDelta = 1; } else { e->xtop = e->xcurr; e->ytop = e->ycurr; e->xbot = e->next->xcurr; e->ybot = e->next->ycurr; e->windDelta = -1; } SetDx(*e); e->polyType = polyType; e->outIdx = -1; } //------------------------------------------------------------------------------ inline void SwapX(TEdge &e) { //swap horizontal edges' top and bottom x's so they follow the natural //progression of the bounds - ie so their xbots will align with the //adjoining lower edge. [Helpful in the ProcessHorizontal() method.] e.xcurr = e.xtop; e.xtop = e.xbot; e.xbot = e.xcurr; } //------------------------------------------------------------------------------ void SwapPoints(IntPoint &pt1, IntPoint &pt2) { IntPoint tmp = pt1; pt1 = pt2; pt2 = tmp; } //------------------------------------------------------------------------------ bool GetOverlapSegment(IntPoint pt1a, IntPoint pt1b, IntPoint pt2a, IntPoint pt2b, IntPoint &pt1, IntPoint &pt2) { //precondition: segments are colinear. if (Abs(pt1a.X - pt1b.X) > Abs(pt1a.Y - pt1b.Y)) { if (pt1a.X > pt1b.X) SwapPoints(pt1a, pt1b); if (pt2a.X > pt2b.X) SwapPoints(pt2a, pt2b); if (pt1a.X > pt2a.X) pt1 = pt1a; else pt1 = pt2a; if (pt1b.X < pt2b.X) pt2 = pt1b; else pt2 = pt2b; return pt1.X < pt2.X; } else { if (pt1a.Y < pt1b.Y) SwapPoints(pt1a, pt1b); if (pt2a.Y < pt2b.Y) SwapPoints(pt2a, pt2b); if (pt1a.Y < pt2a.Y) pt1 = pt1a; else pt1 = pt2a; if (pt1b.Y > pt2b.Y) pt2 = pt1b; else pt2 = pt2b; return pt1.Y > pt2.Y; } } //------------------------------------------------------------------------------ bool FirstIsBottomPt(const OutPt* btmPt1, const OutPt* btmPt2) { OutPt *p = btmPt1->prev; while (PointsEqual(p->pt, btmPt1->pt) && (p != btmPt1)) p = p->prev; double dx1p = std::fabs(GetDx(btmPt1->pt, p->pt)); p = btmPt1->next; while (PointsEqual(p->pt, btmPt1->pt) && (p != btmPt1)) p = p->next; double dx1n = std::fabs(GetDx(btmPt1->pt, p->pt)); p = btmPt2->prev; while (PointsEqual(p->pt, btmPt2->pt) && (p != btmPt2)) p = p->prev; double dx2p = std::fabs(GetDx(btmPt2->pt, p->pt)); p = btmPt2->next; while (PointsEqual(p->pt, btmPt2->pt) && (p != btmPt2)) p = p->next; double dx2n = std::fabs(GetDx(btmPt2->pt, p->pt)); return (dx1p >= dx2p && dx1p >= dx2n) || (dx1n >= dx2p && dx1n >= dx2n); } //------------------------------------------------------------------------------ OutPt* GetBottomPt(OutPt *pp) { OutPt* dups = 0; OutPt* p = pp->next; while (p != pp) { if (p->pt.Y > pp->pt.Y) { pp = p; dups = 0; } else if (p->pt.Y == pp->pt.Y && p->pt.X <= pp->pt.X) { if (p->pt.X < pp->pt.X) { dups = 0; pp = p; } else { if (p->next != pp && p->prev != pp) dups = p; } } p = p->next; } if (dups) { //there appears to be at least 2 vertices at bottomPt so ... while (dups != p) { if (!FirstIsBottomPt(p, dups)) pp = dups; dups = dups->next; while (!PointsEqual(dups->pt, pp->pt)) dups = dups->next; } } return pp; } //------------------------------------------------------------------------------ bool FindSegment(OutPt* &pp, bool UseFullInt64Range, IntPoint &pt1, IntPoint &pt2) { //outPt1 & outPt2 => the overlap segment (if the function returns true) if (!pp) return false; OutPt* pp2 = pp; IntPoint pt1a = pt1, pt2a = pt2; do { if (SlopesEqual(pt1a, pt2a, pp->pt, pp->prev->pt, UseFullInt64Range) && SlopesEqual(pt1a, pt2a, pp->pt, UseFullInt64Range) && GetOverlapSegment(pt1a, pt2a, pp->pt, pp->prev->pt, pt1, pt2)) return true; pp = pp->next; } while (pp != pp2); return false; } //------------------------------------------------------------------------------ bool Pt3IsBetweenPt1AndPt2(const IntPoint pt1, const IntPoint pt2, const IntPoint pt3) { if (PointsEqual(pt1, pt3) || PointsEqual(pt2, pt3)) return true; else if (pt1.X != pt2.X) return (pt1.X < pt3.X) == (pt3.X < pt2.X); else return (pt1.Y < pt3.Y) == (pt3.Y < pt2.Y); } //------------------------------------------------------------------------------ OutPt* InsertPolyPtBetween(OutPt* p1, OutPt* p2, const IntPoint pt) { if (p1 == p2) throw "JoinError"; OutPt* result = new OutPt; result->pt = pt; if (p2 == p1->next) { p1->next = result; p2->prev = result; result->next = p2; result->prev = p1; } else { p2->next = result; p1->prev = result; result->next = p1; result->prev = p2; } return result; } //------------------------------------------------------------------------------ // ClipperBase class methods ... //------------------------------------------------------------------------------ ClipperBase::ClipperBase() //constructor { m_MinimaList = 0; m_CurrentLM = 0; m_UseFullRange = true; } //------------------------------------------------------------------------------ ClipperBase::~ClipperBase() //destructor { Clear(); } //------------------------------------------------------------------------------ bool ClipperBase::AddPolygon( const Polygon &pg, PolyType polyType) { int len = (int)pg.size(); if (len < 3) return false; Polygon p(len); p[0] = pg[0]; int j = 0; long64 maxVal; if (m_UseFullRange) maxVal = hiRange; else maxVal = loRange; for (int i = 0; i < len; ++i) { if (Abs(pg[i].X) > maxVal || Abs(pg[i].Y) > maxVal) { if (Abs(pg[i].X) > hiRange || Abs(pg[i].Y) > hiRange) throw "Coordinate exceeds range bounds"; maxVal = hiRange; m_UseFullRange = true; } if (i == 0 || PointsEqual(p[j], pg[i])) continue; else if (j > 0 && SlopesEqual(p[j-1], p[j], pg[i], m_UseFullRange)) { if (PointsEqual(p[j-1], pg[i])) j--; } else j++; p[j] = pg[i]; } if (j < 2) return false; len = j+1; while (len > 2) { //nb: test for point equality before testing slopes ... if (PointsEqual(p[j], p[0])) j--; else if (PointsEqual(p[0], p[1]) || SlopesEqual(p[j], p[0], p[1], m_UseFullRange)) p[0] = p[j--]; else if (SlopesEqual(p[j-1], p[j], p[0], m_UseFullRange)) j--; else if (SlopesEqual(p[0], p[1], p[2], m_UseFullRange)) { for (int i = 2; i <= j; ++i) p[i-1] = p[i]; j--; } else break; len--; } if (len < 3) return false; //create a new edge array ... TEdge *edges = new TEdge [len]; m_edges.push_back(edges); //convert vertices to a double-linked-list of edges and initialize ... edges[0].xcurr = p[0].X; edges[0].ycurr = p[0].Y; InitEdge(&edges[len-1], &edges[0], &edges[len-2], p[len-1], polyType); for (int i = len-2; i > 0; --i) InitEdge(&edges[i], &edges[i+1], &edges[i-1], p[i], polyType); InitEdge(&edges[0], &edges[1], &edges[len-1], p[0], polyType); //reset xcurr & ycurr and find 'eHighest' (given the Y axis coordinates //increase downward so the 'highest' edge will have the smallest ytop) ... TEdge *e = &edges[0]; TEdge *eHighest = e; do { e->xcurr = e->xbot; e->ycurr = e->ybot; if (e->ytop < eHighest->ytop) eHighest = e; e = e->next; } while ( e != &edges[0]); //make sure eHighest is positioned so the following loop works safely ... if (eHighest->windDelta > 0) eHighest = eHighest->next; if (NEAR_EQUAL(eHighest->dx, HORIZONTAL)) eHighest = eHighest->next; //finally insert each local minima ... e = eHighest; do { e = AddBoundsToLML(e); } while( e != eHighest ); return true; } //------------------------------------------------------------------------------ void ClipperBase::InsertLocalMinima(LocalMinima *newLm) { if( ! m_MinimaList ) { m_MinimaList = newLm; } else if( newLm->Y >= m_MinimaList->Y ) { newLm->next = m_MinimaList; m_MinimaList = newLm; } else { LocalMinima* tmpLm = m_MinimaList; while( tmpLm->next && ( newLm->Y < tmpLm->next->Y ) ) tmpLm = tmpLm->next; newLm->next = tmpLm->next; tmpLm->next = newLm; } } //------------------------------------------------------------------------------ TEdge* ClipperBase::AddBoundsToLML(TEdge *e) { //Starting at the top of one bound we progress to the bottom where there's //a local minima. We then go to the top of the next bound. These two bounds //form the left and right (or right and left) bounds of the local minima. e->nextInLML = 0; e = e->next; for (;;) { if (NEAR_EQUAL(e->dx, HORIZONTAL)) { //nb: proceed through horizontals when approaching from their right, // but break on horizontal minima if approaching from their left. // This ensures 'local minima' are always on the left of horizontals. if (e->next->ytop < e->ytop && e->next->xbot > e->prev->xbot) break; if (e->xtop != e->prev->xbot) SwapX(*e); e->nextInLML = e->prev; } else if (e->ycurr == e->prev->ycurr) break; else e->nextInLML = e->prev; e = e->next; } //e and e.prev are now at a local minima ... LocalMinima* newLm = new LocalMinima; newLm->next = 0; newLm->Y = e->prev->ybot; if ( NEAR_EQUAL(e->dx, HORIZONTAL) ) //horizontal edges never start a left bound { if (e->xbot != e->prev->xbot) SwapX(*e); newLm->leftBound = e->prev; newLm->rightBound = e; } else if (e->dx < e->prev->dx) { newLm->leftBound = e->prev; newLm->rightBound = e; } else { newLm->leftBound = e; newLm->rightBound = e->prev; } newLm->leftBound->side = esLeft; newLm->rightBound->side = esRight; InsertLocalMinima( newLm ); for (;;) { if ( e->next->ytop == e->ytop && !NEAR_EQUAL(e->next->dx, HORIZONTAL) ) break; e->nextInLML = e->next; e = e->next; if ( NEAR_EQUAL(e->dx, HORIZONTAL) && e->xbot != e->prev->xtop) SwapX(*e); } return e->next; } //------------------------------------------------------------------------------ bool ClipperBase::AddPolygons(const Polygons &ppg, PolyType polyType) { bool result = false; for (Polygons::size_type i = 0; i < ppg.size(); ++i) if (AddPolygon(ppg[i], polyType)) result = true; return result; } //------------------------------------------------------------------------------ void ClipperBase::Clear() { DisposeLocalMinimaList(); for (EdgeList::size_type i = 0; i < m_edges.size(); ++i) delete [] m_edges[i]; m_edges.clear(); m_UseFullRange = false; } //------------------------------------------------------------------------------ void ClipperBase::Reset() { m_CurrentLM = m_MinimaList; if( !m_CurrentLM ) return; //ie nothing to process //reset all edges ... LocalMinima* lm = m_MinimaList; while( lm ) { TEdge* e = lm->leftBound; while( e ) { e->xcurr = e->xbot; e->ycurr = e->ybot; e->side = esLeft; e->outIdx = -1; e = e->nextInLML; } e = lm->rightBound; while( e ) { e->xcurr = e->xbot; e->ycurr = e->ybot; e->side = esRight; e->outIdx = -1; e = e->nextInLML; } lm = lm->next; } } //------------------------------------------------------------------------------ void ClipperBase::DisposeLocalMinimaList() { while( m_MinimaList ) { LocalMinima* tmpLm = m_MinimaList->next; delete m_MinimaList; m_MinimaList = tmpLm; } m_CurrentLM = 0; } //------------------------------------------------------------------------------ void ClipperBase::PopLocalMinima() { if( ! m_CurrentLM ) return; m_CurrentLM = m_CurrentLM->next; } //------------------------------------------------------------------------------ IntRect ClipperBase::GetBounds() { IntRect result; LocalMinima* lm = m_MinimaList; if (!lm) { result.left = result.top = result.right = result.bottom = 0; return result; } result.left = lm->leftBound->xbot; result.top = lm->leftBound->ybot; result.right = lm->leftBound->xbot; result.bottom = lm->leftBound->ybot; while (lm) { if (lm->leftBound->ybot > result.bottom) result.bottom = lm->leftBound->ybot; TEdge* e = lm->leftBound; for (;;) { TEdge* bottomE = e; while (e->nextInLML) { if (e->xbot < result.left) result.left = e->xbot; if (e->xbot > result.right) result.right = e->xbot; e = e->nextInLML; } if (e->xbot < result.left) result.left = e->xbot; if (e->xbot > result.right) result.right = e->xbot; if (e->xtop < result.left) result.left = e->xtop; if (e->xtop > result.right) result.right = e->xtop; if (e->ytop < result.top) result.top = e->ytop; if (bottomE == lm->leftBound) e = lm->rightBound; else break; } lm = lm->next; } return result; } //------------------------------------------------------------------------------ // TClipper methods ... //------------------------------------------------------------------------------ Clipper::Clipper() : ClipperBase() //constructor { m_Scanbeam = 0; m_ActiveEdges = 0; m_SortedEdges = 0; m_IntersectNodes = 0; m_ExecuteLocked = false; m_UseFullRange = false; m_ReverseOutput = false; m_ForceSimple = false; } //------------------------------------------------------------------------------ Clipper::~Clipper() //destructor { Clear(); DisposeScanbeamList(); } //------------------------------------------------------------------------------ void Clipper::Clear() { if (m_edges.empty()) return; //avoids problems with ClipperBase destructor DisposeAllPolyPts(); ClipperBase::Clear(); } //------------------------------------------------------------------------------ void Clipper::DisposeScanbeamList() { while ( m_Scanbeam ) { Scanbeam* sb2 = m_Scanbeam->next; delete m_Scanbeam; m_Scanbeam = sb2; } } //------------------------------------------------------------------------------ void Clipper::Reset() { ClipperBase::Reset(); m_Scanbeam = 0; m_ActiveEdges = 0; m_SortedEdges = 0; DisposeAllPolyPts(); LocalMinima* lm = m_MinimaList; while (lm) { InsertScanbeam(lm->Y); InsertScanbeam(lm->leftBound->ytop); lm = lm->next; } } //------------------------------------------------------------------------------ bool Clipper::Execute(ClipType clipType, Polygons &solution, PolyFillType subjFillType, PolyFillType clipFillType) { if( m_ExecuteLocked ) return false; m_ExecuteLocked = true; solution.resize(0); m_SubjFillType = subjFillType; m_ClipFillType = clipFillType; m_ClipType = clipType; m_UsingPolyTree = false; bool succeeded = ExecuteInternal(); if (succeeded) BuildResult(solution); m_ExecuteLocked = false; return succeeded; } //------------------------------------------------------------------------------ bool Clipper::Execute(ClipType clipType, PolyTree& polytree, PolyFillType subjFillType, PolyFillType clipFillType) { if( m_ExecuteLocked ) return false; m_ExecuteLocked = true; m_SubjFillType = subjFillType; m_ClipFillType = clipFillType; m_ClipType = clipType; m_UsingPolyTree = true; bool succeeded = ExecuteInternal(); if (succeeded) BuildResult2(polytree); m_ExecuteLocked = false; return succeeded; } //------------------------------------------------------------------------------ void Clipper::FixHoleLinkage(OutRec &outrec) { //skip OutRecs that (a) contain outermost polygons or //(b) already have the correct owner/child linkage ... if (!outrec.FirstLeft || (outrec.isHole != outrec.FirstLeft->isHole && outrec.FirstLeft->pts)) return; OutRec* orfl = outrec.FirstLeft; while (orfl && ((orfl->isHole == outrec.isHole) || !orfl->pts)) orfl = orfl->FirstLeft; outrec.FirstLeft = orfl; } //------------------------------------------------------------------------------ bool Clipper::ExecuteInternal() { bool succeeded; try { Reset(); if (!m_CurrentLM ) return true; long64 botY = PopScanbeam(); do { InsertLocalMinimaIntoAEL(botY); ClearHorzJoins(); ProcessHorizontals(); long64 topY = PopScanbeam(); succeeded = ProcessIntersections(botY, topY); if (!succeeded) break; ProcessEdgesAtTopOfScanbeam(topY); botY = topY; } while( m_Scanbeam ); } catch(...) { succeeded = false; } if (succeeded) { //tidy up output polygons and fix orientations where necessary ... for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); ++i) { OutRec *outRec = m_PolyOuts[i]; if (!outRec->pts) continue; FixupOutPolygon(*outRec); if (!outRec->pts) continue; if ((outRec->isHole ^ m_ReverseOutput) == (Area(*outRec, m_UseFullRange) > 0)) ReversePolyPtLinks(outRec->pts); } if (!m_Joins.empty()) JoinCommonEdges(); if (m_ForceSimple) DoSimplePolygons(); } ClearJoins(); ClearHorzJoins(); return succeeded; } //------------------------------------------------------------------------------ void Clipper::InsertScanbeam(const long64 Y) { if( !m_Scanbeam ) { m_Scanbeam = new Scanbeam; m_Scanbeam->next = 0; m_Scanbeam->Y = Y; } else if( Y > m_Scanbeam->Y ) { Scanbeam* newSb = new Scanbeam; newSb->Y = Y; newSb->next = m_Scanbeam; m_Scanbeam = newSb; } else { Scanbeam* sb2 = m_Scanbeam; while( sb2->next && ( Y <= sb2->next->Y ) ) sb2 = sb2->next; if( Y == sb2->Y ) return; //ie ignores duplicates Scanbeam* newSb = new Scanbeam; newSb->Y = Y; newSb->next = sb2->next; sb2->next = newSb; } } //------------------------------------------------------------------------------ long64 Clipper::PopScanbeam() { long64 Y = m_Scanbeam->Y; Scanbeam* sb2 = m_Scanbeam; m_Scanbeam = m_Scanbeam->next; delete sb2; return Y; } //------------------------------------------------------------------------------ void Clipper::DisposeAllPolyPts(){ for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); ++i) DisposeOutRec(i); m_PolyOuts.clear(); } //------------------------------------------------------------------------------ void Clipper::DisposeOutRec(PolyOutList::size_type index) { OutRec *outRec = m_PolyOuts[index]; if (outRec->pts) DisposeOutPts(outRec->pts); delete outRec; m_PolyOuts[index] = 0; } //------------------------------------------------------------------------------ void Clipper::SetWindingCount(TEdge &edge) { TEdge *e = edge.prevInAEL; //find the edge of the same polytype that immediately preceeds 'edge' in AEL while ( e && e->polyType != edge.polyType ) e = e->prevInAEL; if ( !e ) { edge.windCnt = edge.windDelta; edge.windCnt2 = 0; e = m_ActiveEdges; //ie get ready to calc windCnt2 } else if ( IsEvenOddFillType(edge) ) { //EvenOdd filling ... edge.windCnt = 1; edge.windCnt2 = e->windCnt2; e = e->nextInAEL; //ie get ready to calc windCnt2 } else { //nonZero, Positive or Negative filling ... if ( e->windCnt * e->windDelta < 0 ) { if (Abs(e->windCnt) > 1) { if (e->windDelta * edge.windDelta < 0) edge.windCnt = e->windCnt; else edge.windCnt = e->windCnt + edge.windDelta; } else edge.windCnt = e->windCnt + e->windDelta + edge.windDelta; } else { if ( Abs(e->windCnt) > 1 && e->windDelta * edge.windDelta < 0) edge.windCnt = e->windCnt; else if ( e->windCnt + edge.windDelta == 0 ) edge.windCnt = e->windCnt; else edge.windCnt = e->windCnt + edge.windDelta; } edge.windCnt2 = e->windCnt2; e = e->nextInAEL; //ie get ready to calc windCnt2 } //update windCnt2 ... if ( IsEvenOddAltFillType(edge) ) { //EvenOdd filling ... while ( e != &edge ) { edge.windCnt2 = (edge.windCnt2 == 0) ? 1 : 0; e = e->nextInAEL; } } else { //nonZero, Positive or Negative filling ... while ( e != &edge ) { edge.windCnt2 += e->windDelta; e = e->nextInAEL; } } } //------------------------------------------------------------------------------ bool Clipper::IsEvenOddFillType(const TEdge& edge) const { if (edge.polyType == ptSubject) return m_SubjFillType == pftEvenOdd; else return m_ClipFillType == pftEvenOdd; } //------------------------------------------------------------------------------ bool Clipper::IsEvenOddAltFillType(const TEdge& edge) const { if (edge.polyType == ptSubject) return m_ClipFillType == pftEvenOdd; else return m_SubjFillType == pftEvenOdd; } //------------------------------------------------------------------------------ bool Clipper::IsContributing(const TEdge& edge) const { PolyFillType pft, pft2; if (edge.polyType == ptSubject) { pft = m_SubjFillType; pft2 = m_ClipFillType; } else { pft = m_ClipFillType; pft2 = m_SubjFillType; } switch(pft) { case pftEvenOdd: case pftNonZero: if (Abs(edge.windCnt) != 1) return false; break; case pftPositive: if (edge.windCnt != 1) return false; break; default: //pftNegative if (edge.windCnt != -1) return false; } switch(m_ClipType) { case ctIntersection: switch(pft2) { case pftEvenOdd: case pftNonZero: return (edge.windCnt2 != 0); case pftPositive: return (edge.windCnt2 > 0); default: return (edge.windCnt2 < 0); } case ctUnion: switch(pft2) { case pftEvenOdd: case pftNonZero: return (edge.windCnt2 == 0); case pftPositive: return (edge.windCnt2 <= 0); default: return (edge.windCnt2 >= 0); } case ctDifference: if (edge.polyType == ptSubject) switch(pft2) { case pftEvenOdd: case pftNonZero: return (edge.windCnt2 == 0); case pftPositive: return (edge.windCnt2 <= 0); default: return (edge.windCnt2 >= 0); } else switch(pft2) { case pftEvenOdd: case pftNonZero: return (edge.windCnt2 != 0); case pftPositive: return (edge.windCnt2 > 0); default: return (edge.windCnt2 < 0); } default: return true; } } //------------------------------------------------------------------------------ void Clipper::AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &pt) { TEdge *e, *prevE; if( NEAR_EQUAL(e2->dx, HORIZONTAL) || ( e1->dx > e2->dx ) ) { AddOutPt( e1, pt ); e2->outIdx = e1->outIdx; e1->side = esLeft; e2->side = esRight; e = e1; if (e->prevInAEL == e2) prevE = e2->prevInAEL; else prevE = e->prevInAEL; } else { AddOutPt( e2, pt ); e1->outIdx = e2->outIdx; e1->side = esRight; e2->side = esLeft; e = e2; if (e->prevInAEL == e1) prevE = e1->prevInAEL; else prevE = e->prevInAEL; } if (prevE && prevE->outIdx >= 0 && (TopX(*prevE, pt.Y) == TopX(*e, pt.Y)) && SlopesEqual(*e, *prevE, m_UseFullRange)) AddJoin(e, prevE, -1, -1); } //------------------------------------------------------------------------------ void Clipper::AddLocalMaxPoly(TEdge *e1, TEdge *e2, const IntPoint &pt) { AddOutPt( e1, pt ); if( e1->outIdx == e2->outIdx ) { e1->outIdx = -1; e2->outIdx = -1; } else if (e1->outIdx < e2->outIdx) AppendPolygon(e1, e2); else AppendPolygon(e2, e1); } //------------------------------------------------------------------------------ void Clipper::AddEdgeToSEL(TEdge *edge) { //SEL pointers in PEdge are reused to build a list of horizontal edges. //However, we don't need to worry about order with horizontal edge processing. if( !m_SortedEdges ) { m_SortedEdges = edge; edge->prevInSEL = 0; edge->nextInSEL = 0; } else { edge->nextInSEL = m_SortedEdges; edge->prevInSEL = 0; m_SortedEdges->prevInSEL = edge; m_SortedEdges = edge; } } //------------------------------------------------------------------------------ void Clipper::CopyAELToSEL() { TEdge* e = m_ActiveEdges; m_SortedEdges = e; while ( e ) { e->prevInSEL = e->prevInAEL; e->nextInSEL = e->nextInAEL; e = e->nextInAEL; } } //------------------------------------------------------------------------------ void Clipper::AddJoin(TEdge *e1, TEdge *e2, int e1OutIdx, int e2OutIdx) { JoinRec* jr = new JoinRec; if (e1OutIdx >= 0) jr->poly1Idx = e1OutIdx; else jr->poly1Idx = e1->outIdx; jr->pt1a = IntPoint(e1->xcurr, e1->ycurr); jr->pt1b = IntPoint(e1->xtop, e1->ytop); if (e2OutIdx >= 0) jr->poly2Idx = e2OutIdx; else jr->poly2Idx = e2->outIdx; jr->pt2a = IntPoint(e2->xcurr, e2->ycurr); jr->pt2b = IntPoint(e2->xtop, e2->ytop); m_Joins.push_back(jr); } //------------------------------------------------------------------------------ void Clipper::ClearJoins() { for (JoinList::size_type i = 0; i < m_Joins.size(); i++) delete m_Joins[i]; m_Joins.resize(0); } //------------------------------------------------------------------------------ void Clipper::AddHorzJoin(TEdge *e, int idx) { HorzJoinRec* hj = new HorzJoinRec; hj->edge = e; hj->savedIdx = idx; m_HorizJoins.push_back(hj); } //------------------------------------------------------------------------------ void Clipper::ClearHorzJoins() { for (HorzJoinList::size_type i = 0; i < m_HorizJoins.size(); i++) delete m_HorizJoins[i]; m_HorizJoins.resize(0); } //------------------------------------------------------------------------------ void Clipper::InsertLocalMinimaIntoAEL(const long64 botY) { while( m_CurrentLM && ( m_CurrentLM->Y == botY ) ) { TEdge* lb = m_CurrentLM->leftBound; TEdge* rb = m_CurrentLM->rightBound; InsertEdgeIntoAEL( lb ); InsertScanbeam( lb->ytop ); InsertEdgeIntoAEL( rb ); if (IsEvenOddFillType(*lb)) { lb->windDelta = 1; rb->windDelta = 1; } else { rb->windDelta = -lb->windDelta; } SetWindingCount( *lb ); rb->windCnt = lb->windCnt; rb->windCnt2 = lb->windCnt2; if( NEAR_EQUAL(rb->dx, HORIZONTAL) ) { //nb: only rightbounds can have a horizontal bottom edge AddEdgeToSEL( rb ); InsertScanbeam( rb->nextInLML->ytop ); } else InsertScanbeam( rb->ytop ); if( IsContributing(*lb) ) AddLocalMinPoly( lb, rb, IntPoint(lb->xcurr, m_CurrentLM->Y) ); //if any output polygons share an edge, they'll need joining later ... if (rb->outIdx >= 0 && NEAR_EQUAL(rb->dx, HORIZONTAL)) { for (HorzJoinList::size_type i = 0; i < m_HorizJoins.size(); ++i) { IntPoint pt, pt2; //returned by GetOverlapSegment() but unused here. HorzJoinRec* hj = m_HorizJoins[i]; //if horizontals rb and hj.edge overlap, flag for joining later ... if (GetOverlapSegment(IntPoint(hj->edge->xbot, hj->edge->ybot), IntPoint(hj->edge->xtop, hj->edge->ytop), IntPoint(rb->xbot, rb->ybot), IntPoint(rb->xtop, rb->ytop), pt, pt2)) AddJoin(hj->edge, rb, hj->savedIdx); } } if( lb->nextInAEL != rb ) { if (rb->outIdx >= 0 && rb->prevInAEL->outIdx >= 0 && SlopesEqual(*rb->prevInAEL, *rb, m_UseFullRange)) AddJoin(rb, rb->prevInAEL); TEdge* e = lb->nextInAEL; IntPoint pt = IntPoint(lb->xcurr, lb->ycurr); while( e != rb ) { if(!e) throw clipperException("InsertLocalMinimaIntoAEL: missing rightbound!"); //nb: For calculating winding counts etc, IntersectEdges() assumes //that param1 will be to the right of param2 ABOVE the intersection ... IntersectEdges( rb , e , pt , ipNone); //order important here e = e->nextInAEL; } } PopLocalMinima(); } } //------------------------------------------------------------------------------ void Clipper::DeleteFromAEL(TEdge *e) { TEdge* AelPrev = e->prevInAEL; TEdge* AelNext = e->nextInAEL; if( !AelPrev && !AelNext && (e != m_ActiveEdges) ) return; //already deleted if( AelPrev ) AelPrev->nextInAEL = AelNext; else m_ActiveEdges = AelNext; if( AelNext ) AelNext->prevInAEL = AelPrev; e->nextInAEL = 0; e->prevInAEL = 0; } //------------------------------------------------------------------------------ void Clipper::DeleteFromSEL(TEdge *e) { TEdge* SelPrev = e->prevInSEL; TEdge* SelNext = e->nextInSEL; if( !SelPrev && !SelNext && (e != m_SortedEdges) ) return; //already deleted if( SelPrev ) SelPrev->nextInSEL = SelNext; else m_SortedEdges = SelNext; if( SelNext ) SelNext->prevInSEL = SelPrev; e->nextInSEL = 0; e->prevInSEL = 0; } //------------------------------------------------------------------------------ void Clipper::IntersectEdges(TEdge *e1, TEdge *e2, const IntPoint &pt, const IntersectProtects protects) { //e1 will be to the left of e2 BELOW the intersection. Therefore e1 is before //e2 in AEL except when e1 is being inserted at the intersection point ... bool e1stops = !(ipLeft & protects) && !e1->nextInLML && e1->xtop == pt.X && e1->ytop == pt.Y; bool e2stops = !(ipRight & protects) && !e2->nextInLML && e2->xtop == pt.X && e2->ytop == pt.Y; bool e1Contributing = ( e1->outIdx >= 0 ); bool e2contributing = ( e2->outIdx >= 0 ); //update winding counts... //assumes that e1 will be to the right of e2 ABOVE the intersection if ( e1->polyType == e2->polyType ) { if ( IsEvenOddFillType( *e1) ) { int oldE1WindCnt = e1->windCnt; e1->windCnt = e2->windCnt; e2->windCnt = oldE1WindCnt; } else { if (e1->windCnt + e2->windDelta == 0 ) e1->windCnt = -e1->windCnt; else e1->windCnt += e2->windDelta; if ( e2->windCnt - e1->windDelta == 0 ) e2->windCnt = -e2->windCnt; else e2->windCnt -= e1->windDelta; } } else { if (!IsEvenOddFillType(*e2)) e1->windCnt2 += e2->windDelta; else e1->windCnt2 = ( e1->windCnt2 == 0 ) ? 1 : 0; if (!IsEvenOddFillType(*e1)) e2->windCnt2 -= e1->windDelta; else e2->windCnt2 = ( e2->windCnt2 == 0 ) ? 1 : 0; } PolyFillType e1FillType, e2FillType, e1FillType2, e2FillType2; if (e1->polyType == ptSubject) { e1FillType = m_SubjFillType; e1FillType2 = m_ClipFillType; } else { e1FillType = m_ClipFillType; e1FillType2 = m_SubjFillType; } if (e2->polyType == ptSubject) { e2FillType = m_SubjFillType; e2FillType2 = m_ClipFillType; } else { e2FillType = m_ClipFillType; e2FillType2 = m_SubjFillType; } long64 e1Wc, e2Wc; switch (e1FillType) { case pftPositive: e1Wc = e1->windCnt; break; case pftNegative: e1Wc = -e1->windCnt; break; default: e1Wc = Abs(e1->windCnt); } switch(e2FillType) { case pftPositive: e2Wc = e2->windCnt; break; case pftNegative: e2Wc = -e2->windCnt; break; default: e2Wc = Abs(e2->windCnt); } if ( e1Contributing && e2contributing ) { if ( e1stops || e2stops || (e1Wc != 0 && e1Wc != 1) || (e2Wc != 0 && e2Wc != 1) || (e1->polyType != e2->polyType && m_ClipType != ctXor) ) AddLocalMaxPoly(e1, e2, pt); else { AddOutPt(e1, pt); AddOutPt(e2, pt); SwapSides( *e1 , *e2 ); SwapPolyIndexes( *e1 , *e2 ); } } else if ( e1Contributing ) { if (e2Wc == 0 || e2Wc == 1) { AddOutPt(e1, pt); SwapSides(*e1, *e2); SwapPolyIndexes(*e1, *e2); } } else if ( e2contributing ) { if (e1Wc == 0 || e1Wc == 1) { AddOutPt(e2, pt); SwapSides(*e1, *e2); SwapPolyIndexes(*e1, *e2); } } else if ( (e1Wc == 0 || e1Wc == 1) && (e2Wc == 0 || e2Wc == 1) && !e1stops && !e2stops ) { //neither edge is currently contributing ... long64 e1Wc2, e2Wc2; switch (e1FillType2) { case pftPositive: e1Wc2 = e1->windCnt2; break; case pftNegative : e1Wc2 = -e1->windCnt2; break; default: e1Wc2 = Abs(e1->windCnt2); } switch (e2FillType2) { case pftPositive: e2Wc2 = e2->windCnt2; break; case pftNegative: e2Wc2 = -e2->windCnt2; break; default: e2Wc2 = Abs(e2->windCnt2); } if (e1->polyType != e2->polyType) AddLocalMinPoly(e1, e2, pt); else if (e1Wc == 1 && e2Wc == 1) switch( m_ClipType ) { case ctIntersection: if (e1Wc2 > 0 && e2Wc2 > 0) AddLocalMinPoly(e1, e2, pt); break; case ctUnion: if ( e1Wc2 <= 0 && e2Wc2 <= 0 ) AddLocalMinPoly(e1, e2, pt); break; case ctDifference: if (((e1->polyType == ptClip) && (e1Wc2 > 0) && (e2Wc2 > 0)) || ((e1->polyType == ptSubject) && (e1Wc2 <= 0) && (e2Wc2 <= 0))) AddLocalMinPoly(e1, e2, pt); break; case ctXor: AddLocalMinPoly(e1, e2, pt); } else SwapSides( *e1, *e2 ); } if( (e1stops != e2stops) && ( (e1stops && (e1->outIdx >= 0)) || (e2stops && (e2->outIdx >= 0)) ) ) { SwapSides( *e1, *e2 ); SwapPolyIndexes( *e1, *e2 ); } //finally, delete any non-contributing maxima edges ... if( e1stops ) DeleteFromAEL( e1 ); if( e2stops ) DeleteFromAEL( e2 ); } //------------------------------------------------------------------------------ void Clipper::SetHoleState(TEdge *e, OutRec *outrec) { bool isHole = false; TEdge *e2 = e->prevInAEL; while (e2) { if (e2->outIdx >= 0) { isHole = !isHole; if (! outrec->FirstLeft) outrec->FirstLeft = m_PolyOuts[e2->outIdx]; } e2 = e2->prevInAEL; } if (isHole) outrec->isHole = true; } //------------------------------------------------------------------------------ OutRec* GetLowermostRec(OutRec *outRec1, OutRec *outRec2) { //work out which polygon fragment has the correct hole state ... if (!outRec1->bottomPt) outRec1->bottomPt = GetBottomPt(outRec1->pts); if (!outRec2->bottomPt) outRec2->bottomPt = GetBottomPt(outRec2->pts); OutPt *outPt1 = outRec1->bottomPt; OutPt *outPt2 = outRec2->bottomPt; if (outPt1->pt.Y > outPt2->pt.Y) return outRec1; else if (outPt1->pt.Y < outPt2->pt.Y) return outRec2; else if (outPt1->pt.X < outPt2->pt.X) return outRec1; else if (outPt1->pt.X > outPt2->pt.X) return outRec2; else if (outPt1->next == outPt1) return outRec2; else if (outPt2->next == outPt2) return outRec1; else if (FirstIsBottomPt(outPt1, outPt2)) return outRec1; else return outRec2; } //------------------------------------------------------------------------------ bool Param1RightOfParam2(OutRec* outRec1, OutRec* outRec2) { do { outRec1 = outRec1->FirstLeft; if (outRec1 == outRec2) return true; } while (outRec1); return false; } //------------------------------------------------------------------------------ OutRec* Clipper::GetOutRec(int idx) { OutRec* outrec = m_PolyOuts[idx]; while (outrec != m_PolyOuts[outrec->idx]) outrec = m_PolyOuts[outrec->idx]; return outrec; } //------------------------------------------------------------------------------ void Clipper::AppendPolygon(TEdge *e1, TEdge *e2) { //get the start and ends of both output polygons ... OutRec *outRec1 = m_PolyOuts[e1->outIdx]; OutRec *outRec2 = m_PolyOuts[e2->outIdx]; OutRec *holeStateRec; if (Param1RightOfParam2(outRec1, outRec2)) holeStateRec = outRec2; else if (Param1RightOfParam2(outRec2, outRec1)) holeStateRec = outRec1; else holeStateRec = GetLowermostRec(outRec1, outRec2); OutPt* p1_lft = outRec1->pts; OutPt* p1_rt = p1_lft->prev; OutPt* p2_lft = outRec2->pts; OutPt* p2_rt = p2_lft->prev; EdgeSide side; //join e2 poly onto e1 poly and delete pointers to e2 ... if( e1->side == esLeft ) { if( e2->side == esLeft ) { //z y x a b c ReversePolyPtLinks(p2_lft); p2_lft->next = p1_lft; p1_lft->prev = p2_lft; p1_rt->next = p2_rt; p2_rt->prev = p1_rt; outRec1->pts = p2_rt; } else { //x y z a b c p2_rt->next = p1_lft; p1_lft->prev = p2_rt; p2_lft->prev = p1_rt; p1_rt->next = p2_lft; outRec1->pts = p2_lft; } side = esLeft; } else { if( e2->side == esRight ) { //a b c z y x ReversePolyPtLinks(p2_lft); p1_rt->next = p2_rt; p2_rt->prev = p1_rt; p2_lft->next = p1_lft; p1_lft->prev = p2_lft; } else { //a b c x y z p1_rt->next = p2_lft; p2_lft->prev = p1_rt; p1_lft->prev = p2_rt; p2_rt->next = p1_lft; } side = esRight; } outRec1->bottomPt = 0; if (holeStateRec == outRec2) { if (outRec2->FirstLeft != outRec1) outRec1->FirstLeft = outRec2->FirstLeft; outRec1->isHole = outRec2->isHole; } outRec2->pts = 0; outRec2->bottomPt = 0; outRec2->FirstLeft = outRec1; int OKIdx = e1->outIdx; int ObsoleteIdx = e2->outIdx; e1->outIdx = -1; //nb: safe because we only get here via AddLocalMaxPoly e2->outIdx = -1; TEdge* e = m_ActiveEdges; while( e ) { if( e->outIdx == ObsoleteIdx ) { e->outIdx = OKIdx; e->side = side; break; } e = e->nextInAEL; } outRec2->idx = outRec1->idx; } //------------------------------------------------------------------------------ OutRec* Clipper::CreateOutRec() { OutRec* result = new OutRec; result->isHole = false; result->FirstLeft = 0; result->pts = 0; result->bottomPt = 0; result->polyNode = 0; m_PolyOuts.push_back(result); result->idx = (int)m_PolyOuts.size()-1; return result; } //------------------------------------------------------------------------------ void Clipper::AddOutPt(TEdge *e, const IntPoint &pt) { bool ToFront = (e->side == esLeft); if( e->outIdx < 0 ) { OutRec *outRec = CreateOutRec(); e->outIdx = outRec->idx; OutPt* op = new OutPt; outRec->pts = op; op->pt = pt; op->idx = outRec->idx; op->next = op; op->prev = op; SetHoleState(e, outRec); } else { OutRec *outRec = m_PolyOuts[e->outIdx]; OutPt* op = outRec->pts; if ((ToFront && PointsEqual(pt, op->pt)) || (!ToFront && PointsEqual(pt, op->prev->pt))) return; OutPt* op2 = new OutPt; op2->pt = pt; op2->idx = outRec->idx; op2->next = op; op2->prev = op->prev; op2->prev->next = op2; op->prev = op2; if (ToFront) outRec->pts = op2; } } //------------------------------------------------------------------------------ void Clipper::ProcessHorizontals() { TEdge* horzEdge = m_SortedEdges; while( horzEdge ) { DeleteFromSEL( horzEdge ); ProcessHorizontal( horzEdge ); horzEdge = m_SortedEdges; } } //------------------------------------------------------------------------------ bool Clipper::IsTopHorz(const long64 XPos) { TEdge* e = m_SortedEdges; while( e ) { if( ( XPos >= std::min(e->xcurr, e->xtop) ) && ( XPos <= std::max(e->xcurr, e->xtop) ) ) return false; e = e->nextInSEL; } return true; } //------------------------------------------------------------------------------ inline bool IsMinima(TEdge *e) { return e && (e->prev->nextInLML != e) && (e->next->nextInLML != e); } //------------------------------------------------------------------------------ inline bool IsMaxima(TEdge *e, const long64 Y) { return e && e->ytop == Y && !e->nextInLML; } //------------------------------------------------------------------------------ inline bool IsIntermediate(TEdge *e, const long64 Y) { return e->ytop == Y && e->nextInLML; } //------------------------------------------------------------------------------ TEdge *GetMaximaPair(TEdge *e) { if( !IsMaxima(e->next, e->ytop) || e->next->xtop != e->xtop ) return e->prev; else return e->next; } //------------------------------------------------------------------------------ void Clipper::SwapPositionsInAEL(TEdge *edge1, TEdge *edge2) { if( edge1->nextInAEL == edge2 ) { TEdge* next = edge2->nextInAEL; if( next ) next->prevInAEL = edge1; TEdge* prev = edge1->prevInAEL; if( prev ) prev->nextInAEL = edge2; edge2->prevInAEL = prev; edge2->nextInAEL = edge1; edge1->prevInAEL = edge2; edge1->nextInAEL = next; } else if( edge2->nextInAEL == edge1 ) { TEdge* next = edge1->nextInAEL; if( next ) next->prevInAEL = edge2; TEdge* prev = edge2->prevInAEL; if( prev ) prev->nextInAEL = edge1; edge1->prevInAEL = prev; edge1->nextInAEL = edge2; edge2->prevInAEL = edge1; edge2->nextInAEL = next; } else { TEdge* next = edge1->nextInAEL; TEdge* prev = edge1->prevInAEL; edge1->nextInAEL = edge2->nextInAEL; if( edge1->nextInAEL ) edge1->nextInAEL->prevInAEL = edge1; edge1->prevInAEL = edge2->prevInAEL; if( edge1->prevInAEL ) edge1->prevInAEL->nextInAEL = edge1; edge2->nextInAEL = next; if( edge2->nextInAEL ) edge2->nextInAEL->prevInAEL = edge2; edge2->prevInAEL = prev; if( edge2->prevInAEL ) edge2->prevInAEL->nextInAEL = edge2; } if( !edge1->prevInAEL ) m_ActiveEdges = edge1; else if( !edge2->prevInAEL ) m_ActiveEdges = edge2; } //------------------------------------------------------------------------------ void Clipper::SwapPositionsInSEL(TEdge *edge1, TEdge *edge2) { if( !( edge1->nextInSEL ) && !( edge1->prevInSEL ) ) return; if( !( edge2->nextInSEL ) && !( edge2->prevInSEL ) ) return; if( edge1->nextInSEL == edge2 ) { TEdge* next = edge2->nextInSEL; if( next ) next->prevInSEL = edge1; TEdge* prev = edge1->prevInSEL; if( prev ) prev->nextInSEL = edge2; edge2->prevInSEL = prev; edge2->nextInSEL = edge1; edge1->prevInSEL = edge2; edge1->nextInSEL = next; } else if( edge2->nextInSEL == edge1 ) { TEdge* next = edge1->nextInSEL; if( next ) next->prevInSEL = edge2; TEdge* prev = edge2->prevInSEL; if( prev ) prev->nextInSEL = edge1; edge1->prevInSEL = prev; edge1->nextInSEL = edge2; edge2->prevInSEL = edge1; edge2->nextInSEL = next; } else { TEdge* next = edge1->nextInSEL; TEdge* prev = edge1->prevInSEL; edge1->nextInSEL = edge2->nextInSEL; if( edge1->nextInSEL ) edge1->nextInSEL->prevInSEL = edge1; edge1->prevInSEL = edge2->prevInSEL; if( edge1->prevInSEL ) edge1->prevInSEL->nextInSEL = edge1; edge2->nextInSEL = next; if( edge2->nextInSEL ) edge2->nextInSEL->prevInSEL = edge2; edge2->prevInSEL = prev; if( edge2->prevInSEL ) edge2->prevInSEL->nextInSEL = edge2; } if( !edge1->prevInSEL ) m_SortedEdges = edge1; else if( !edge2->prevInSEL ) m_SortedEdges = edge2; } //------------------------------------------------------------------------------ TEdge* GetNextInAEL(TEdge *e, Direction dir) { return dir == dLeftToRight ? e->nextInAEL : e->prevInAEL; } //------------------------------------------------------------------------------ void Clipper::ProcessHorizontal(TEdge *horzEdge) { Direction dir; long64 horzLeft, horzRight; if( horzEdge->xcurr < horzEdge->xtop ) { horzLeft = horzEdge->xcurr; horzRight = horzEdge->xtop; dir = dLeftToRight; } else { horzLeft = horzEdge->xtop; horzRight = horzEdge->xcurr; dir = dRightToLeft; } TEdge* eMaxPair; if( horzEdge->nextInLML ) eMaxPair = 0; else eMaxPair = GetMaximaPair(horzEdge); TEdge* e = GetNextInAEL( horzEdge , dir ); while( e ) { if ( e->xcurr == horzEdge->xtop && !eMaxPair ) { if (SlopesEqual(*e, *horzEdge->nextInLML, m_UseFullRange)) { //if output polygons share an edge, they'll need joining later ... if (horzEdge->outIdx >= 0 && e->outIdx >= 0) AddJoin(horzEdge->nextInLML, e, horzEdge->outIdx); break; //we've reached the end of the horizontal line } else if (e->dx < horzEdge->nextInLML->dx) //we really have got to the end of the intermediate horz edge so quit. //nb: More -ve slopes follow more +ve slopes ABOVE the horizontal. break; } TEdge* eNext = GetNextInAEL( e, dir ); if (eMaxPair || ((dir == dLeftToRight) && (e->xcurr < horzRight)) || ((dir == dRightToLeft) && (e->xcurr > horzLeft))) { //so far we're still in range of the horizontal edge if( e == eMaxPair ) { //horzEdge is evidently a maxima horizontal and we've arrived at its end. if (dir == dLeftToRight) IntersectEdges(horzEdge, e, IntPoint(e->xcurr, horzEdge->ycurr), ipNone); else IntersectEdges(e, horzEdge, IntPoint(e->xcurr, horzEdge->ycurr), ipNone); if (eMaxPair->outIdx >= 0) throw clipperException("ProcessHorizontal error"); return; } else if( NEAR_EQUAL(e->dx, HORIZONTAL) && !IsMinima(e) && !(e->xcurr > e->xtop) ) { //An overlapping horizontal edge. Overlapping horizontal edges are //processed as if layered with the current horizontal edge (horizEdge) //being infinitesimally lower that the next (e). Therfore, we //intersect with e only if e.xcurr is within the bounds of horzEdge ... if( dir == dLeftToRight ) IntersectEdges( horzEdge , e, IntPoint(e->xcurr, horzEdge->ycurr), (IsTopHorz( e->xcurr ))? ipLeft : ipBoth ); else IntersectEdges( e, horzEdge, IntPoint(e->xcurr, horzEdge->ycurr), (IsTopHorz( e->xcurr ))? ipRight : ipBoth ); } else if( dir == dLeftToRight ) { IntersectEdges( horzEdge, e, IntPoint(e->xcurr, horzEdge->ycurr), (IsTopHorz( e->xcurr ))? ipLeft : ipBoth ); } else { IntersectEdges( e, horzEdge, IntPoint(e->xcurr, horzEdge->ycurr), (IsTopHorz( e->xcurr ))? ipRight : ipBoth ); } SwapPositionsInAEL( horzEdge, e ); } else if( (dir == dLeftToRight && e->xcurr >= horzRight) || (dir == dRightToLeft && e->xcurr <= horzLeft) ) break; e = eNext; } //end while if( horzEdge->nextInLML ) { if( horzEdge->outIdx >= 0 ) AddOutPt( horzEdge, IntPoint(horzEdge->xtop, horzEdge->ytop)); UpdateEdgeIntoAEL( horzEdge ); } else { if ( horzEdge->outIdx >= 0 ) IntersectEdges( horzEdge, eMaxPair, IntPoint(horzEdge->xtop, horzEdge->ycurr), ipBoth); if (eMaxPair->outIdx >= 0) throw clipperException("ProcessHorizontal error"); DeleteFromAEL(eMaxPair); DeleteFromAEL(horzEdge); } } //------------------------------------------------------------------------------ void Clipper::UpdateEdgeIntoAEL(TEdge *&e) { if( !e->nextInLML ) throw clipperException("UpdateEdgeIntoAEL: invalid call"); TEdge* AelPrev = e->prevInAEL; TEdge* AelNext = e->nextInAEL; e->nextInLML->outIdx = e->outIdx; if( AelPrev ) AelPrev->nextInAEL = e->nextInLML; else m_ActiveEdges = e->nextInLML; if( AelNext ) AelNext->prevInAEL = e->nextInLML; e->nextInLML->side = e->side; e->nextInLML->windDelta = e->windDelta; e->nextInLML->windCnt = e->windCnt; e->nextInLML->windCnt2 = e->windCnt2; e = e->nextInLML; e->prevInAEL = AelPrev; e->nextInAEL = AelNext; if( !NEAR_EQUAL(e->dx, HORIZONTAL) ) InsertScanbeam( e->ytop ); } //------------------------------------------------------------------------------ bool Clipper::ProcessIntersections(const long64 botY, const long64 topY) { if( !m_ActiveEdges ) return true; try { BuildIntersectList(botY, topY); if (!m_IntersectNodes) return true; if (!m_IntersectNodes->next || FixupIntersectionOrder()) ProcessIntersectList(); else return false; } catch(...) { m_SortedEdges = 0; DisposeIntersectNodes(); throw clipperException("ProcessIntersections error"); } m_SortedEdges = 0; return true; } //------------------------------------------------------------------------------ void Clipper::DisposeIntersectNodes() { while ( m_IntersectNodes ) { IntersectNode* iNode = m_IntersectNodes->next; delete m_IntersectNodes; m_IntersectNodes = iNode; } } //------------------------------------------------------------------------------ void Clipper::BuildIntersectList(const long64 botY, const long64 topY) { if ( !m_ActiveEdges ) return; //prepare for sorting ... TEdge* e = m_ActiveEdges; m_SortedEdges = e; while( e ) { e->prevInSEL = e->prevInAEL; e->nextInSEL = e->nextInAEL; e->xcurr = TopX( *e, topY ); e = e->nextInAEL; } //bubblesort ... bool isModified = true; while( isModified && m_SortedEdges ) { isModified = false; e = m_SortedEdges; while( e->nextInSEL ) { TEdge *eNext = e->nextInSEL; IntPoint pt; if(e->xcurr > eNext->xcurr) { if (!IntersectPoint(*e, *eNext, pt, m_UseFullRange) && e->xcurr > eNext->xcurr +1) throw clipperException("Intersection error"); if (pt.Y > botY) { pt.Y = botY; pt.X = TopX(*e, pt.Y); } AddIntersectNode( e, eNext, pt ); SwapPositionsInSEL(e, eNext); isModified = true; } else e = eNext; } if( e->prevInSEL ) e->prevInSEL->nextInSEL = 0; else break; } m_SortedEdges = 0; } //------------------------------------------------------------------------------ void Clipper::AddIntersectNode(TEdge *e1, TEdge *e2, const IntPoint &pt) { IntersectNode* newNode = new IntersectNode; newNode->edge1 = e1; newNode->edge2 = e2; newNode->pt = pt; newNode->next = 0; if( !m_IntersectNodes ) m_IntersectNodes = newNode; else if(newNode->pt.Y > m_IntersectNodes->pt.Y ) { newNode->next = m_IntersectNodes; m_IntersectNodes = newNode; } else { IntersectNode* iNode = m_IntersectNodes; while(iNode->next && newNode->pt.Y <= iNode->next->pt.Y) iNode = iNode->next; newNode->next = iNode->next; iNode->next = newNode; } } //------------------------------------------------------------------------------ void Clipper::ProcessIntersectList() { while( m_IntersectNodes ) { IntersectNode* iNode = m_IntersectNodes->next; { IntersectEdges( m_IntersectNodes->edge1 , m_IntersectNodes->edge2 , m_IntersectNodes->pt, ipBoth ); SwapPositionsInAEL( m_IntersectNodes->edge1 , m_IntersectNodes->edge2 ); } delete m_IntersectNodes; m_IntersectNodes = iNode; } } //------------------------------------------------------------------------------ void Clipper::DoMaxima(TEdge *e, long64 topY) { TEdge* eMaxPair = GetMaximaPair(e); long64 X = e->xtop; TEdge* eNext = e->nextInAEL; while( eNext != eMaxPair ) { if (!eNext) throw clipperException("DoMaxima error"); IntersectEdges( e, eNext, IntPoint(X, topY), ipBoth ); SwapPositionsInAEL(e, eNext); eNext = e->nextInAEL; } if( e->outIdx < 0 && eMaxPair->outIdx < 0 ) { DeleteFromAEL( e ); DeleteFromAEL( eMaxPair ); } else if( e->outIdx >= 0 && eMaxPair->outIdx >= 0 ) { IntersectEdges( e, eMaxPair, IntPoint(X, topY), ipNone ); } else throw clipperException("DoMaxima error"); } //------------------------------------------------------------------------------ void Clipper::ProcessEdgesAtTopOfScanbeam(const long64 topY) { TEdge* e = m_ActiveEdges; while( e ) { //1. process maxima, treating them as if they're 'bent' horizontal edges, // but exclude maxima with horizontal edges. nb: e can't be a horizontal. if( IsMaxima(e, topY) && !NEAR_EQUAL(GetMaximaPair(e)->dx, HORIZONTAL) ) { //'e' might be removed from AEL, as may any following edges so ... TEdge* ePrev = e->prevInAEL; DoMaxima(e, topY); if( !ePrev ) e = m_ActiveEdges; else e = ePrev->nextInAEL; } else { bool intermediateVert = IsIntermediate(e, topY); //2. promote horizontal edges, otherwise update xcurr and ycurr ... if (intermediateVert && NEAR_EQUAL(e->nextInLML->dx, HORIZONTAL) ) { if (e->outIdx >= 0) { AddOutPt(e, IntPoint(e->xtop, e->ytop)); for (HorzJoinList::size_type i = 0; i < m_HorizJoins.size(); ++i) { IntPoint pt, pt2; HorzJoinRec* hj = m_HorizJoins[i]; if (GetOverlapSegment(IntPoint(hj->edge->xbot, hj->edge->ybot), IntPoint(hj->edge->xtop, hj->edge->ytop), IntPoint(e->nextInLML->xbot, e->nextInLML->ybot), IntPoint(e->nextInLML->xtop, e->nextInLML->ytop), pt, pt2)) AddJoin(hj->edge, e->nextInLML, hj->savedIdx, e->outIdx); } AddHorzJoin(e->nextInLML, e->outIdx); } UpdateEdgeIntoAEL(e); AddEdgeToSEL(e); } else { e->xcurr = TopX( *e, topY ); e->ycurr = topY; if (m_ForceSimple && e->prevInAEL && e->prevInAEL->xcurr == e->xcurr && e->outIdx >= 0 && e->prevInAEL->outIdx >= 0) { if (intermediateVert) AddOutPt(e->prevInAEL, IntPoint(e->xcurr, topY)); else AddOutPt(e, IntPoint(e->xcurr, topY)); } } e = e->nextInAEL; } } //3. Process horizontals at the top of the scanbeam ... ProcessHorizontals(); //4. Promote intermediate vertices ... e = m_ActiveEdges; while( e ) { if( IsIntermediate( e, topY ) ) { if( e->outIdx >= 0 ) AddOutPt(e, IntPoint(e->xtop,e->ytop)); UpdateEdgeIntoAEL(e); //if output polygons share an edge, they'll need joining later ... TEdge* ePrev = e->prevInAEL; TEdge* eNext = e->nextInAEL; if (ePrev && ePrev->xcurr == e->xbot && ePrev->ycurr == e->ybot && e->outIdx >= 0 && ePrev->outIdx >= 0 && ePrev->ycurr > ePrev->ytop && SlopesEqual(*e, *ePrev, m_UseFullRange)) { AddOutPt(ePrev, IntPoint(e->xbot, e->ybot)); AddJoin(e, ePrev); } else if (eNext && eNext->xcurr == e->xbot && eNext->ycurr == e->ybot && e->outIdx >= 0 && eNext->outIdx >= 0 && eNext->ycurr > eNext->ytop && SlopesEqual(*e, *eNext, m_UseFullRange)) { AddOutPt(eNext, IntPoint(e->xbot, e->ybot)); AddJoin(e, eNext); } } e = e->nextInAEL; } } //------------------------------------------------------------------------------ void Clipper::FixupOutPolygon(OutRec &outrec) { //FixupOutPolygon() - removes duplicate points and simplifies consecutive //parallel edges by removing the middle vertex. OutPt *lastOK = 0; outrec.bottomPt = 0; OutPt *pp = outrec.pts; for (;;) { if (pp->prev == pp || pp->prev == pp->next ) { DisposeOutPts(pp); outrec.pts = 0; return; } //test for duplicate points and for same slope (cross-product) ... if ( PointsEqual(pp->pt, pp->next->pt) || SlopesEqual(pp->prev->pt, pp->pt, pp->next->pt, m_UseFullRange) ) { lastOK = 0; OutPt *tmp = pp; pp->prev->next = pp->next; pp->next->prev = pp->prev; pp = pp->prev; delete tmp; } else if (pp == lastOK) break; else { if (!lastOK) lastOK = pp; pp = pp->next; } } outrec.pts = pp; } //------------------------------------------------------------------------------ void Clipper::BuildResult(Polygons &polys) { polys.reserve(m_PolyOuts.size()); for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); ++i) { if (m_PolyOuts[i]->pts) { Polygon pg; OutPt* p = m_PolyOuts[i]->pts; do { pg.push_back(p->pt); p = p->prev; } while (p != m_PolyOuts[i]->pts); if (pg.size() > 2) polys.push_back(pg); } } } //------------------------------------------------------------------------------ int PointCount(OutPt *pts) { if (!pts) return 0; int result = 0; OutPt* p = pts; do { result++; p = p->next; } while (p != pts); return result; } //------------------------------------------------------------------------------ void Clipper::BuildResult2(PolyTree& polytree) { polytree.Clear(); polytree.AllNodes.reserve(m_PolyOuts.size()); //add each output polygon/contour to polytree ... for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); i++) { OutRec* outRec = m_PolyOuts[i]; int cnt = PointCount(outRec->pts); if (cnt < 3) continue; FixHoleLinkage(*outRec); PolyNode* pn = new PolyNode(); //nb: polytree takes ownership of all the PolyNodes polytree.AllNodes.push_back(pn); outRec->polyNode = pn; pn->Parent = 0; pn->Index = 0; pn->Contour.reserve(cnt); OutPt *op = outRec->pts; for (int j = 0; j < cnt; j++) { pn->Contour.push_back(op->pt); op = op->prev; } } //fixup PolyNode links etc ... polytree.Childs.reserve(m_PolyOuts.size()); for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); i++) { OutRec* outRec = m_PolyOuts[i]; if (!outRec->polyNode) continue; if (outRec->FirstLeft) outRec->FirstLeft->polyNode->AddChild(*outRec->polyNode); else polytree.AddChild(*outRec->polyNode); } } //------------------------------------------------------------------------------ void SwapIntersectNodes(IntersectNode &int1, IntersectNode &int2) { //just swap the contents (because fIntersectNodes is a single-linked-list) IntersectNode inode = int1; //gets a copy of Int1 int1.edge1 = int2.edge1; int1.edge2 = int2.edge2; int1.pt = int2.pt; int2.edge1 = inode.edge1; int2.edge2 = inode.edge2; int2.pt = inode.pt; } //------------------------------------------------------------------------------ inline bool EdgesAdjacent(const IntersectNode &inode) { return (inode.edge1->nextInSEL == inode.edge2) || (inode.edge1->prevInSEL == inode.edge2); } //------------------------------------------------------------------------------ bool Clipper::FixupIntersectionOrder() { //pre-condition: intersections are sorted bottom-most (then left-most) first. //Now it's crucial that intersections are made only between adjacent edges, //so to ensure this the order of intersections may need adjusting ... IntersectNode *inode = m_IntersectNodes; CopyAELToSEL(); while (inode) { if (!EdgesAdjacent(*inode)) { IntersectNode *nextNode = inode->next; while (nextNode && !EdgesAdjacent(*nextNode)) nextNode = nextNode->next; if (!nextNode) return false; SwapIntersectNodes(*inode, *nextNode); } SwapPositionsInSEL(inode->edge1, inode->edge2); inode = inode->next; } return true; } //------------------------------------------------------------------------------ bool E2InsertsBeforeE1(TEdge &e1, TEdge &e2) { if (e2.xcurr == e1.xcurr) { if (e2.ytop > e1.ytop) return e2.xtop < TopX(e1, e2.ytop); else return e1.xtop > TopX(e2, e1.ytop); } else return e2.xcurr < e1.xcurr; } //------------------------------------------------------------------------------ void Clipper::InsertEdgeIntoAEL(TEdge *edge) { edge->prevInAEL = 0; edge->nextInAEL = 0; if( !m_ActiveEdges ) { m_ActiveEdges = edge; } else if( E2InsertsBeforeE1(*m_ActiveEdges, *edge) ) { edge->nextInAEL = m_ActiveEdges; m_ActiveEdges->prevInAEL = edge; m_ActiveEdges = edge; } else { TEdge* e = m_ActiveEdges; while( e->nextInAEL && !E2InsertsBeforeE1(*e->nextInAEL , *edge) ) e = e->nextInAEL; edge->nextInAEL = e->nextInAEL; if( e->nextInAEL ) e->nextInAEL->prevInAEL = edge; edge->prevInAEL = e; e->nextInAEL = edge; } } //---------------------------------------------------------------------- bool Clipper::JoinPoints(const JoinRec *j, OutPt *&p1, OutPt *&p2) { OutRec *outRec1 = m_PolyOuts[j->poly1Idx]; OutRec *outRec2 = m_PolyOuts[j->poly2Idx]; if (!outRec1 || !outRec2) return false; OutPt *pp1a = outRec1->pts; OutPt *pp2a = outRec2->pts; IntPoint pt1 = j->pt2a, pt2 = j->pt2b; IntPoint pt3 = j->pt1a, pt4 = j->pt1b; if (!FindSegment(pp1a, m_UseFullRange, pt1, pt2)) return false; if (outRec1 == outRec2) { //we're searching the same polygon for overlapping segments so //segment 2 mustn't be the same as segment 1 ... pp2a = pp1a->next; if (!FindSegment(pp2a, m_UseFullRange, pt3, pt4) || (pp2a == pp1a)) return false; } else if (!FindSegment(pp2a, m_UseFullRange, pt3, pt4)) return false; if (!GetOverlapSegment(pt1, pt2, pt3, pt4, pt1, pt2)) return false; OutPt *p3, *p4, *prev = pp1a->prev; //get p1 & p2 polypts - the overlap start & endpoints on poly1 if (PointsEqual(pp1a->pt, pt1)) p1 = pp1a; else if (PointsEqual(prev->pt, pt1)) p1 = prev; else p1 = InsertPolyPtBetween(pp1a, prev, pt1); if (PointsEqual(pp1a->pt, pt2)) p2 = pp1a; else if (PointsEqual(prev->pt, pt2)) p2 = prev; else if ((p1 == pp1a) || (p1 == prev)) p2 = InsertPolyPtBetween(pp1a, prev, pt2); else if (Pt3IsBetweenPt1AndPt2(pp1a->pt, p1->pt, pt2)) p2 = InsertPolyPtBetween(pp1a, p1, pt2); else p2 = InsertPolyPtBetween(p1, prev, pt2); //get p3 & p4 polypts - the overlap start & endpoints on poly2 prev = pp2a->prev; if (PointsEqual(pp2a->pt, pt1)) p3 = pp2a; else if (PointsEqual(prev->pt, pt1)) p3 = prev; else p3 = InsertPolyPtBetween(pp2a, prev, pt1); if (PointsEqual(pp2a->pt, pt2)) p4 = pp2a; else if (PointsEqual(prev->pt, pt2)) p4 = prev; else if ((p3 == pp2a) || (p3 == prev)) p4 = InsertPolyPtBetween(pp2a, prev, pt2); else if (Pt3IsBetweenPt1AndPt2(pp2a->pt, p3->pt, pt2)) p4 = InsertPolyPtBetween(pp2a, p3, pt2); else p4 = InsertPolyPtBetween(p3, prev, pt2); //p1.pt == p3.pt and p2.pt == p4.pt so join p1 to p3 and p2 to p4 ... if (p1->next == p2 && p3->prev == p4) { p1->next = p3; p3->prev = p1; p2->prev = p4; p4->next = p2; return true; } else if (p1->prev == p2 && p3->next == p4) { p1->prev = p3; p3->next = p1; p2->next = p4; p4->prev = p2; return true; } else return false; //an orientation is probably wrong } //---------------------------------------------------------------------- void Clipper::FixupJoinRecs(JoinRec *j, OutPt *pt, unsigned startIdx) { for (JoinList::size_type k = startIdx; k < m_Joins.size(); k++) { JoinRec* j2 = m_Joins[k]; if (j2->poly1Idx == j->poly1Idx && PointIsVertex(j2->pt1a, pt)) j2->poly1Idx = j->poly2Idx; if (j2->poly2Idx == j->poly1Idx && PointIsVertex(j2->pt2a, pt)) j2->poly2Idx = j->poly2Idx; } } //---------------------------------------------------------------------- bool Poly2ContainsPoly1(OutPt* outPt1, OutPt* outPt2, bool UseFullInt64Range) { OutPt* pt = outPt1; //Because the polygons may be touching, we need to find a vertex that //isn't touching the other polygon ... if (PointOnPolygon(pt->pt, outPt2, UseFullInt64Range)) { pt = pt->next; while (pt != outPt1 && PointOnPolygon(pt->pt, outPt2, UseFullInt64Range)) pt = pt->next; if (pt == outPt1) return true; } return PointInPolygon(pt->pt, outPt2, UseFullInt64Range); } //---------------------------------------------------------------------- void Clipper::FixupFirstLefts1(OutRec* OldOutRec, OutRec* NewOutRec) { for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); ++i) { OutRec* outRec = m_PolyOuts[i]; if (outRec->pts && outRec->FirstLeft == OldOutRec) { if (Poly2ContainsPoly1(outRec->pts, NewOutRec->pts, m_UseFullRange)) outRec->FirstLeft = NewOutRec; } } } //---------------------------------------------------------------------- void Clipper::FixupFirstLefts2(OutRec* OldOutRec, OutRec* NewOutRec) { for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); ++i) { OutRec* outRec = m_PolyOuts[i]; if (outRec->FirstLeft == OldOutRec) outRec->FirstLeft = NewOutRec; } } //---------------------------------------------------------------------- void Clipper::JoinCommonEdges() { for (JoinList::size_type i = 0; i < m_Joins.size(); i++) { JoinRec* j = m_Joins[i]; OutRec *outRec1 = GetOutRec(j->poly1Idx); OutRec *outRec2 = GetOutRec(j->poly2Idx); if (!outRec1->pts || !outRec2->pts) continue; //get the polygon fragment with the correct hole state (FirstLeft) //before calling JoinPoints() ... OutRec *holeStateRec; if (outRec1 == outRec2) holeStateRec = outRec1; else if (Param1RightOfParam2(outRec1, outRec2)) holeStateRec = outRec2; else if (Param1RightOfParam2(outRec2, outRec1)) holeStateRec = outRec1; else holeStateRec = GetLowermostRec(outRec1, outRec2); OutPt *p1, *p2; if (!JoinPoints(j, p1, p2)) continue; if (outRec1 == outRec2) { //instead of joining two polygons, we've just created a new one by //splitting one polygon into two. outRec1->pts = p1; outRec1->bottomPt = 0; outRec2 = CreateOutRec(); outRec2->pts = p2; if (Poly2ContainsPoly1(outRec2->pts, outRec1->pts, m_UseFullRange)) { //outRec2 is contained by outRec1 ... outRec2->isHole = !outRec1->isHole; outRec2->FirstLeft = outRec1; FixupJoinRecs(j, p2, i+1); //fixup FirstLeft pointers that may need reassigning to OutRec1 if (m_UsingPolyTree) FixupFirstLefts2(outRec2, outRec1); FixupOutPolygon(*outRec1); //nb: do this BEFORE testing orientation FixupOutPolygon(*outRec2); // but AFTER calling FixupJoinRecs() if ((outRec2->isHole ^ m_ReverseOutput) == (Area(*outRec2, m_UseFullRange) > 0)) ReversePolyPtLinks(outRec2->pts); } else if (Poly2ContainsPoly1(outRec1->pts, outRec2->pts, m_UseFullRange)) { //outRec1 is contained by outRec2 ... outRec2->isHole = outRec1->isHole; outRec1->isHole = !outRec2->isHole; outRec2->FirstLeft = outRec1->FirstLeft; outRec1->FirstLeft = outRec2; FixupJoinRecs(j, p2, i+1); //fixup FirstLeft pointers that may need reassigning to OutRec1 if (m_UsingPolyTree) FixupFirstLefts2(outRec1, outRec2); FixupOutPolygon(*outRec1); //nb: do this BEFORE testing orientation FixupOutPolygon(*outRec2); // but AFTER calling FixupJoinRecs() if ((outRec1->isHole ^ m_ReverseOutput) == (Area(*outRec1, m_UseFullRange) > 0)) ReversePolyPtLinks(outRec1->pts); } else { //the 2 polygons are completely separate ... outRec2->isHole = outRec1->isHole; outRec2->FirstLeft = outRec1->FirstLeft; FixupJoinRecs(j, p2, i+1); //fixup FirstLeft pointers that may need reassigning to OutRec2 if (m_UsingPolyTree) FixupFirstLefts1(outRec1, outRec2); FixupOutPolygon(*outRec1); //nb: do this BEFORE testing orientation FixupOutPolygon(*outRec2); // but AFTER calling FixupJoinRecs() } } else { //joined 2 polygons together ... //cleanup redundant edges ... FixupOutPolygon(*outRec1); outRec2->pts = 0; outRec2->bottomPt = 0; outRec2->idx = outRec1->idx; outRec1->isHole = holeStateRec->isHole; if (holeStateRec == outRec2) outRec1->FirstLeft = outRec2->FirstLeft; outRec2->FirstLeft = outRec1; //fixup FirstLeft pointers that may need reassigning to OutRec1 if (m_UsingPolyTree) FixupFirstLefts2(outRec2, outRec1); } } } //------------------------------------------------------------------------------ inline void UpdateOutPtIdxs(OutRec& outrec) { OutPt* op = outrec.pts; do { op->idx = outrec.idx; op = op->prev; } while(op != outrec.pts); } //------------------------------------------------------------------------------ void Clipper::DoSimplePolygons() { PolyOutList::size_type i = 0; while (i < m_PolyOuts.size()) { OutRec* outrec = m_PolyOuts[i++]; OutPt* op = outrec->pts; if (!op) continue; do //for each Pt in Polygon until duplicate found do ... { OutPt* op2 = op->next; while (op2 != outrec->pts) { if (PointsEqual(op->pt, op2->pt) && op2->next != op && op2->prev != op) { //split the polygon into two ... OutPt* op3 = op->prev; OutPt* op4 = op2->prev; op->prev = op4; op4->next = op; op2->prev = op3; op3->next = op2; outrec->pts = op; OutRec* outrec2 = CreateOutRec(); outrec2->pts = op2; UpdateOutPtIdxs(*outrec2); if (Poly2ContainsPoly1(outrec2->pts, outrec->pts, m_UseFullRange)) { //OutRec2 is contained by OutRec1 ... outrec2->isHole = !outrec->isHole; outrec2->FirstLeft = outrec; } else if (Poly2ContainsPoly1(outrec->pts, outrec2->pts, m_UseFullRange)) { //OutRec1 is contained by OutRec2 ... outrec2->isHole = outrec->isHole; outrec->isHole = !outrec2->isHole; outrec2->FirstLeft = outrec->FirstLeft; outrec->FirstLeft = outrec2; } else { //the 2 polygons are separate ... outrec2->isHole = outrec->isHole; outrec2->FirstLeft = outrec->FirstLeft; } op2 = op; //ie get ready for the next iteration } op2 = op2->next; } op = op->next; } while (op != outrec->pts); } } //------------------------------------------------------------------------------ void ReversePolygon(Polygon& p) { std::reverse(p.begin(), p.end()); } //------------------------------------------------------------------------------ void ReversePolygons(Polygons& p) { for (Polygons::size_type i = 0; i < p.size(); ++i) ReversePolygon(p[i]); } //------------------------------------------------------------------------------ // OffsetPolygon functions ... //------------------------------------------------------------------------------ struct DoublePoint { double X; double Y; DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {} }; //------------------------------------------------------------------------------ Polygon BuildArc(const IntPoint &pt, const double a1, const double a2, const double r, double limit) { //see notes in clipper.pas regarding steps double arcFrac = std::fabs(a2 - a1) / (2 * pi); int steps = (int)(arcFrac * pi / std::acos(1 - limit / std::fabs(r))); if (steps < 2) steps = 2; else if (steps > (int)(222.0 * arcFrac)) steps = (int)(222.0 * arcFrac); double x = std::cos(a1); double y = std::sin(a1); double c = std::cos((a2 - a1) / steps); double s = std::sin((a2 - a1) / steps); Polygon result(steps +1); for (int i = 0; i <= steps; ++i) { result[i].X = pt.X + Round(x * r); result[i].Y = pt.Y + Round(y * r); double x2 = x; x = x * c - s * y; //cross product y = x2 * s + y * c; //dot product } return result; } //------------------------------------------------------------------------------ DoublePoint GetUnitNormal(const IntPoint &pt1, const IntPoint &pt2) { if(pt2.X == pt1.X && pt2.Y == pt1.Y) return DoublePoint(0, 0); double dx = (double)(pt2.X - pt1.X); double dy = (double)(pt2.Y - pt1.Y); double f = 1 *1.0/ std::sqrt( dx*dx + dy*dy ); dx *= f; dy *= f; return DoublePoint(dy, -dx); } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ class PolyOffsetBuilder { private: Polygons m_p; Polygon* m_curr_poly; std::vector normals; double m_delta, m_RMin, m_R; size_t m_i, m_j, m_k; static const int buffLength = 128; JoinType m_jointype; public: PolyOffsetBuilder(const Polygons& in_polys, Polygons& out_polys, double delta, JoinType jointype, double limit, bool autoFix) { //nb precondition - out_polys != ptsin_polys if (NEAR_ZERO(delta)) { out_polys = in_polys; return; } this->m_p = in_polys; this->m_delta = delta; this->m_jointype = jointype; //ChecksInput - fixes polygon orientation if necessary and removes //duplicate vertices. Can be set false when you're sure that polygon //orientation is correct and that there are no duplicate vertices. if (autoFix) { size_t Len = m_p.size(), botI = 0; while (botI < Len && m_p[botI].empty()) botI++; if (botI == Len) return; //botPt: used to find the lowermost (in inverted Y-axis) & leftmost point //This point (on m_p[botI]) must be on an outer polygon ring and if //its orientation is false (counterclockwise) then assume all polygons //need reversing ... IntPoint botPt = m_p[botI][0]; for (size_t i = botI; i < Len; ++i) { if (m_p[i].size() < 3) continue; if (UpdateBotPt(m_p[i][0], botPt)) botI = i; Polygon::iterator it = m_p[i].begin() +1; while (it != m_p[i].end()) { if (PointsEqual(*it, *(it -1))) it = m_p[i].erase(it); else { if (UpdateBotPt(*it, botPt)) botI = i; ++it; } } } if (!Orientation(m_p[botI])) ReversePolygons(m_p); } switch (jointype) { case jtRound: if (limit <= 0) limit = 0.25; else if (limit > std::fabs(delta)) limit = std::fabs(delta); break; case jtMiter: if (limit < 2) limit = 2; break; default: //unused limit = 1; } m_RMin = 2.0/(limit*limit); double deltaSq = delta*delta; out_polys.clear(); out_polys.resize(m_p.size()); for (m_i = 0; m_i < m_p.size(); m_i++) { m_curr_poly = &out_polys[m_i]; size_t len = m_p[m_i].size(); if (len > 1 && m_p[m_i][0].X == m_p[m_i][len - 1].X && m_p[m_i][0].Y == m_p[m_i][len-1].Y) len--; //when 'shrinking' polygons - to minimize artefacts //strip those polygons that have an area < pi * delta^2 ... double a1 = Area(m_p[m_i]); if (delta < 0) { if (a1 > 0 && a1 < deltaSq *pi) len = 0; } else if (a1 < 0 && -a1 < deltaSq *pi) len = 0; //holes have neg. area if (len == 0 || (len < 3 && delta <= 0)) continue; else if (len == 1) { Polygon arc; arc = BuildArc(m_p[m_i][len-1], 0, 2 * pi, delta, limit); out_polys[m_i] = arc; continue; } //build normals ... normals.clear(); normals.resize(len); normals[len-1] = GetUnitNormal(m_p[m_i][len-1], m_p[m_i][0]); for (m_j = 0; m_j < len -1; ++m_j) normals[m_j] = GetUnitNormal(m_p[m_i][m_j], m_p[m_i][m_j+1]); m_k = len -1; for (m_j = 0; m_j < len; ++m_j) { switch (jointype) { case jtMiter: { m_R = 1 + (normals[m_j].X*normals[m_k].X + normals[m_j].Y*normals[m_k].Y); if (m_R >= m_RMin) DoMiter(); else DoSquare(limit); break; } case jtSquare: DoSquare(1.0); break; case jtRound: DoRound(limit); break; } m_k = m_j; } } //finally, clean up untidy corners using Clipper ... Clipper clpr; clpr.AddPolygons(out_polys, ptSubject); if (delta > 0) { if (!clpr.Execute(ctUnion, out_polys, pftPositive, pftPositive)) out_polys.clear(); } else { IntRect r = clpr.GetBounds(); Polygon outer(4); outer[0] = IntPoint(r.left - 10, r.bottom + 10); outer[1] = IntPoint(r.right + 10, r.bottom + 10); outer[2] = IntPoint(r.right + 10, r.top - 10); outer[3] = IntPoint(r.left - 10, r.top - 10); clpr.AddPolygon(outer, ptSubject); if (clpr.Execute(ctUnion, out_polys, pftNegative, pftNegative)) { out_polys.erase(out_polys.begin()); ReversePolygons(out_polys); } else out_polys.clear(); } } //------------------------------------------------------------------------------ private: void AddPoint(const IntPoint& pt) { if (m_curr_poly->size() == m_curr_poly->capacity()) m_curr_poly->reserve(m_curr_poly->capacity() + buffLength); m_curr_poly->push_back(pt); } //------------------------------------------------------------------------------ void DoSquare(double mul) { IntPoint pt1 = IntPoint((long64)Round(m_p[m_i][m_j].X + normals[m_k].X * m_delta), (long64)Round(m_p[m_i][m_j].Y + normals[m_k].Y * m_delta)); IntPoint pt2 = IntPoint((long64)Round(m_p[m_i][m_j].X + normals[m_j].X * m_delta), (long64)Round(m_p[m_i][m_j].Y + normals[m_j].Y * m_delta)); if ((normals[m_k].X * normals[m_j].Y - normals[m_j].X * normals[m_k].Y) * m_delta >= 0) { double a1 = std::atan2(normals[m_k].Y, normals[m_k].X); double a2 = std::atan2(-normals[m_j].Y, -normals[m_j].X); a1 = std::fabs(a2 - a1); if (a1 > pi) a1 = pi * 2 - a1; double dx = std::tan((pi - a1) / 4) * std::fabs(m_delta * mul); pt1 = IntPoint((long64)(pt1.X -normals[m_k].Y * dx), (long64)(pt1.Y + normals[m_k].X * dx)); AddPoint(pt1); pt2 = IntPoint((long64)(pt2.X + normals[m_j].Y * dx), (long64)(pt2.Y -normals[m_j].X * dx)); AddPoint(pt2); } else { AddPoint(pt1); AddPoint(m_p[m_i][m_j]); AddPoint(pt2); } } //------------------------------------------------------------------------------ void DoMiter() { if ((normals[m_k].X * normals[m_j].Y - normals[m_j].X * normals[m_k].Y) * m_delta >= 0) { double q = m_delta / m_R; AddPoint(IntPoint((long64)Round(m_p[m_i][m_j].X + (normals[m_k].X + normals[m_j].X) * q), (long64)Round(m_p[m_i][m_j].Y + (normals[m_k].Y + normals[m_j].Y) * q))); } else { IntPoint pt1 = IntPoint((long64)Round(m_p[m_i][m_j].X + normals[m_k].X * m_delta), (long64)Round(m_p[m_i][m_j].Y + normals[m_k].Y * m_delta)); IntPoint pt2 = IntPoint((long64)Round(m_p[m_i][m_j].X + normals[m_j].X * m_delta), (long64)Round(m_p[m_i][m_j].Y + normals[m_j].Y * m_delta)); AddPoint(pt1); AddPoint(m_p[m_i][m_j]); AddPoint(pt2); } } //------------------------------------------------------------------------------ void DoRound(double limit) { IntPoint pt1 = IntPoint((long64)Round(m_p[m_i][m_j].X + normals[m_k].X * m_delta), (long64)Round(m_p[m_i][m_j].Y + normals[m_k].Y * m_delta)); IntPoint pt2 = IntPoint((long64)Round(m_p[m_i][m_j].X + normals[m_j].X * m_delta), (long64)Round(m_p[m_i][m_j].Y + normals[m_j].Y * m_delta)); AddPoint(pt1); //round off reflex angles (ie > 180 deg) unless almost flat (ie < ~10deg). if ((normals[m_k].X*normals[m_j].Y - normals[m_j].X*normals[m_k].Y) * m_delta >= 0) { if (normals[m_j].X * normals[m_k].X + normals[m_j].Y * normals[m_k].Y < 0.985) { double a1 = std::atan2(normals[m_k].Y, normals[m_k].X); double a2 = std::atan2(normals[m_j].Y, normals[m_j].X); if (m_delta > 0 && a2 < a1) a2 += pi *2; else if (m_delta < 0 && a2 > a1) a2 -= pi *2; Polygon arc = BuildArc(m_p[m_i][m_j], a1, a2, m_delta, limit); for (Polygon::size_type m = 0; m < arc.size(); m++) AddPoint(arc[m]); } } else AddPoint(m_p[m_i][m_j]); AddPoint(pt2); } //-------------------------------------------------------------------------- bool UpdateBotPt(const IntPoint &pt, IntPoint &botPt) { if (pt.Y > botPt.Y || (pt.Y == botPt.Y && pt.X < botPt.X)) { botPt = pt; return true; } else return false; } //-------------------------------------------------------------------------- }; //end PolyOffsetBuilder //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ void OffsetPolygons(const Polygons &in_polys, Polygons &out_polys, double delta, JoinType jointype, double limit, bool autoFix) { if (&out_polys == &in_polys) { Polygons poly2(in_polys); PolyOffsetBuilder(poly2, out_polys, delta, jointype, limit, autoFix); } else PolyOffsetBuilder(in_polys, out_polys, delta, jointype, limit, autoFix); } //------------------------------------------------------------------------------ void SimplifyPolygon(const Polygon &in_poly, Polygons &out_polys, PolyFillType fillType) { Clipper c; c.ForceSimple(true); c.AddPolygon(in_poly, ptSubject); c.Execute(ctUnion, out_polys, fillType, fillType); } //------------------------------------------------------------------------------ void SimplifyPolygons(const Polygons &in_polys, Polygons &out_polys, PolyFillType fillType) { Clipper c; c.ForceSimple(true); c.AddPolygons(in_polys, ptSubject); c.Execute(ctUnion, out_polys, fillType, fillType); } //------------------------------------------------------------------------------ void SimplifyPolygons(Polygons &polys, PolyFillType fillType) { SimplifyPolygons(polys, polys, fillType); } //------------------------------------------------------------------------------ inline double DistanceSqrd(const IntPoint& pt1, const IntPoint& pt2) { double dx = ((double)pt1.X - pt2.X); double dy = ((double)pt1.Y - pt2.Y); return (dx*dx + dy*dy); } //------------------------------------------------------------------------------ DoublePoint ClosestPointOnLine(const IntPoint& pt, const IntPoint& linePt1, const IntPoint& linePt2) { double dx = ((double)linePt2.X - linePt1.X); double dy = ((double)linePt2.Y - linePt1.Y); if (dx == 0 && dy == 0) return DoublePoint((double)linePt1.X, (double)linePt1.Y); double q = ((pt.X-linePt1.X)*dx + (pt.Y-linePt1.Y)*dy) / (dx*dx + dy*dy); return DoublePoint( (1-q)*linePt1.X + q*linePt2.X, (1-q)*linePt1.Y + q*linePt2.Y); } //------------------------------------------------------------------------------ bool SlopesNearColinear(const IntPoint& pt1, const IntPoint& pt2, const IntPoint& pt3, double distSqrd) { if (DistanceSqrd(pt1, pt2) > DistanceSqrd(pt1, pt3)) return false; DoublePoint cpol = ClosestPointOnLine(pt2, pt1, pt3); double dx = pt2.X - cpol.X; double dy = pt2.Y - cpol.Y; return (dx*dx + dy*dy) < distSqrd; } //------------------------------------------------------------------------------ bool PointsAreClose(IntPoint pt1, IntPoint pt2, double distSqrd) { double dx = (double)pt1.X - pt2.X; double dy = (double)pt1.Y - pt2.Y; return ((dx * dx) + (dy * dy) <= distSqrd); } //------------------------------------------------------------------------------ void CleanPolygon(Polygon& in_poly, Polygon& out_poly, double distance) { //distance = proximity in units/pixels below which vertices //will be stripped. Default ~= sqrt(2). int highI = in_poly.size() -1; double distSqrd = distance * distance; while (highI > 0 && PointsAreClose(in_poly[highI], in_poly[0], distSqrd)) highI--; if (highI < 2) { out_poly.clear(); return; } out_poly.resize(highI + 1); IntPoint pt = in_poly[highI]; int i = 0, k = 0; for (;;) { while (i <= highI && PointsAreClose(pt, in_poly[i+1], distSqrd)) i+=2; int i2 = i; while (i <= highI && PointsAreClose(in_poly[i], in_poly[i+1], distSqrd) || SlopesNearColinear(pt, in_poly[i], in_poly[+1], distSqrd)) i++; if (i >= highI) break; else if (i != i2) continue; pt = in_poly[i++]; out_poly[k++] = pt; } if (i <= highI) out_poly[k++] = in_poly[i]; if (k > 2 && SlopesNearColinear(out_poly[k -2], out_poly[k -1], out_poly[0], distSqrd)) k--; if (k < 3) out_poly.clear(); else if (k <= highI) out_poly.resize(k); } //------------------------------------------------------------------------------ void CleanPolygons(Polygons& in_polys, Polygons& out_polys, double distance) { for (Polygons::size_type i = 0; i < in_polys.size(); ++i) CleanPolygon(in_polys[i], out_polys[i], distance); } //------------------------------------------------------------------------------ void AddPolyNodeToPolygons(PolyNode& polynode, Polygons& polygons) { if (!polynode.Contour.empty()) polygons.push_back(polynode.Contour); for (int i = 0; i < polynode.ChildCount(); ++i) AddPolyNodeToPolygons(*polynode.Childs[i], polygons); } //------------------------------------------------------------------------------ void PolyTreeToPolygons(PolyTree& polytree, Polygons& polygons) { polygons.resize(0); polygons.reserve(polytree.Total()); AddPolyNodeToPolygons(polytree, polygons); } //------------------------------------------------------------------------------ std::ostream& operator <<(std::ostream &s, IntPoint& p) { s << p.X << ' ' << p.Y << "\n"; return s; } //------------------------------------------------------------------------------ std::ostream& operator <<(std::ostream &s, Polygon &p) { for (Polygon::size_type i = 0; i < p.size(); i++) s << p[i]; s << "\n"; return s; } //------------------------------------------------------------------------------ std::ostream& operator <<(std::ostream &s, Polygons &p) { for (Polygons::size_type i = 0; i < p.size(); i++) s << p[i]; s << "\n"; return s; } //------------------------------------------------------------------------------ } //ClipperLib namespace Math-Clipper-1.29/src/clipper.hpp000555001750001750 2731313467455703 16131 0ustar00mikemike000000000000/******************************************************************************* * * * Author : Angus Johnson * * Version : 5.1.5 * * Date : 4 May 2013 * * Website : http://www.angusj.com * * Copyright : Angus Johnson 2010-2013 * * * * License: * * Use, modification & distribution is subject to Boost Software License Ver 1. * * http://www.boost.org/LICENSE_1_0.txt * * * * Attributions: * * The code in this library is an extension of Bala Vatti's clipping algorithm: * * "A generic solution to polygon clipping" * * Communications of the ACM, Vol 35, Issue 7 (July 1992) pp 56-63. * * http://portal.acm.org/citation.cfm?id=129906 * * * * Computer graphics and geometric modeling: implementation and algorithms * * By Max K. Agoston * * Springer; 1 edition (January 4, 2005) * * http://books.google.com/books?q=vatti+clipping+agoston * * * * See also: * * "Polygon Offsetting by Computing Winding Numbers" * * Paper no. DETC2005-85513 pp. 565-575 * * ASME 2005 International Design Engineering Technical Conferences * * and Computers and Information in Engineering Conference (IDETC/CIE2005) * * September 24-28, 2005 , Long Beach, California, USA * * http://www.me.berkeley.edu/~mcmains/pubs/DAC05OffsetPolygon.pdf * * * *******************************************************************************/ #ifndef clipper_hpp #define clipper_hpp #include #include #include #include #include namespace ClipperLib { enum ClipType { ctIntersection, ctUnion, ctDifference, ctXor }; enum PolyType { ptSubject, ptClip }; //By far the most widely used winding rules for polygon filling are //EvenOdd & NonZero (GDI, GDI+, XLib, OpenGL, Cairo, AGG, Quartz, SVG, Gr32) //Others rules include Positive, Negative and ABS_GTR_EQ_TWO (only in OpenGL) //see http://glprogramming.com/red/chapter11.html enum PolyFillType { pftEvenOdd, pftNonZero, pftPositive, pftNegative }; typedef signed long long long64; typedef unsigned long long ulong64; struct IntPoint { public: long64 X; long64 Y; IntPoint(long64 x = 0, long64 y = 0): X(x), Y(y) {}; friend std::ostream& operator <<(std::ostream &s, IntPoint &p); }; typedef std::vector< IntPoint > Polygon; typedef std::vector< Polygon > Polygons; std::ostream& operator <<(std::ostream &s, Polygon &p); std::ostream& operator <<(std::ostream &s, Polygons &p); class PolyNode; typedef std::vector< PolyNode* > PolyNodes; class PolyNode { public: PolyNode(); Polygon Contour; PolyNodes Childs; PolyNode* Parent; PolyNode* GetNext() const; bool IsHole() const; int ChildCount() const; private: PolyNode* GetNextSiblingUp() const; unsigned Index; //node index in Parent.Childs void AddChild(PolyNode& child); friend class Clipper; //to access Index }; class PolyTree: public PolyNode { public: ~PolyTree(){Clear();}; PolyNode* GetFirst() const; void Clear(); int Total() const; private: PolyNodes AllNodes; friend class Clipper; //to access AllNodes }; enum JoinType { jtSquare, jtRound, jtMiter }; bool Orientation(const Polygon &poly); double Area(const Polygon &poly); void OffsetPolygons(const Polygons &in_polys, Polygons &out_polys, double delta, JoinType jointype = jtSquare, double limit = 0, bool autoFix = true); void SimplifyPolygon(const Polygon &in_poly, Polygons &out_polys, PolyFillType fillType = pftEvenOdd); void SimplifyPolygons(const Polygons &in_polys, Polygons &out_polys, PolyFillType fillType = pftEvenOdd); void SimplifyPolygons(Polygons &polys, PolyFillType fillType = pftEvenOdd); void CleanPolygon(Polygon& in_poly, Polygon& out_poly, double distance = 1.415); void CleanPolygons(Polygons& in_polys, Polygons& out_polys, double distance = 1.415); void PolyTreeToPolygons(PolyTree& polytree, Polygons& polygons); void ReversePolygon(Polygon& p); void ReversePolygons(Polygons& p); //used internally ... enum EdgeSide { esLeft = 1, esRight = 2}; enum IntersectProtects { ipNone = 0, ipLeft = 1, ipRight = 2, ipBoth = 3 }; struct TEdge { long64 xbot; long64 ybot; long64 xcurr; long64 ycurr; long64 xtop; long64 ytop; double dx; long64 deltaX; long64 deltaY; PolyType polyType; EdgeSide side; int windDelta; //1 or -1 depending on winding direction int windCnt; int windCnt2; //winding count of the opposite polytype int outIdx; TEdge *next; TEdge *prev; TEdge *nextInLML; TEdge *nextInAEL; TEdge *prevInAEL; TEdge *nextInSEL; TEdge *prevInSEL; }; struct IntersectNode { TEdge *edge1; TEdge *edge2; IntPoint pt; IntersectNode *next; }; struct LocalMinima { long64 Y; TEdge *leftBound; TEdge *rightBound; LocalMinima *next; }; struct Scanbeam { long64 Y; Scanbeam *next; }; struct OutPt; //forward declaration struct OutRec { int idx; bool isHole; OutRec *FirstLeft; //see comments in clipper.pas PolyNode *polyNode; OutPt *pts; OutPt *bottomPt; }; struct OutPt { int idx; IntPoint pt; OutPt *next; OutPt *prev; }; struct JoinRec { IntPoint pt1a; IntPoint pt1b; int poly1Idx; IntPoint pt2a; IntPoint pt2b; int poly2Idx; }; struct HorzJoinRec { TEdge *edge; int savedIdx; }; struct IntRect { long64 left; long64 top; long64 right; long64 bottom; }; typedef std::vector < OutRec* > PolyOutList; typedef std::vector < TEdge* > EdgeList; typedef std::vector < JoinRec* > JoinList; typedef std::vector < HorzJoinRec* > HorzJoinList; //ClipperBase is the ancestor to the Clipper class. It should not be //instantiated directly. This class simply abstracts the conversion of sets of //polygon coordinates into edge objects that are stored in a LocalMinima list. class ClipperBase { public: ClipperBase(); virtual ~ClipperBase(); bool AddPolygon(const Polygon &pg, PolyType polyType); bool AddPolygons( const Polygons &ppg, PolyType polyType); virtual void Clear(); IntRect GetBounds(); protected: void DisposeLocalMinimaList(); TEdge* AddBoundsToLML(TEdge *e); void PopLocalMinima(); virtual void Reset(); void InsertLocalMinima(LocalMinima *newLm); LocalMinima *m_CurrentLM; LocalMinima *m_MinimaList; bool m_UseFullRange; EdgeList m_edges; }; class Clipper : public virtual ClipperBase { public: Clipper(); ~Clipper(); bool Execute(ClipType clipType, Polygons &solution, PolyFillType subjFillType = pftEvenOdd, PolyFillType clipFillType = pftEvenOdd); bool Execute(ClipType clipType, PolyTree &polytree, PolyFillType subjFillType = pftEvenOdd, PolyFillType clipFillType = pftEvenOdd); void Clear(); bool ReverseSolution() {return m_ReverseOutput;}; void ReverseSolution(bool value) {m_ReverseOutput = value;}; bool ForceSimple() {return m_ForceSimple;}; void ForceSimple(bool value) {m_ForceSimple = value;}; protected: void Reset(); virtual bool ExecuteInternal(); private: PolyOutList m_PolyOuts; JoinList m_Joins; HorzJoinList m_HorizJoins; ClipType m_ClipType; Scanbeam *m_Scanbeam; TEdge *m_ActiveEdges; TEdge *m_SortedEdges; IntersectNode *m_IntersectNodes; bool m_ExecuteLocked; PolyFillType m_ClipFillType; PolyFillType m_SubjFillType; bool m_ReverseOutput; bool m_UsingPolyTree; bool m_ForceSimple; void DisposeScanbeamList(); void SetWindingCount(TEdge& edge); bool IsEvenOddFillType(const TEdge& edge) const; bool IsEvenOddAltFillType(const TEdge& edge) const; void InsertScanbeam(const long64 Y); long64 PopScanbeam(); void InsertLocalMinimaIntoAEL(const long64 botY); void InsertEdgeIntoAEL(TEdge *edge); void AddEdgeToSEL(TEdge *edge); void CopyAELToSEL(); void DeleteFromSEL(TEdge *e); void DeleteFromAEL(TEdge *e); void UpdateEdgeIntoAEL(TEdge *&e); void SwapPositionsInSEL(TEdge *edge1, TEdge *edge2); bool IsContributing(const TEdge& edge) const; bool IsTopHorz(const long64 XPos); void SwapPositionsInAEL(TEdge *edge1, TEdge *edge2); void DoMaxima(TEdge *e, long64 topY); void ProcessHorizontals(); void ProcessHorizontal(TEdge *horzEdge); void AddLocalMaxPoly(TEdge *e1, TEdge *e2, const IntPoint &pt); void AddLocalMinPoly(TEdge *e1, TEdge *e2, const IntPoint &pt); OutRec* GetOutRec(int idx); void AppendPolygon(TEdge *e1, TEdge *e2); void IntersectEdges(TEdge *e1, TEdge *e2, const IntPoint &pt, const IntersectProtects protects); OutRec* CreateOutRec(); void AddOutPt(TEdge *e, const IntPoint &pt); void DisposeAllPolyPts(); void DisposeOutRec(PolyOutList::size_type index); bool ProcessIntersections(const long64 botY, const long64 topY); void AddIntersectNode(TEdge *e1, TEdge *e2, const IntPoint &pt); void BuildIntersectList(const long64 botY, const long64 topY); void ProcessIntersectList(); void ProcessEdgesAtTopOfScanbeam(const long64 topY); void BuildResult(Polygons& polys); void BuildResult2(PolyTree& polytree); void SetHoleState(TEdge *e, OutRec *outrec); void DisposeIntersectNodes(); bool FixupIntersectionOrder(); void FixupOutPolygon(OutRec &outrec); bool IsHole(TEdge *e); void FixHoleLinkage(OutRec &outrec); void AddJoin(TEdge *e1, TEdge *e2, int e1OutIdx = -1, int e2OutIdx = -1); void ClearJoins(); void AddHorzJoin(TEdge *e, int idx); void ClearHorzJoins(); bool JoinPoints(const JoinRec *j, OutPt *&p1, OutPt *&p2); void FixupJoinRecs(JoinRec *j, OutPt *pt, unsigned startIdx); void JoinCommonEdges(); void DoSimplePolygons(); void FixupFirstLefts1(OutRec* OldOutRec, OutRec* NewOutRec); void FixupFirstLefts2(OutRec* OldOutRec, OutRec* NewOutRec); }; //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ class clipperException : public std::exception { public: clipperException(const char* description): m_descr(description) {} virtual ~clipperException() throw() {} virtual const char* what() const throw() {return m_descr.c_str();} private: std::string m_descr; }; //------------------------------------------------------------------------------ } //ClipperLib namespace #endif //clipper_hpp Math-Clipper-1.29/src/myinit.h000444001750001750 253613467455703 15421 0ustar00mikemike000000000000#ifndef __clipper_myinit_h_ #define __clipper_myinit_h_ // fix build error under clang for pre-5.18 Perls #undef dNOOP #define dNOOP struct Perl___notused_struct #include "clipper.hpp" using namespace ClipperLib; //----------------------------------------------------------- // legacy code from Clipper documentation struct ExPolygon { ClipperLib::Polygon outer; ClipperLib::Polygons holes; }; typedef std::vector< ExPolygon > ExPolygons; void AddOuterPolyNodeToExPolygons(ClipperLib::PolyNode& polynode, ExPolygons& expolygons) { size_t cnt = expolygons.size(); expolygons.resize(cnt + 1); expolygons[cnt].outer = polynode.Contour; expolygons[cnt].holes.resize(polynode.ChildCount()); for (int i = 0; i < polynode.ChildCount(); ++i) { expolygons[cnt].holes[i] = polynode.Childs[i]->Contour; //Add outer polygons contained by (nested within) holes ... for (int j = 0; j < polynode.Childs[i]->ChildCount(); ++j) AddOuterPolyNodeToExPolygons(*polynode.Childs[i]->Childs[j], expolygons); } } void PolyTreeToExPolygons(ClipperLib::PolyTree& polytree, ExPolygons& expolygons) { expolygons.clear(); for (int i = 0; i < polytree.ChildCount(); ++i) AddOuterPolyNodeToExPolygons(*polytree.Childs[i], expolygons); } //----------------------------------------------------------- #include "poly2av.h" #include "offset.h" #endif Math-Clipper-1.29/src/offset.h000444001750001750 165713467455703 15401 0ustar00mikemike000000000000#ifndef clipper_offset_h_ #define clipper_offset_h_ #include "myinit.h" void _scale_polygons(ClipperLib::Polygons* polygons, const double scale) { for (ClipperLib::Polygons::size_type i = 0; i != (*polygons).size(); i++) { ClipperLib::Polygon* mypoly = &(*polygons)[i]; for (ClipperLib::Polygon::size_type j = 0; j != (*mypoly).size(); j++) { (*mypoly)[j].X *= scale; (*mypoly)[j].Y *= scale; } } } ClipperLib::Polygons* _int_offset(ClipperLib::Polygons* polygons, const float delta, const double scale, ClipperLib::JoinType jointype, const double MiterLimit) { // scale _scale_polygons(polygons, scale); // perform offset ClipperLib::Polygons* retval = new ClipperLib::Polygons(); ClipperLib::OffsetPolygons(*polygons, *retval, (delta*scale), jointype, MiterLimit); // unscale _scale_polygons(retval, 1/scale); return retval; } #endif Math-Clipper-1.29/src/poly2av.h000444001750001750 1506313467455703 15523 0ustar00mikemike000000000000#ifndef clipper_poly2av_h_ #define clipper_poly2av_h_ #include "myinit.h" SV* polygon2perl(pTHX_ const ClipperLib::Polygon& poly) { AV* av = newAV(); AV* innerav; const unsigned int len = poly.size(); av_extend(av, len == 0 ? 0 : len-1); for (unsigned int i = 0; i < len; i++) { innerav = newAV(); av_store(av, i, newRV_noinc((SV*)innerav)); av_fill(innerav, 1); // IVSIZE is from perl/lib/CORE/config.h, defined as sizeof(IV) #if IVSIZE >= 8 // if Perl integers are 64 bit, use newSViv() av_store(innerav, 0, newSViv(poly[i].X)); av_store(innerav, 1, newSViv(poly[i].Y)); #else // otherwise we expect Clipper integers to fit in the // 53 bit mantissa of a Perl double av_store(innerav, 0, newSVnv(poly[i].X)); av_store(innerav, 1, newSVnv(poly[i].Y)); #endif } return (SV*)newRV_noinc((SV*)av); } SV* polygons2perl(pTHX_ const ClipperLib::Polygons& poly) { AV* av = newAV(); SV* innerav; const unsigned int len = poly.size(); av_extend(av, len == 0 ? 0 : len-1); for (unsigned int i = 0; i < len; i++) { innerav = polygon2perl(aTHX_ poly[i]); av_store(av, i, innerav); } return (SV*)newRV_noinc((SV*)av); } SV* expolygon2perl(pTHX_ const ExPolygon& poly) { HV* hv = newHV(); (void)hv_stores( hv, "outer", (SV*)polygon2perl(aTHX_ poly.outer) ); (void)hv_stores( hv, "holes", (SV*)polygons2perl(aTHX_ poly.holes) ); return (SV*)newRV_noinc((SV*)hv); } SV* expolygons2perl(pTHX_ const ExPolygons& polys) { AV* av = newAV(); SV* innerav; const unsigned int len = polys.size(); av_extend(av, len == 0 ? 0 : len-1); for (unsigned int i = 0; i < len; i++) { innerav = expolygon2perl(aTHX_ polys[i]); av_store(av, i, innerav); } return (SV*)newRV_noinc((SV*)av); } SV* polynode2perl(const PolyNode& node); SV* polynode_children_2_perl(const PolyNode& node) { AV* av = newAV(); const unsigned int len = node.ChildCount(); av_extend(av, len == 0 ? 0 : len-1); for (int i = 0; i < len; ++i) { av_store(av, i, polynode2perl(*node.Childs[i])); } return (SV*)newRV_noinc((SV*)av); } SV* polynode2perl(const PolyNode& node) { HV* hv = newHV(); if (node.IsHole()) { (void)hv_stores( hv, "hole", (SV*)polygon2perl(aTHX_ node.Contour) ); } else { (void)hv_stores( hv, "outer", (SV*)polygon2perl(aTHX_ node.Contour) ); } (void)hv_stores( hv, "children", (SV*)polynode_children_2_perl(node) ); return (SV*)newRV_noinc((SV*)hv); } SV* polytree2perl(pTHX_ const PolyTree& polytree) { return polynode_children_2_perl(polytree); } ClipperLib::Polygon* perl2polygon(pTHX_ AV* theAv) { const unsigned int len = av_len(theAv)+1; ClipperLib::Polygon* retval = new ClipperLib::Polygon(len); SV** elem; AV* innerav; for (unsigned int i = 0; i < len; i++) { elem = av_fetch(theAv, i, 0); if (!SvROK(*elem) || SvTYPE(SvRV(*elem)) != SVt_PVAV || av_len((AV*)SvRV(*elem)) < 1) { delete retval; return NULL; } innerav = (AV*)SvRV(*elem); ClipperLib::IntPoint& p = (*retval)[i]; // IVSIZE is from perl/lib/CORE/config.h, defined as sizeof(IV) #if IVSIZE >= 8 // if Perl integers are 64 bit, use SvIV() // Clipper.pm then supports 64 bit ints. p.X = (ClipperLib::long64)SvIV(*av_fetch(innerav, 0, 0)); p.Y = (ClipperLib::long64)SvIV(*av_fetch(innerav, 1, 0)); #else // otherwise coerce the Perl scalar to a double, with SvNV() // Perl doubles commonly allow 53 bits for the mantissa. // So in the common case, Clipper.pm supports 53 bit integers, stored in doubles on the Perl side. p.X = (ClipperLib::long64)SvNV(*av_fetch(innerav, 0, 0)); p.Y = (ClipperLib::long64)SvNV(*av_fetch(innerav, 1, 0)); #endif } return retval; } ClipperLib::Polygons* perl2polygons(pTHX_ AV* theAv) { const unsigned int len = av_len(theAv)+1; ClipperLib::Polygons* retval = new ClipperLib::Polygons(len); SV** elem; AV* innerav; for (unsigned int i = 0; i < len; i++) { elem = av_fetch(theAv, i, 0); if (!SvROK(*elem) || SvTYPE(SvRV(*elem)) != SVt_PVAV || av_len((AV*)SvRV(*elem)) < 1) { delete retval; return NULL; } innerav = (AV*)SvRV(*elem); ClipperLib::Polygon* tmp = perl2polygon(aTHX_ innerav); if (tmp == NULL) { delete retval; return NULL; } (*retval)[i] = *tmp; delete tmp; } return retval; } #define AV_CHECK(outav, hv, key) \ STMT_START { \ SV** buf = hv_fetchs(hv, key, 0); \ if (!buf || !*buf) { \ croak("Missing ExPolygon hash key: '" key "' or not an array reference."); \ } \ SvGETMAGIC(*buf); \ if (SvROK(*buf) && SvTYPE(SvRV(*buf)) == SVt_PVAV) { \ outav = (AV*)SvRV(*buf); \ } \ else { \ croak(key " is not an ARRAY reference"); \ } \ } STMT_END ExPolygon* perl2expolygon(pTHX_ HV* theHv) { AV* outerav; AV* holesav; AV_CHECK(outerav, theHv, "outer"); AV_CHECK(holesav, theHv, "holes"); ExPolygon* retval = new ExPolygon(); ClipperLib::Polygon* tmp = perl2polygon(aTHX_ outerav); if (!tmp) { delete retval; return NULL; } retval->outer = *tmp; ClipperLib::Polygons* tmps = perl2polygons(aTHX_ holesav); if (!tmps) { delete retval; return NULL; } retval->holes = *tmps; return retval; } #undef AV_CHECK ExPolygons* perl2expolygons(pTHX_ AV* theAv) { const unsigned int len = av_len(theAv)+1; std::vector tmpEx; // Done because of croak SV** elem; HV* innerhv; for (unsigned int i = 0; i < len; i++) { elem = av_fetch(theAv, i, 0); if (!SvROK(*elem) || SvTYPE(SvRV(*elem)) != SVt_PVHV) return NULL; innerhv = (HV*)SvRV(*elem); ExPolygon* tmp = perl2expolygon(aTHX_ innerhv); if (tmp == NULL) return NULL; tmpEx[i] = *tmp; delete tmp; } ExPolygons* retval = new ExPolygons(tmpEx); return retval; } #endif Math-Clipper-1.29/src/ppport.h000444001750001750 52540613467455703 15502 0ustar00mikemike000000000000#if 0 <<'SKIP'; #endif /* ---------------------------------------------------------------------- ppport.h -- Perl/Pollution/Portability Version 3.19 Automatically created by Devel::PPPort running under perl 5.010000. Do NOT edit this file directly! -- Edit PPPort_pm.PL and the includes in parts/inc/ instead. Use 'perldoc ppport.h' to view the documentation below. ---------------------------------------------------------------------- SKIP =pod =head1 NAME ppport.h - Perl/Pollution/Portability version 3.19 =head1 SYNOPSIS perl ppport.h [options] [source files] Searches current directory for files if no [source files] are given --help show short help --version show version --patch=file write one patch file with changes --copy=suffix write changed copies with suffix --diff=program use diff program and options --compat-version=version provide compatibility with Perl version --cplusplus accept C++ comments --quiet don't output anything except fatal errors --nodiag don't show diagnostics --nohints don't show hints --nochanges don't suggest changes --nofilter don't filter input files --strip strip all script and doc functionality from ppport.h --list-provided list provided API --list-unsupported list unsupported API --api-info=name show Perl API portability information =head1 COMPATIBILITY This version of F is designed to support operation with Perl installations back to 5.003, and has been tested up to 5.10.0. =head1 OPTIONS =head2 --help Display a brief usage summary. =head2 --version Display the version of F. =head2 --patch=I If this option is given, a single patch file will be created if any changes are suggested. This requires a working diff program to be installed on your system. =head2 --copy=I If this option is given, a copy of each file will be saved with the given suffix that contains the suggested changes. This does not require any external programs. Note that this does not automagially add a dot between the original filename and the suffix. If you want the dot, you have to include it in the option argument. If neither C<--patch> or C<--copy> are given, the default is to simply print the diffs for each file. This requires either C or a C program to be installed. =head2 --diff=I Manually set the diff program and options to use. The default is to use C, when installed, and output unified context diffs. =head2 --compat-version=I Tell F to check for compatibility with the given Perl version. The default is to check for compatibility with Perl version 5.003. You can use this option to reduce the output of F if you intend to be backward compatible only down to a certain Perl version. =head2 --cplusplus Usually, F will detect C++ style comments and replace them with C style comments for portability reasons. Using this option instructs F to leave C++ comments untouched. =head2 --quiet Be quiet. Don't print anything except fatal errors. =head2 --nodiag Don't output any diagnostic messages. Only portability alerts will be printed. =head2 --nohints Don't output any hints. Hints often contain useful portability notes. Warnings will still be displayed. =head2 --nochanges Don't suggest any changes. Only give diagnostic output and hints unless these are also deactivated. =head2 --nofilter Don't filter the list of input files. By default, files not looking like source code (i.e. not *.xs, *.c, *.cc, *.cpp or *.h) are skipped. =head2 --strip Strip all script and documentation functionality from F. This reduces the size of F dramatically and may be useful if you want to include F in smaller modules without increasing their distribution size too much. The stripped F will have a C<--unstrip> option that allows you to undo the stripping, but only if an appropriate C module is installed. =head2 --list-provided Lists the API elements for which compatibility is provided by F. Also lists if it must be explicitly requested, if it has dependencies, and if there are hints or warnings for it. =head2 --list-unsupported Lists the API elements that are known not to be supported by F and below which version of Perl they probably won't be available or work. =head2 --api-info=I Show portability information for API elements matching I. If I is surrounded by slashes, it is interpreted as a regular expression. =head1 DESCRIPTION In order for a Perl extension (XS) module to be as portable as possible across differing versions of Perl itself, certain steps need to be taken. =over 4 =item * Including this header is the first major one. This alone will give you access to a large part of the Perl API that hasn't been available in earlier Perl releases. Use perl ppport.h --list-provided to see which API elements are provided by ppport.h. =item * You should avoid using deprecated parts of the API. For example, using global Perl variables without the C prefix is deprecated. Also, some API functions used to have a C prefix. Using this form is also deprecated. You can safely use the supported API, as F will provide wrappers for older Perl versions. =item * If you use one of a few functions or variables that were not present in earlier versions of Perl, and that can't be provided using a macro, you have to explicitly request support for these functions by adding one or more C<#define>s in your source code before the inclusion of F. These functions or variables will be marked C in the list shown by C<--list-provided>. Depending on whether you module has a single or multiple files that use such functions or variables, you want either C or global variants. For a C function or variable (used only in a single source file), use: #define NEED_function #define NEED_variable For a global function or variable (used in multiple source files), use: #define NEED_function_GLOBAL #define NEED_variable_GLOBAL Note that you mustn't have more than one global request for the same function or variable in your project. Function / Variable Static Request Global Request ----------------------------------------------------------------------------------------- PL_parser NEED_PL_parser NEED_PL_parser_GLOBAL PL_signals NEED_PL_signals NEED_PL_signals_GLOBAL eval_pv() NEED_eval_pv NEED_eval_pv_GLOBAL grok_bin() NEED_grok_bin NEED_grok_bin_GLOBAL grok_hex() NEED_grok_hex NEED_grok_hex_GLOBAL grok_number() NEED_grok_number NEED_grok_number_GLOBAL grok_numeric_radix() NEED_grok_numeric_radix NEED_grok_numeric_radix_GLOBAL grok_oct() NEED_grok_oct NEED_grok_oct_GLOBAL load_module() NEED_load_module NEED_load_module_GLOBAL my_snprintf() NEED_my_snprintf NEED_my_snprintf_GLOBAL my_sprintf() NEED_my_sprintf NEED_my_sprintf_GLOBAL my_strlcat() NEED_my_strlcat NEED_my_strlcat_GLOBAL my_strlcpy() NEED_my_strlcpy NEED_my_strlcpy_GLOBAL newCONSTSUB() NEED_newCONSTSUB NEED_newCONSTSUB_GLOBAL newRV_noinc() NEED_newRV_noinc NEED_newRV_noinc_GLOBAL newSV_type() NEED_newSV_type NEED_newSV_type_GLOBAL newSVpvn_flags() NEED_newSVpvn_flags NEED_newSVpvn_flags_GLOBAL newSVpvn_share() NEED_newSVpvn_share NEED_newSVpvn_share_GLOBAL pv_display() NEED_pv_display NEED_pv_display_GLOBAL pv_escape() NEED_pv_escape NEED_pv_escape_GLOBAL pv_pretty() NEED_pv_pretty NEED_pv_pretty_GLOBAL sv_2pv_flags() NEED_sv_2pv_flags NEED_sv_2pv_flags_GLOBAL sv_2pvbyte() NEED_sv_2pvbyte NEED_sv_2pvbyte_GLOBAL sv_catpvf_mg() NEED_sv_catpvf_mg NEED_sv_catpvf_mg_GLOBAL sv_catpvf_mg_nocontext() NEED_sv_catpvf_mg_nocontext NEED_sv_catpvf_mg_nocontext_GLOBAL sv_pvn_force_flags() NEED_sv_pvn_force_flags NEED_sv_pvn_force_flags_GLOBAL sv_setpvf_mg() NEED_sv_setpvf_mg NEED_sv_setpvf_mg_GLOBAL sv_setpvf_mg_nocontext() NEED_sv_setpvf_mg_nocontext NEED_sv_setpvf_mg_nocontext_GLOBAL vload_module() NEED_vload_module NEED_vload_module_GLOBAL vnewSVpvf() NEED_vnewSVpvf NEED_vnewSVpvf_GLOBAL warner() NEED_warner NEED_warner_GLOBAL To avoid namespace conflicts, you can change the namespace of the explicitly exported functions / variables using the C macro. Just C<#define> the macro before including C: #define DPPP_NAMESPACE MyOwnNamespace_ #include "ppport.h" The default namespace is C. =back The good thing is that most of the above can be checked by running F on your source code. See the next section for details. =head1 EXAMPLES To verify whether F is needed for your module, whether you should make any changes to your code, and whether any special defines should be used, F can be run as a Perl script to check your source code. Simply say: perl ppport.h The result will usually be a list of patches suggesting changes that should at least be acceptable, if not necessarily the most efficient solution, or a fix for all possible problems. If you know that your XS module uses features only available in newer Perl releases, if you're aware that it uses C++ comments, and if you want all suggestions as a single patch file, you could use something like this: perl ppport.h --compat-version=5.6.0 --cplusplus --patch=test.diff If you only want your code to be scanned without any suggestions for changes, use: perl ppport.h --nochanges You can specify a different C program or options, using the C<--diff> option: perl ppport.h --diff='diff -C 10' This would output context diffs with 10 lines of context. If you want to create patched copies of your files instead, use: perl ppport.h --copy=.new To display portability information for the C function, use: perl ppport.h --api-info=newSVpvn Since the argument to C<--api-info> can be a regular expression, you can use perl ppport.h --api-info=/_nomg$/ to display portability information for all C<_nomg> functions or perl ppport.h --api-info=/./ to display information for all known API elements. =head1 BUGS If this version of F is causing failure during the compilation of this module, please check if newer versions of either this module or C are available on CPAN before sending a bug report. If F was generated using the latest version of C and is causing failure of this module, please file a bug report using the CPAN Request Tracker at L. Please include the following information: =over 4 =item 1. The complete output from running "perl -V" =item 2. This file. =item 3. The name and version of the module you were trying to build. =item 4. A full log of the build that failed. =item 5. Any other information that you think could be relevant. =back For the latest version of this code, please get the C module from CPAN. =head1 COPYRIGHT Version 3.x, Copyright (c) 2004-2009, Marcus Holland-Moritz. Version 2.x, Copyright (C) 2001, Paul Marquess. Version 1.x, Copyright (C) 1999, Kenneth Albanowski. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO See L. =cut use strict; # Disable broken TRIE-optimization BEGIN { eval '${^RE_TRIE_MAXBUF} = -1' if $] >= 5.009004 && $] <= 5.009005 } my $VERSION = 3.19; my %opt = ( quiet => 0, diag => 1, hints => 1, changes => 1, cplusplus => 0, filter => 1, strip => 0, version => 0, ); my($ppport) = $0 =~ /([\w.]+)$/; my $LF = '(?:\r\n|[\r\n])'; # line feed my $HS = "[ \t]"; # horizontal whitespace # Never use C comments in this file! my $ccs = '/'.'*'; my $cce = '*'.'/'; my $rccs = quotemeta $ccs; my $rcce = quotemeta $cce; eval { require Getopt::Long; Getopt::Long::GetOptions(\%opt, qw( help quiet diag! filter! hints! changes! cplusplus strip version patch=s copy=s diff=s compat-version=s list-provided list-unsupported api-info=s )) or usage(); }; if ($@ and grep /^-/, @ARGV) { usage() if "@ARGV" =~ /^--?h(?:elp)?$/; die "Getopt::Long not found. Please don't use any options.\n"; } if ($opt{version}) { print "This is $0 $VERSION.\n"; exit 0; } usage() if $opt{help}; strip() if $opt{strip}; if (exists $opt{'compat-version'}) { my($r,$v,$s) = eval { parse_version($opt{'compat-version'}) }; if ($@) { die "Invalid version number format: '$opt{'compat-version'}'\n"; } die "Only Perl 5 is supported\n" if $r != 5; die "Invalid version number: $opt{'compat-version'}\n" if $v >= 1000 || $s >= 1000; $opt{'compat-version'} = sprintf "%d.%03d%03d", $r, $v, $s; } else { $opt{'compat-version'} = 5; } my %API = map { /^(\w+)\|([^|]*)\|([^|]*)\|(\w*)$/ ? ( $1 => { ($2 ? ( base => $2 ) : ()), ($3 ? ( todo => $3 ) : ()), (index($4, 'v') >= 0 ? ( varargs => 1 ) : ()), (index($4, 'p') >= 0 ? ( provided => 1 ) : ()), (index($4, 'n') >= 0 ? ( nothxarg => 1 ) : ()), } ) : die "invalid spec: $_" } qw( AvFILLp|5.004050||p AvFILL||| CLASS|||n CPERLscope|5.005000||p CX_CURPAD_SAVE||| CX_CURPAD_SV||| CopFILEAV|5.006000||p CopFILEGV_set|5.006000||p CopFILEGV|5.006000||p CopFILESV|5.006000||p CopFILE_set|5.006000||p CopFILE|5.006000||p CopSTASHPV_set|5.006000||p CopSTASHPV|5.006000||p CopSTASH_eq|5.006000||p CopSTASH_set|5.006000||p CopSTASH|5.006000||p CopyD|5.009002||p Copy||| CvPADLIST||| CvSTASH||| CvWEAKOUTSIDE||| DEFSV_set|5.011000||p DEFSV|5.004050||p END_EXTERN_C|5.005000||p ENTER||| ERRSV|5.004050||p EXTEND||| EXTERN_C|5.005000||p F0convert|||n FREETMPS||| GIMME_V||5.004000|n GIMME|||n GROK_NUMERIC_RADIX|5.007002||p G_ARRAY||| G_DISCARD||| G_EVAL||| G_METHOD|5.006001||p G_NOARGS||| G_SCALAR||| G_VOID||5.004000| GetVars||| GvSVn|5.009003||p GvSV||| Gv_AMupdate||| HEf_SVKEY||5.004000| HeHASH||5.004000| HeKEY||5.004000| HeKLEN||5.004000| HePV||5.004000| HeSVKEY_force||5.004000| HeSVKEY_set||5.004000| HeSVKEY||5.004000| HeUTF8||5.011000| HeVAL||5.004000| HvNAMELEN_get|5.009003||p HvNAME_get|5.009003||p HvNAME||| INT2PTR|5.006000||p IN_LOCALE_COMPILETIME|5.007002||p IN_LOCALE_RUNTIME|5.007002||p IN_LOCALE|5.007002||p IN_PERL_COMPILETIME|5.008001||p IS_NUMBER_GREATER_THAN_UV_MAX|5.007002||p IS_NUMBER_INFINITY|5.007002||p IS_NUMBER_IN_UV|5.007002||p IS_NUMBER_NAN|5.007003||p IS_NUMBER_NEG|5.007002||p IS_NUMBER_NOT_INT|5.007002||p IVSIZE|5.006000||p IVTYPE|5.006000||p IVdf|5.006000||p LEAVE||| LVRET||| MARK||| MULTICALL||5.011000| MY_CXT_CLONE|5.009002||p MY_CXT_INIT|5.007003||p MY_CXT|5.007003||p MoveD|5.009002||p Move||| NOOP|5.005000||p NUM2PTR|5.006000||p NVTYPE|5.006000||p NVef|5.006001||p NVff|5.006001||p NVgf|5.006001||p Newxc|5.009003||p Newxz|5.009003||p Newx|5.009003||p Nullav||| Nullch||| Nullcv||| Nullhv||| Nullsv||| ORIGMARK||| PAD_BASE_SV||| PAD_CLONE_VARS||| PAD_COMPNAME_FLAGS||| PAD_COMPNAME_GEN_set||| PAD_COMPNAME_GEN||| PAD_COMPNAME_OURSTASH||| PAD_COMPNAME_PV||| PAD_COMPNAME_TYPE||| PAD_DUP||| PAD_RESTORE_LOCAL||| PAD_SAVE_LOCAL||| PAD_SAVE_SETNULLPAD||| PAD_SETSV||| PAD_SET_CUR_NOSAVE||| PAD_SET_CUR||| PAD_SVl||| PAD_SV||| PERLIO_FUNCS_CAST|5.009003||p PERLIO_FUNCS_DECL|5.009003||p PERL_ABS|5.008001||p PERL_BCDVERSION|5.011000||p PERL_GCC_BRACE_GROUPS_FORBIDDEN|5.008001||p PERL_HASH|5.004000||p PERL_INT_MAX|5.004000||p PERL_INT_MIN|5.004000||p PERL_LONG_MAX|5.004000||p PERL_LONG_MIN|5.004000||p PERL_MAGIC_arylen|5.007002||p PERL_MAGIC_backref|5.007002||p PERL_MAGIC_bm|5.007002||p PERL_MAGIC_collxfrm|5.007002||p PERL_MAGIC_dbfile|5.007002||p PERL_MAGIC_dbline|5.007002||p PERL_MAGIC_defelem|5.007002||p PERL_MAGIC_envelem|5.007002||p PERL_MAGIC_env|5.007002||p PERL_MAGIC_ext|5.007002||p PERL_MAGIC_fm|5.007002||p PERL_MAGIC_glob|5.011000||p PERL_MAGIC_isaelem|5.007002||p PERL_MAGIC_isa|5.007002||p PERL_MAGIC_mutex|5.011000||p PERL_MAGIC_nkeys|5.007002||p PERL_MAGIC_overload_elem|5.007002||p PERL_MAGIC_overload_table|5.007002||p PERL_MAGIC_overload|5.007002||p PERL_MAGIC_pos|5.007002||p PERL_MAGIC_qr|5.007002||p PERL_MAGIC_regdata|5.007002||p PERL_MAGIC_regdatum|5.007002||p PERL_MAGIC_regex_global|5.007002||p PERL_MAGIC_shared_scalar|5.007003||p PERL_MAGIC_shared|5.007003||p PERL_MAGIC_sigelem|5.007002||p PERL_MAGIC_sig|5.007002||p PERL_MAGIC_substr|5.007002||p PERL_MAGIC_sv|5.007002||p PERL_MAGIC_taint|5.007002||p PERL_MAGIC_tiedelem|5.007002||p PERL_MAGIC_tiedscalar|5.007002||p PERL_MAGIC_tied|5.007002||p PERL_MAGIC_utf8|5.008001||p PERL_MAGIC_uvar_elem|5.007003||p PERL_MAGIC_uvar|5.007002||p PERL_MAGIC_vec|5.007002||p PERL_MAGIC_vstring|5.008001||p PERL_PV_ESCAPE_ALL|5.009004||p PERL_PV_ESCAPE_FIRSTCHAR|5.009004||p PERL_PV_ESCAPE_NOBACKSLASH|5.009004||p PERL_PV_ESCAPE_NOCLEAR|5.009004||p PERL_PV_ESCAPE_QUOTE|5.009004||p PERL_PV_ESCAPE_RE|5.009005||p PERL_PV_ESCAPE_UNI_DETECT|5.009004||p PERL_PV_ESCAPE_UNI|5.009004||p PERL_PV_PRETTY_DUMP|5.009004||p PERL_PV_PRETTY_ELLIPSES|5.010000||p PERL_PV_PRETTY_LTGT|5.009004||p PERL_PV_PRETTY_NOCLEAR|5.010000||p PERL_PV_PRETTY_QUOTE|5.009004||p PERL_PV_PRETTY_REGPROP|5.009004||p PERL_QUAD_MAX|5.004000||p PERL_QUAD_MIN|5.004000||p PERL_REVISION|5.006000||p PERL_SCAN_ALLOW_UNDERSCORES|5.007003||p PERL_SCAN_DISALLOW_PREFIX|5.007003||p PERL_SCAN_GREATER_THAN_UV_MAX|5.007003||p PERL_SCAN_SILENT_ILLDIGIT|5.008001||p PERL_SHORT_MAX|5.004000||p PERL_SHORT_MIN|5.004000||p PERL_SIGNALS_UNSAFE_FLAG|5.008001||p PERL_SUBVERSION|5.006000||p PERL_SYS_INIT3||5.006000| PERL_SYS_INIT||| PERL_SYS_TERM||5.011000| PERL_UCHAR_MAX|5.004000||p PERL_UCHAR_MIN|5.004000||p PERL_UINT_MAX|5.004000||p PERL_UINT_MIN|5.004000||p PERL_ULONG_MAX|5.004000||p PERL_ULONG_MIN|5.004000||p PERL_UNUSED_ARG|5.009003||p PERL_UNUSED_CONTEXT|5.009004||p PERL_UNUSED_DECL|5.007002||p PERL_UNUSED_VAR|5.007002||p PERL_UQUAD_MAX|5.004000||p PERL_UQUAD_MIN|5.004000||p PERL_USE_GCC_BRACE_GROUPS|5.009004||p PERL_USHORT_MAX|5.004000||p PERL_USHORT_MIN|5.004000||p PERL_VERSION|5.006000||p PL_DBsignal|5.005000||p PL_DBsingle|||pn PL_DBsub|||pn PL_DBtrace|||pn PL_Sv|5.005000||p PL_bufend|5.011000||p PL_bufptr|5.011000||p PL_compiling|5.004050||p PL_copline|5.011000||p PL_curcop|5.004050||p PL_curstash|5.004050||p PL_debstash|5.004050||p PL_defgv|5.004050||p PL_diehook|5.004050||p PL_dirty|5.004050||p PL_dowarn|||pn PL_errgv|5.004050||p PL_error_count|5.011000||p PL_expect|5.011000||p PL_hexdigit|5.005000||p PL_hints|5.005000||p PL_in_my_stash|5.011000||p PL_in_my|5.011000||p PL_last_in_gv|||n PL_laststatval|5.005000||p PL_lex_state|5.011000||p PL_lex_stuff|5.011000||p PL_linestr|5.011000||p PL_modglobal||5.005000|n PL_na|5.004050||pn PL_no_modify|5.006000||p PL_ofsgv|||n PL_parser|5.009005||p PL_perl_destruct_level|5.004050||p PL_perldb|5.004050||p PL_ppaddr|5.006000||p PL_rsfp_filters|5.004050||p PL_rsfp|5.004050||p PL_rs|||n PL_signals|5.008001||p PL_stack_base|5.004050||p PL_stack_sp|5.004050||p PL_statcache|5.005000||p PL_stdingv|5.004050||p PL_sv_arenaroot|5.004050||p PL_sv_no|5.004050||pn PL_sv_undef|5.004050||pn PL_sv_yes|5.004050||pn PL_tainted|5.004050||p PL_tainting|5.004050||p PL_tokenbuf|5.011000||p POP_MULTICALL||5.011000| POPi|||n POPl|||n POPn|||n POPpbytex||5.007001|n POPpx||5.005030|n POPp|||n POPs|||n PTR2IV|5.006000||p PTR2NV|5.006000||p PTR2UV|5.006000||p PTR2nat|5.009003||p PTR2ul|5.007001||p PTRV|5.006000||p PUSHMARK||| PUSH_MULTICALL||5.011000| PUSHi||| PUSHmortal|5.009002||p PUSHn||| PUSHp||| PUSHs||| PUSHu|5.004000||p PUTBACK||| PerlIO_clearerr||5.007003| PerlIO_close||5.007003| PerlIO_context_layers||5.009004| PerlIO_eof||5.007003| PerlIO_error||5.007003| PerlIO_fileno||5.007003| PerlIO_fill||5.007003| PerlIO_flush||5.007003| PerlIO_get_base||5.007003| PerlIO_get_bufsiz||5.007003| PerlIO_get_cnt||5.007003| PerlIO_get_ptr||5.007003| PerlIO_read||5.007003| PerlIO_seek||5.007003| PerlIO_set_cnt||5.007003| PerlIO_set_ptrcnt||5.007003| PerlIO_setlinebuf||5.007003| PerlIO_stderr||5.007003| PerlIO_stdin||5.007003| PerlIO_stdout||5.007003| PerlIO_tell||5.007003| PerlIO_unread||5.007003| PerlIO_write||5.007003| Perl_signbit||5.009005|n PoisonFree|5.009004||p PoisonNew|5.009004||p PoisonWith|5.009004||p Poison|5.008000||p RETVAL|||n Renewc||| Renew||| SAVECLEARSV||| SAVECOMPPAD||| SAVEPADSV||| SAVETMPS||| SAVE_DEFSV|5.004050||p SPAGAIN||| SP||| START_EXTERN_C|5.005000||p START_MY_CXT|5.007003||p STMT_END|||p STMT_START|||p STR_WITH_LEN|5.009003||p ST||| SV_CONST_RETURN|5.009003||p SV_COW_DROP_PV|5.008001||p SV_COW_SHARED_HASH_KEYS|5.009005||p SV_GMAGIC|5.007002||p SV_HAS_TRAILING_NUL|5.009004||p SV_IMMEDIATE_UNREF|5.007001||p SV_MUTABLE_RETURN|5.009003||p SV_NOSTEAL|5.009002||p SV_SMAGIC|5.009003||p SV_UTF8_NO_ENCODING|5.008001||p SVfARG|5.009005||p SVf_UTF8|5.006000||p SVf|5.006000||p SVt_IV||| SVt_NV||| SVt_PVAV||| SVt_PVCV||| SVt_PVHV||| SVt_PVMG||| SVt_PV||| Safefree||| Slab_Alloc||| Slab_Free||| Slab_to_rw||| StructCopy||| SvCUR_set||| SvCUR||| SvEND||| SvGAMAGIC||5.006001| SvGETMAGIC|5.004050||p SvGROW||| SvIOK_UV||5.006000| SvIOK_notUV||5.006000| SvIOK_off||| SvIOK_only_UV||5.006000| SvIOK_only||| SvIOK_on||| SvIOKp||| SvIOK||| SvIVX||| SvIV_nomg|5.009001||p SvIV_set||| SvIVx||| SvIV||| SvIsCOW_shared_hash||5.008003| SvIsCOW||5.008003| SvLEN_set||| SvLEN||| SvLOCK||5.007003| SvMAGIC_set|5.009003||p SvNIOK_off||| SvNIOKp||| SvNIOK||| SvNOK_off||| SvNOK_only||| SvNOK_on||| SvNOKp||| SvNOK||| SvNVX||| SvNV_set||| SvNVx||| SvNV||| SvOK||| SvOOK_offset||5.011000| SvOOK||| SvPOK_off||| SvPOK_only_UTF8||5.006000| SvPOK_only||| SvPOK_on||| SvPOKp||| SvPOK||| SvPVX_const|5.009003||p SvPVX_mutable|5.009003||p SvPVX||| SvPV_const|5.009003||p SvPV_flags_const_nolen|5.009003||p SvPV_flags_const|5.009003||p SvPV_flags_mutable|5.009003||p SvPV_flags|5.007002||p SvPV_force_flags_mutable|5.009003||p SvPV_force_flags_nolen|5.009003||p SvPV_force_flags|5.007002||p SvPV_force_mutable|5.009003||p SvPV_force_nolen|5.009003||p SvPV_force_nomg_nolen|5.009003||p SvPV_force_nomg|5.007002||p SvPV_force|||p SvPV_mutable|5.009003||p SvPV_nolen_const|5.009003||p SvPV_nolen|5.006000||p SvPV_nomg_const_nolen|5.009003||p SvPV_nomg_const|5.009003||p SvPV_nomg|5.007002||p SvPV_renew|5.009003||p SvPV_set||| SvPVbyte_force||5.009002| SvPVbyte_nolen||5.006000| SvPVbytex_force||5.006000| SvPVbytex||5.006000| SvPVbyte|5.006000||p SvPVutf8_force||5.006000| SvPVutf8_nolen||5.006000| SvPVutf8x_force||5.006000| SvPVutf8x||5.006000| SvPVutf8||5.006000| SvPVx||| SvPV||| SvREFCNT_dec||| SvREFCNT_inc_NN|5.009004||p SvREFCNT_inc_simple_NN|5.009004||p SvREFCNT_inc_simple_void_NN|5.009004||p SvREFCNT_inc_simple_void|5.009004||p SvREFCNT_inc_simple|5.009004||p SvREFCNT_inc_void_NN|5.009004||p SvREFCNT_inc_void|5.009004||p SvREFCNT_inc|||p SvREFCNT||| SvROK_off||| SvROK_on||| SvROK||| SvRV_set|5.009003||p SvRV||| SvRXOK||5.009005| SvRX||5.009005| SvSETMAGIC||| SvSHARED_HASH|5.009003||p SvSHARE||5.007003| SvSTASH_set|5.009003||p SvSTASH||| SvSetMagicSV_nosteal||5.004000| SvSetMagicSV||5.004000| SvSetSV_nosteal||5.004000| SvSetSV||| SvTAINTED_off||5.004000| SvTAINTED_on||5.004000| SvTAINTED||5.004000| SvTAINT||| SvTRUE||| SvTYPE||| SvUNLOCK||5.007003| SvUOK|5.007001|5.006000|p SvUPGRADE||| SvUTF8_off||5.006000| SvUTF8_on||5.006000| SvUTF8||5.006000| SvUVXx|5.004000||p SvUVX|5.004000||p SvUV_nomg|5.009001||p SvUV_set|5.009003||p SvUVx|5.004000||p SvUV|5.004000||p SvVOK||5.008001| SvVSTRING_mg|5.009004||p THIS|||n UNDERBAR|5.009002||p UTF8_MAXBYTES|5.009002||p UVSIZE|5.006000||p UVTYPE|5.006000||p UVXf|5.007001||p UVof|5.006000||p UVuf|5.006000||p UVxf|5.006000||p WARN_ALL|5.006000||p WARN_AMBIGUOUS|5.006000||p WARN_ASSERTIONS|5.011000||p WARN_BAREWORD|5.006000||p WARN_CLOSED|5.006000||p WARN_CLOSURE|5.006000||p WARN_DEBUGGING|5.006000||p WARN_DEPRECATED|5.006000||p WARN_DIGIT|5.006000||p WARN_EXEC|5.006000||p WARN_EXITING|5.006000||p WARN_GLOB|5.006000||p WARN_INPLACE|5.006000||p WARN_INTERNAL|5.006000||p WARN_IO|5.006000||p WARN_LAYER|5.008000||p WARN_MALLOC|5.006000||p WARN_MISC|5.006000||p WARN_NEWLINE|5.006000||p WARN_NUMERIC|5.006000||p WARN_ONCE|5.006000||p WARN_OVERFLOW|5.006000||p WARN_PACK|5.006000||p WARN_PARENTHESIS|5.006000||p WARN_PIPE|5.006000||p WARN_PORTABLE|5.006000||p WARN_PRECEDENCE|5.006000||p WARN_PRINTF|5.006000||p WARN_PROTOTYPE|5.006000||p WARN_QW|5.006000||p WARN_RECURSION|5.006000||p WARN_REDEFINE|5.006000||p WARN_REGEXP|5.006000||p WARN_RESERVED|5.006000||p WARN_SEMICOLON|5.006000||p WARN_SEVERE|5.006000||p WARN_SIGNAL|5.006000||p WARN_SUBSTR|5.006000||p WARN_SYNTAX|5.006000||p WARN_TAINT|5.006000||p WARN_THREADS|5.008000||p WARN_UNINITIALIZED|5.006000||p WARN_UNOPENED|5.006000||p WARN_UNPACK|5.006000||p WARN_UNTIE|5.006000||p WARN_UTF8|5.006000||p WARN_VOID|5.006000||p XCPT_CATCH|5.009002||p XCPT_RETHROW|5.009002||p XCPT_TRY_END|5.009002||p XCPT_TRY_START|5.009002||p XPUSHi||| XPUSHmortal|5.009002||p XPUSHn||| XPUSHp||| XPUSHs||| XPUSHu|5.004000||p XSPROTO|5.010000||p XSRETURN_EMPTY||| XSRETURN_IV||| XSRETURN_NO||| XSRETURN_NV||| XSRETURN_PV||| XSRETURN_UNDEF||| XSRETURN_UV|5.008001||p XSRETURN_YES||| XSRETURN|||p XST_mIV||| XST_mNO||| XST_mNV||| XST_mPV||| XST_mUNDEF||| XST_mUV|5.008001||p XST_mYES||| XS_VERSION_BOOTCHECK||| XS_VERSION||| XSprePUSH|5.006000||p XS||| ZeroD|5.009002||p Zero||| _aMY_CXT|5.007003||p _pMY_CXT|5.007003||p aMY_CXT_|5.007003||p aMY_CXT|5.007003||p aTHXR_|5.011000||p aTHXR|5.011000||p aTHX_|5.006000||p aTHX|5.006000||p add_data|||n addmad||| allocmy||| amagic_call||| amagic_cmp_locale||| amagic_cmp||| amagic_i_ncmp||| amagic_ncmp||| any_dup||| ao||| append_elem||| append_list||| append_madprops||| apply_attrs_my||| apply_attrs_string||5.006001| apply_attrs||| apply||| atfork_lock||5.007003|n atfork_unlock||5.007003|n av_arylen_p||5.009003| av_clear||| av_create_and_push||5.009005| av_create_and_unshift_one||5.009005| av_delete||5.006000| av_exists||5.006000| av_extend||| av_fetch||| av_fill||| av_iter_p||5.011000| av_len||| av_make||| av_pop||| av_push||| av_reify||| av_shift||| av_store||| av_undef||| av_unshift||| ax|||n bad_type||| bind_match||| block_end||| block_gimme||5.004000| block_start||| boolSV|5.004000||p boot_core_PerlIO||| boot_core_UNIVERSAL||| boot_core_mro||| bytes_from_utf8||5.007001| bytes_to_uni|||n bytes_to_utf8||5.006001| call_argv|5.006000||p call_atexit||5.006000| call_list||5.004000| call_method|5.006000||p call_pv|5.006000||p call_sv|5.006000||p calloc||5.007002|n cando||| cast_i32||5.006000| cast_iv||5.006000| cast_ulong||5.006000| cast_uv||5.006000| check_type_and_open||| check_uni||| checkcomma||| checkposixcc||| ckWARN|5.006000||p ck_anoncode||| ck_bitop||| ck_concat||| ck_defined||| ck_delete||| ck_die||| ck_each||| ck_eof||| ck_eval||| ck_exec||| ck_exists||| ck_exit||| ck_ftst||| ck_fun||| ck_glob||| ck_grep||| ck_index||| ck_join||| ck_lfun||| ck_listiob||| ck_match||| ck_method||| ck_null||| ck_open||| ck_readline||| ck_repeat||| ck_require||| ck_return||| ck_rfun||| ck_rvconst||| ck_sassign||| ck_select||| ck_shift||| ck_sort||| ck_spair||| ck_split||| ck_subr||| ck_substr||| ck_svconst||| ck_trunc||| ck_unpack||| ckwarn_d||5.009003| ckwarn||5.009003| cl_and|||n cl_anything|||n cl_init_zero|||n cl_init|||n cl_is_anything|||n cl_or|||n clear_placeholders||| closest_cop||| convert||| cop_free||| cr_textfilter||| create_eval_scope||| croak_nocontext|||vn croak_xs_usage||5.011000| croak|||v csighandler||5.009003|n curmad||| custom_op_desc||5.007003| custom_op_name||5.007003| cv_ckproto_len||| cv_clone||| cv_const_sv||5.004000| cv_dump||| cv_undef||| cx_dump||5.005000| cx_dup||| cxinc||| dAXMARK|5.009003||p dAX|5.007002||p dITEMS|5.007002||p dMARK||| dMULTICALL||5.009003| dMY_CXT_SV|5.007003||p dMY_CXT|5.007003||p dNOOP|5.006000||p dORIGMARK||| dSP||| dTHR|5.004050||p dTHXR|5.011000||p dTHXa|5.006000||p dTHXoa|5.006000||p dTHX|5.006000||p dUNDERBAR|5.009002||p dVAR|5.009003||p dXCPT|5.009002||p dXSARGS||| dXSI32||| dXSTARG|5.006000||p deb_curcv||| deb_nocontext|||vn deb_stack_all||| deb_stack_n||| debop||5.005000| debprofdump||5.005000| debprof||| debstackptrs||5.007003| debstack||5.007003| debug_start_match||| deb||5.007003|v del_sv||| delete_eval_scope||| delimcpy||5.004000| deprecate_old||| deprecate||| despatch_signals||5.007001| destroy_matcher||| die_nocontext|||vn die_where||| die|||v dirp_dup||| div128||| djSP||| do_aexec5||| do_aexec||| do_aspawn||| do_binmode||5.004050| do_chomp||| do_chop||| do_close||| do_dump_pad||| do_eof||| do_exec3||| do_execfree||| do_exec||| do_gv_dump||5.006000| do_gvgv_dump||5.006000| do_hv_dump||5.006000| do_ipcctl||| do_ipcget||| do_join||| do_kv||| do_magic_dump||5.006000| do_msgrcv||| do_msgsnd||| do_oddball||| do_op_dump||5.006000| do_op_xmldump||| do_open9||5.006000| do_openn||5.007001| do_open||5.004000| do_pmop_dump||5.006000| do_pmop_xmldump||| do_print||| do_readline||| do_seek||| do_semop||| do_shmio||| do_smartmatch||| do_spawn_nowait||| do_spawn||| do_sprintf||| do_sv_dump||5.006000| do_sysseek||| do_tell||| do_trans_complex_utf8||| do_trans_complex||| do_trans_count_utf8||| do_trans_count||| do_trans_simple_utf8||| do_trans_simple||| do_trans||| do_vecget||| do_vecset||| do_vop||| docatch||| doeval||| dofile||| dofindlabel||| doform||| doing_taint||5.008001|n dooneliner||| doopen_pm||| doparseform||| dopoptoeval||| dopoptogiven||| dopoptolabel||| dopoptoloop||| dopoptosub_at||| dopoptowhen||| doref||5.009003| dounwind||| dowantarray||| dump_all||5.006000| dump_eval||5.006000| dump_exec_pos||| dump_fds||| dump_form||5.006000| dump_indent||5.006000|v dump_mstats||| dump_packsubs||5.006000| dump_sub||5.006000| dump_sv_child||| dump_trie_interim_list||| dump_trie_interim_table||| dump_trie||| dump_vindent||5.006000| dumpuntil||| dup_attrlist||| emulate_cop_io||| eval_pv|5.006000||p eval_sv|5.006000||p exec_failed||| expect_number||| fbm_compile||5.005000| fbm_instr||5.005000| feature_is_enabled||| fetch_cop_label||5.011000| filter_add||| filter_del||| filter_gets||| filter_read||| find_and_forget_pmops||| find_array_subscript||| find_beginning||| find_byclass||| find_hash_subscript||| find_in_my_stash||| find_runcv||5.008001| find_rundefsvoffset||5.009002| find_script||| find_uninit_var||| first_symbol|||n fold_constants||| forbid_setid||| force_ident||| force_list||| force_next||| force_version||| force_word||| forget_pmop||| form_nocontext|||vn form||5.004000|v fp_dup||| fprintf_nocontext|||vn free_global_struct||| free_tied_hv_pool||| free_tmps||| gen_constant_list||| get_arena||| get_aux_mg||| get_av|5.006000||p get_context||5.006000|n get_cvn_flags||5.009005| get_cv|5.006000||p get_db_sub||| get_debug_opts||| get_hash_seed||| get_hv|5.006000||p get_isa_hash||| get_mstats||| get_no_modify||| get_num||| get_op_descs||5.005000| get_op_names||5.005000| get_opargs||| get_ppaddr||5.006000| get_re_arg||| get_sv|5.006000||p get_vtbl||5.005030| getcwd_sv||5.007002| getenv_len||| glob_2number||| glob_assign_glob||| glob_assign_ref||| gp_dup||| gp_free||| gp_ref||| grok_bin|5.007003||p grok_hex|5.007003||p grok_number|5.007002||p grok_numeric_radix|5.007002||p grok_oct|5.007003||p group_end||| gv_AVadd||| gv_HVadd||| gv_IOadd||| gv_SVadd||| gv_autoload4||5.004000| gv_check||| gv_const_sv||5.009003| gv_dump||5.006000| gv_efullname3||5.004000| gv_efullname4||5.006001| gv_efullname||| gv_ename||| gv_fetchfile_flags||5.009005| gv_fetchfile||| gv_fetchmeth_autoload||5.007003| gv_fetchmethod_autoload||5.004000| gv_fetchmethod_flags||5.011000| gv_fetchmethod||| gv_fetchmeth||| gv_fetchpvn_flags|5.009002||p gv_fetchpvs|5.009004||p gv_fetchpv||| gv_fetchsv||5.009002| gv_fullname3||5.004000| gv_fullname4||5.006001| gv_fullname||| gv_get_super_pkg||| gv_handler||5.007001| gv_init_sv||| gv_init||| gv_name_set||5.009004| gv_stashpvn|5.004000||p gv_stashpvs|5.009003||p gv_stashpv||| gv_stashsv||| he_dup||| hek_dup||| hfreeentries||| hsplit||| hv_assert||5.011000| hv_auxinit|||n hv_backreferences_p||| hv_clear_placeholders||5.009001| hv_clear||| hv_common_key_len||5.010000| hv_common||5.010000| hv_copy_hints_hv||| hv_delayfree_ent||5.004000| hv_delete_common||| hv_delete_ent||5.004000| hv_delete||| hv_eiter_p||5.009003| hv_eiter_set||5.009003| hv_exists_ent||5.004000| hv_exists||| hv_fetch_ent||5.004000| hv_fetchs|5.009003||p hv_fetch||| hv_free_ent||5.004000| hv_iterinit||| hv_iterkeysv||5.004000| hv_iterkey||| hv_iternext_flags||5.008000| hv_iternextsv||| hv_iternext||| hv_iterval||| hv_kill_backrefs||| hv_ksplit||5.004000| hv_magic_check|||n hv_magic||| hv_name_set||5.009003| hv_notallowed||| hv_placeholders_get||5.009003| hv_placeholders_p||5.009003| hv_placeholders_set||5.009003| hv_riter_p||5.009003| hv_riter_set||5.009003| hv_scalar||5.009001| hv_store_ent||5.004000| hv_store_flags||5.008000| hv_stores|5.009004||p hv_store||| hv_undef||| ibcmp_locale||5.004000| ibcmp_utf8||5.007003| ibcmp||| incline||| incpush_if_exists||| incpush_use_sep||| incpush||| ingroup||| init_argv_symbols||| init_debugger||| init_global_struct||| init_i18nl10n||5.006000| init_i18nl14n||5.006000| init_ids||| init_interp||| init_main_stash||| init_perllib||| init_postdump_symbols||| init_predump_symbols||| init_stacks||5.005000| init_tm||5.007002| instr||| intro_my||| intuit_method||| intuit_more||| invert||| io_close||| isALNUMC|5.006000||p isALNUM||| isALPHA||| isASCII|5.006000||p isBLANK|5.006001||p isCNTRL|5.006000||p isDIGIT||| isGRAPH|5.006000||p isGV_with_GP|5.009004||p isLOWER||| isPRINT|5.004000||p isPSXSPC|5.006001||p isPUNCT|5.006000||p isSPACE||| isUPPER||| isXDIGIT|5.006000||p is_an_int||| is_gv_magical_sv||| is_handle_constructor|||n is_list_assignment||| is_lvalue_sub||5.007001| is_uni_alnum_lc||5.006000| is_uni_alnumc_lc||5.006000| is_uni_alnumc||5.006000| is_uni_alnum||5.006000| is_uni_alpha_lc||5.006000| is_uni_alpha||5.006000| is_uni_ascii_lc||5.006000| is_uni_ascii||5.006000| is_uni_cntrl_lc||5.006000| is_uni_cntrl||5.006000| is_uni_digit_lc||5.006000| is_uni_digit||5.006000| is_uni_graph_lc||5.006000| is_uni_graph||5.006000| is_uni_idfirst_lc||5.006000| is_uni_idfirst||5.006000| is_uni_lower_lc||5.006000| is_uni_lower||5.006000| is_uni_print_lc||5.006000| is_uni_print||5.006000| is_uni_punct_lc||5.006000| is_uni_punct||5.006000| is_uni_space_lc||5.006000| is_uni_space||5.006000| is_uni_upper_lc||5.006000| is_uni_upper||5.006000| is_uni_xdigit_lc||5.006000| is_uni_xdigit||5.006000| is_utf8_alnumc||5.006000| is_utf8_alnum||5.006000| is_utf8_alpha||5.006000| is_utf8_ascii||5.006000| is_utf8_char_slow|||n is_utf8_char||5.006000| is_utf8_cntrl||5.006000| is_utf8_common||| is_utf8_digit||5.006000| is_utf8_graph||5.006000| is_utf8_idcont||5.008000| is_utf8_idfirst||5.006000| is_utf8_lower||5.006000| is_utf8_mark||5.006000| is_utf8_print||5.006000| is_utf8_punct||5.006000| is_utf8_space||5.006000| is_utf8_string_loclen||5.009003| is_utf8_string_loc||5.008001| is_utf8_string||5.006001| is_utf8_upper||5.006000| is_utf8_xdigit||5.006000| isa_lookup||| items|||n ix|||n jmaybe||| join_exact||| keyword||| leave_scope||| lex_end||| lex_start||| linklist||| listkids||| list||| load_module_nocontext|||vn load_module|5.006000||pv localize||| looks_like_bool||| looks_like_number||| lop||| mPUSHi|5.009002||p mPUSHn|5.009002||p mPUSHp|5.009002||p mPUSHs|5.011000||p mPUSHu|5.009002||p mXPUSHi|5.009002||p mXPUSHn|5.009002||p mXPUSHp|5.009002||p mXPUSHs|5.011000||p mXPUSHu|5.009002||p mad_free||| madlex||| madparse||| magic_clear_all_env||| magic_clearenv||| magic_clearhint||| magic_clearisa||| magic_clearpack||| magic_clearsig||| magic_dump||5.006000| magic_existspack||| magic_freearylen_p||| magic_freeovrld||| magic_getarylen||| magic_getdefelem||| magic_getnkeys||| magic_getpack||| magic_getpos||| magic_getsig||| magic_getsubstr||| magic_gettaint||| magic_getuvar||| magic_getvec||| magic_get||| magic_killbackrefs||| magic_len||| magic_methcall||| magic_methpack||| magic_nextpack||| magic_regdata_cnt||| magic_regdatum_get||| magic_regdatum_set||| magic_scalarpack||| magic_set_all_env||| magic_setamagic||| magic_setarylen||| magic_setcollxfrm||| magic_setdbline||| magic_setdefelem||| magic_setenv||| magic_sethint||| magic_setisa||| magic_setmglob||| magic_setnkeys||| magic_setpack||| magic_setpos||| magic_setregexp||| magic_setsig||| magic_setsubstr||| magic_settaint||| magic_setutf8||| magic_setuvar||| magic_setvec||| magic_set||| magic_sizepack||| magic_wipepack||| make_matcher||| make_trie_failtable||| make_trie||| malloc_good_size|||n malloced_size|||n malloc||5.007002|n markstack_grow||| matcher_matches_sv||| measure_struct||| memEQ|5.004000||p memNE|5.004000||p mem_collxfrm||| mem_log_common|||n mess_alloc||| mess_nocontext|||vn mess||5.006000|v method_common||| mfree||5.007002|n mg_clear||| mg_copy||| mg_dup||| mg_find||| mg_free||| mg_get||| mg_length||5.005000| mg_localize||| mg_magical||| mg_set||| mg_size||5.005000| mini_mktime||5.007002| missingterm||| mode_from_discipline||| modkids||| mod||| more_bodies||| more_sv||| moreswitches||| mro_get_from_name||5.011000| mro_get_linear_isa_dfs||| mro_get_linear_isa||5.009005| mro_get_private_data||5.011000| mro_isa_changed_in||| mro_meta_dup||| mro_meta_init||| mro_method_changed_in||5.009005| mro_register||5.011000| mro_set_mro||5.011000| mro_set_private_data||5.011000| mul128||| mulexp10|||n my_atof2||5.007002| my_atof||5.006000| my_attrs||| my_bcopy|||n my_betoh16|||n my_betoh32|||n my_betoh64|||n my_betohi|||n my_betohl|||n my_betohs|||n my_bzero|||n my_chsize||| my_clearenv||| my_cxt_index||| my_cxt_init||| my_dirfd||5.009005| my_exit_jump||| my_exit||| my_failure_exit||5.004000| my_fflush_all||5.006000| my_fork||5.007003|n my_htobe16|||n my_htobe32|||n my_htobe64|||n my_htobei|||n my_htobel|||n my_htobes|||n my_htole16|||n my_htole32|||n my_htole64|||n my_htolei|||n my_htolel|||n my_htoles|||n my_htonl||| my_kid||| my_letoh16|||n my_letoh32|||n my_letoh64|||n my_letohi|||n my_letohl|||n my_letohs|||n my_lstat||| my_memcmp||5.004000|n my_memset|||n my_ntohl||| my_pclose||5.004000| my_popen_list||5.007001| my_popen||5.004000| my_setenv||| my_snprintf|5.009004||pvn my_socketpair||5.007003|n my_sprintf|5.009003||pvn my_stat||| my_strftime||5.007002| my_strlcat|5.009004||pn my_strlcpy|5.009004||pn my_swabn|||n my_swap||| my_unexec||| my_vsnprintf||5.009004|n need_utf8|||n newANONATTRSUB||5.006000| newANONHASH||| newANONLIST||| newANONSUB||| newASSIGNOP||| newATTRSUB||5.006000| newAVREF||| newAV||| newBINOP||| newCONDOP||| newCONSTSUB|5.004050||p newCVREF||| newDEFSVOP||| newFORM||| newFOROP||| newGIVENOP||5.009003| newGIVWHENOP||| newGP||| newGVOP||| newGVREF||| newGVgen||| newHVREF||| newHVhv||5.005000| newHV||| newIO||| newLISTOP||| newLOGOP||| newLOOPEX||| newLOOPOP||| newMADPROP||| newMADsv||| newMYSUB||| newNULLLIST||| newOP||| newPADOP||| newPMOP||| newPROG||| newPVOP||| newRANGE||| newRV_inc|5.004000||p newRV_noinc|5.004000||p newRV||| newSLICEOP||| newSTATEOP||| newSUB||| newSVOP||| newSVREF||| newSV_type|5.009005||p newSVhek||5.009003| newSViv||| newSVnv||| newSVpvf_nocontext|||vn newSVpvf||5.004000|v newSVpvn_flags|5.011000||p newSVpvn_share|5.007001||p newSVpvn_utf8|5.011000||p newSVpvn|5.004050||p newSVpvs_flags|5.011000||p newSVpvs_share||5.009003| newSVpvs|5.009003||p newSVpv||| newSVrv||| newSVsv||| newSVuv|5.006000||p newSV||| newTOKEN||| newUNOP||| newWHENOP||5.009003| newWHILEOP||5.009003| newXS_flags||5.009004| newXSproto||5.006000| newXS||5.006000| new_collate||5.006000| new_constant||| new_ctype||5.006000| new_he||| new_logop||| new_numeric||5.006000| new_stackinfo||5.005000| new_version||5.009000| new_warnings_bitfield||| next_symbol||| nextargv||| nextchar||| ninstr||| no_bareword_allowed||| no_fh_allowed||| no_op||| not_a_number||| nothreadhook||5.008000| nuke_stacks||| num_overflow|||n offer_nice_chunk||| oopsAV||| oopsHV||| op_clear||| op_const_sv||| op_dump||5.006000| op_free||| op_getmad_weak||| op_getmad||| op_null||5.007002| op_refcnt_dec||| op_refcnt_inc||| op_refcnt_lock||5.009002| op_refcnt_unlock||5.009002| op_xmldump||| open_script||| pMY_CXT_|5.007003||p pMY_CXT|5.007003||p pTHX_|5.006000||p pTHX|5.006000||p packWARN|5.007003||p pack_cat||5.007003| pack_rec||| package||| packlist||5.008001| pad_add_anon||| pad_add_name||| pad_alloc||| pad_block_start||| pad_check_dup||| pad_compname_type||| pad_findlex||| pad_findmy||| pad_fixup_inner_anons||| pad_free||| pad_leavemy||| pad_new||| pad_peg|||n pad_push||| pad_reset||| pad_setsv||| pad_sv||5.011000| pad_swipe||| pad_tidy||| pad_undef||| parse_body||| parse_unicode_opts||| parser_dup||| parser_free||| path_is_absolute|||n peep||| pending_Slabs_to_ro||| perl_alloc_using|||n perl_alloc|||n perl_clone_using|||n perl_clone|||n perl_construct|||n perl_destruct||5.007003|n perl_free|||n perl_parse||5.006000|n perl_run|||n pidgone||| pm_description||| pmflag||| pmop_dump||5.006000| pmop_xmldump||| pmruntime||| pmtrans||| pop_scope||| pregcomp||5.009005| pregexec||| pregfree2||5.011000| pregfree||| prepend_elem||| prepend_madprops||| printbuf||| printf_nocontext|||vn process_special_blocks||| ptr_table_clear||5.009005| ptr_table_fetch||5.009005| ptr_table_find|||n ptr_table_free||5.009005| ptr_table_new||5.009005| ptr_table_split||5.009005| ptr_table_store||5.009005| push_scope||| put_byte||| pv_display|5.006000||p pv_escape|5.009004||p pv_pretty|5.009004||p pv_uni_display||5.007003| qerror||| qsortsvu||| re_compile||5.009005| re_croak2||| re_dup_guts||| re_intuit_start||5.009005| re_intuit_string||5.006000| readpipe_override||| realloc||5.007002|n reentrant_free||| reentrant_init||| reentrant_retry|||vn reentrant_size||| ref_array_or_hash||| refcounted_he_chain_2hv||| refcounted_he_fetch||| refcounted_he_free||| refcounted_he_new_common||| refcounted_he_new||| refcounted_he_value||| refkids||| refto||| ref||5.011000| reg_check_named_buff_matched||| reg_named_buff_all||5.009005| reg_named_buff_exists||5.009005| reg_named_buff_fetch||5.009005| reg_named_buff_firstkey||5.009005| reg_named_buff_iter||| reg_named_buff_nextkey||5.009005| reg_named_buff_scalar||5.009005| reg_named_buff||| reg_namedseq||| reg_node||| reg_numbered_buff_fetch||| reg_numbered_buff_length||| reg_numbered_buff_store||| reg_qr_package||| reg_recode||| reg_scan_name||| reg_skipcomment||| reg_temp_copy||| reganode||| regatom||| regbranch||| regclass_swash||5.009004| regclass||| regcppop||| regcppush||| regcurly|||n regdump_extflags||| regdump||5.005000| regdupe_internal||| regexec_flags||5.005000| regfree_internal||5.009005| reghop3|||n reghop4|||n reghopmaybe3|||n reginclass||| reginitcolors||5.006000| reginsert||| regmatch||| regnext||5.005000| regpiece||| regpposixcc||| regprop||| regrepeat||| regtail_study||| regtail||| regtry||| reguni||| regwhite|||n reg||| repeatcpy||| report_evil_fh||| report_uninit||| require_pv||5.006000| require_tie_mod||| restore_magic||| rninstr||| rsignal_restore||| rsignal_save||| rsignal_state||5.004000| rsignal||5.004000| run_body||| run_user_filter||| runops_debug||5.005000| runops_standard||5.005000| rvpv_dup||| rxres_free||| rxres_restore||| rxres_save||| safesyscalloc||5.006000|n safesysfree||5.006000|n safesysmalloc||5.006000|n safesysrealloc||5.006000|n same_dirent||| save_I16||5.004000| save_I32||| save_I8||5.006000| save_adelete||5.011000| save_aelem||5.004050| save_alloc||5.006000| save_aptr||| save_ary||| save_bool||5.008001| save_clearsv||| save_delete||| save_destructor_x||5.006000| save_destructor||5.006000| save_freeop||| save_freepv||| save_freesv||| save_generic_pvref||5.006001| save_generic_svref||5.005030| save_gp||5.004000| save_hash||| save_hek_flags|||n save_helem_flags||5.011000| save_helem||5.004050| save_hints||| save_hptr||| save_int||| save_item||| save_iv||5.005000| save_lines||| save_list||| save_long||| save_magic||| save_mortalizesv||5.007001| save_nogv||| save_op||| save_padsv_and_mortalize||5.011000| save_pptr||| save_pushi32ptr||| save_pushptri32ptr||| save_pushptrptr||| save_pushptr||5.011000| save_re_context||5.006000| save_scalar_at||| save_scalar||| save_set_svflags||5.009000| save_shared_pvref||5.007003| save_sptr||| save_svref||| save_vptr||5.006000| savepvn||| savepvs||5.009003| savepv||| savesharedpvn||5.009005| savesharedpv||5.007003| savestack_grow_cnt||5.008001| savestack_grow||| savesvpv||5.009002| sawparens||| scalar_mod_type|||n scalarboolean||| scalarkids||| scalarseq||| scalarvoid||| scalar||| scan_bin||5.006000| scan_commit||| scan_const||| scan_formline||| scan_heredoc||| scan_hex||| scan_ident||| scan_inputsymbol||| scan_num||5.007001| scan_oct||| scan_pat||| scan_str||| scan_subst||| scan_trans||| scan_version||5.009001| scan_vstring||5.009005| scan_word||| scope||| screaminstr||5.005000| search_const||| seed||5.008001| sequence_num||| sequence_tail||| sequence||| set_context||5.006000|n set_numeric_local||5.006000| set_numeric_radix||5.006000| set_numeric_standard||5.006000| setdefout||| share_hek_flags||| share_hek||5.004000| si_dup||| sighandler|||n simplify_sort||| skipspace0||| skipspace1||| skipspace2||| skipspace||| softref2xv||| sortcv_stacked||| sortcv_xsub||| sortcv||| sortsv_flags||5.009003| sortsv||5.007003| space_join_names_mortal||| ss_dup||| stack_grow||| start_force||| start_glob||| start_subparse||5.004000| stashpv_hvname_match||5.011000| stdize_locale||| store_cop_label||| strEQ||| strGE||| strGT||| strLE||| strLT||| strNE||| str_to_version||5.006000| strip_return||| strnEQ||| strnNE||| study_chunk||| sub_crush_depth||| sublex_done||| sublex_push||| sublex_start||| sv_2bool||| sv_2cv||| sv_2io||| sv_2iuv_common||| sv_2iuv_non_preserve||| sv_2iv_flags||5.009001| sv_2iv||| sv_2mortal||| sv_2num||| sv_2nv||| sv_2pv_flags|5.007002||p sv_2pv_nolen|5.006000||p sv_2pvbyte_nolen|5.006000||p sv_2pvbyte|5.006000||p sv_2pvutf8_nolen||5.006000| sv_2pvutf8||5.006000| sv_2pv||| sv_2uv_flags||5.009001| sv_2uv|5.004000||p sv_add_arena||| sv_add_backref||| sv_backoff||| sv_bless||| sv_cat_decode||5.008001| sv_catpv_mg|5.004050||p sv_catpvf_mg_nocontext|||pvn sv_catpvf_mg|5.006000|5.004000|pv sv_catpvf_nocontext|||vn sv_catpvf||5.004000|v sv_catpvn_flags||5.007002| sv_catpvn_mg|5.004050||p sv_catpvn_nomg|5.007002||p sv_catpvn||| sv_catpvs|5.009003||p sv_catpv||| sv_catsv_flags||5.007002| sv_catsv_mg|5.004050||p sv_catsv_nomg|5.007002||p sv_catsv||| sv_catxmlpvn||| sv_catxmlsv||| sv_chop||| sv_clean_all||| sv_clean_objs||| sv_clear||| sv_cmp_locale||5.004000| sv_cmp||| sv_collxfrm||| sv_compile_2op||5.008001| sv_copypv||5.007003| sv_dec||| sv_del_backref||| sv_derived_from||5.004000| sv_destroyable||5.010000| sv_does||5.009004| sv_dump||| sv_dup_inc_multiple||| sv_dup||| sv_eq||| sv_exp_grow||| sv_force_normal_flags||5.007001| sv_force_normal||5.006000| sv_free2||| sv_free_arenas||| sv_free||| sv_gets||5.004000| sv_grow||| sv_i_ncmp||| sv_inc||| sv_insert_flags||5.011000| sv_insert||| sv_isa||| sv_isobject||| sv_iv||5.005000| sv_kill_backrefs||| sv_len_utf8||5.006000| sv_len||| sv_magic_portable|5.011000|5.004000|p sv_magicext||5.007003| sv_magic||| sv_mortalcopy||| sv_ncmp||| sv_newmortal||| sv_newref||| sv_nolocking||5.007003| sv_nosharing||5.007003| sv_nounlocking||| sv_nv||5.005000| sv_peek||5.005000| sv_pos_b2u_midway||| sv_pos_b2u||5.006000| sv_pos_u2b_cached||| sv_pos_u2b_forwards|||n sv_pos_u2b_midway|||n sv_pos_u2b||5.006000| sv_pvbyten_force||5.006000| sv_pvbyten||5.006000| sv_pvbyte||5.006000| sv_pvn_force_flags|5.007002||p sv_pvn_force||| sv_pvn_nomg|5.007003|5.005000|p sv_pvn||5.005000| sv_pvutf8n_force||5.006000| sv_pvutf8n||5.006000| sv_pvutf8||5.006000| sv_pv||5.006000| sv_recode_to_utf8||5.007003| sv_reftype||| sv_release_COW||| sv_replace||| sv_report_used||| sv_reset||| sv_rvweaken||5.006000| sv_setiv_mg|5.004050||p sv_setiv||| sv_setnv_mg|5.006000||p sv_setnv||| sv_setpv_mg|5.004050||p sv_setpvf_mg_nocontext|||pvn sv_setpvf_mg|5.006000|5.004000|pv sv_setpvf_nocontext|||vn sv_setpvf||5.004000|v sv_setpviv_mg||5.008001| sv_setpviv||5.008001| sv_setpvn_mg|5.004050||p sv_setpvn||| sv_setpvs|5.009004||p sv_setpv||| sv_setref_iv||| sv_setref_nv||| sv_setref_pvn||| sv_setref_pv||| sv_setref_uv||5.007001| sv_setsv_cow||| sv_setsv_flags||5.007002| sv_setsv_mg|5.004050||p sv_setsv_nomg|5.007002||p sv_setsv||| sv_setuv_mg|5.004050||p sv_setuv|5.004000||p sv_tainted||5.004000| sv_taint||5.004000| sv_true||5.005000| sv_unglob||| sv_uni_display||5.007003| sv_unmagic||| sv_unref_flags||5.007001| sv_unref||| sv_untaint||5.004000| sv_upgrade||| sv_usepvn_flags||5.009004| sv_usepvn_mg|5.004050||p sv_usepvn||| sv_utf8_decode||5.006000| sv_utf8_downgrade||5.006000| sv_utf8_encode||5.006000| sv_utf8_upgrade_flags_grow||5.011000| sv_utf8_upgrade_flags||5.007002| sv_utf8_upgrade_nomg||5.007002| sv_utf8_upgrade||5.007001| sv_uv|5.005000||p sv_vcatpvf_mg|5.006000|5.004000|p sv_vcatpvfn||5.004000| sv_vcatpvf|5.006000|5.004000|p sv_vsetpvf_mg|5.006000|5.004000|p sv_vsetpvfn||5.004000| sv_vsetpvf|5.006000|5.004000|p sv_xmlpeek||| svtype||| swallow_bom||| swap_match_buff||| swash_fetch||5.007002| swash_get||| swash_init||5.006000| sys_init3||5.010000|n sys_init||5.010000|n sys_intern_clear||| sys_intern_dup||| sys_intern_init||| sys_term||5.010000|n taint_env||| taint_proper||| tmps_grow||5.006000| toLOWER||| toUPPER||| to_byte_substr||| to_uni_fold||5.007003| to_uni_lower_lc||5.006000| to_uni_lower||5.007003| to_uni_title_lc||5.006000| to_uni_title||5.007003| to_uni_upper_lc||5.006000| to_uni_upper||5.007003| to_utf8_case||5.007003| to_utf8_fold||5.007003| to_utf8_lower||5.007003| to_utf8_substr||| to_utf8_title||5.007003| to_utf8_upper||5.007003| token_free||| token_getmad||| tokenize_use||| tokeq||| tokereport||| too_few_arguments||| too_many_arguments||| uiv_2buf|||n unlnk||| unpack_rec||| unpack_str||5.007003| unpackstring||5.008001| unshare_hek_or_pvn||| unshare_hek||| unsharepvn||5.004000| unwind_handler_stack||| update_debugger_info||| upg_version||5.009005| usage||| utf16_to_utf8_reversed||5.006001| utf16_to_utf8||5.006001| utf8_distance||5.006000| utf8_hop||5.006000| utf8_length||5.007001| utf8_mg_pos_cache_update||| utf8_to_bytes||5.006001| utf8_to_uvchr||5.007001| utf8_to_uvuni||5.007001| utf8n_to_uvchr||| utf8n_to_uvuni||5.007001| utilize||| uvchr_to_utf8_flags||5.007003| uvchr_to_utf8||| uvuni_to_utf8_flags||5.007003| uvuni_to_utf8||5.007001| validate_suid||| varname||| vcmp||5.009000| vcroak||5.006000| vdeb||5.007003| vdie_common||| vdie_croak_common||| vdie||| vform||5.006000| visit||| vivify_defelem||| vivify_ref||| vload_module|5.006000||p vmess||5.006000| vnewSVpvf|5.006000|5.004000|p vnormal||5.009002| vnumify||5.009000| vstringify||5.009000| vverify||5.009003| vwarner||5.006000| vwarn||5.006000| wait4pid||| warn_nocontext|||vn warner_nocontext|||vn warner|5.006000|5.004000|pv warn|||v watch||| whichsig||| write_no_mem||| write_to_stderr||| xmldump_all||| xmldump_attr||| xmldump_eval||| xmldump_form||| xmldump_indent|||v xmldump_packsubs||| xmldump_sub||| xmldump_vindent||| yyerror||| yylex||| yyparse||| yywarn||| ); if (exists $opt{'list-unsupported'}) { my $f; for $f (sort { lc $a cmp lc $b } keys %API) { next unless $API{$f}{todo}; print "$f ", '.'x(40-length($f)), " ", format_version($API{$f}{todo}), "\n"; } exit 0; } # Scan for possible replacement candidates my(%replace, %need, %hints, %warnings, %depends); my $replace = 0; my($hint, $define, $function); sub find_api { my $code = shift; $code =~ s{ / (?: \*[^*]*\*+(?:[^$ccs][^*]*\*+)* / | /[^\r\n]*) | "[^"\\]*(?:\\.[^"\\]*)*" | '[^'\\]*(?:\\.[^'\\]*)*' }{}egsx; grep { exists $API{$_} } $code =~ /(\w+)/mg; } while () { if ($hint) { my $h = $hint->[0] eq 'Hint' ? \%hints : \%warnings; if (m{^\s*\*\s(.*?)\s*$}) { for (@{$hint->[1]}) { $h->{$_} ||= ''; # suppress warning with older perls $h->{$_} .= "$1\n"; } } else { undef $hint } } $hint = [$1, [split /,?\s+/, $2]] if m{^\s*$rccs\s+(Hint|Warning):\s+(\w+(?:,?\s+\w+)*)\s*$}; if ($define) { if ($define->[1] =~ /\\$/) { $define->[1] .= $_; } else { if (exists $API{$define->[0]} && $define->[1] !~ /^DPPP_\(/) { my @n = find_api($define->[1]); push @{$depends{$define->[0]}}, @n if @n } undef $define; } } $define = [$1, $2] if m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(.*)}; if ($function) { if (/^}/) { if (exists $API{$function->[0]}) { my @n = find_api($function->[1]); push @{$depends{$function->[0]}}, @n if @n } undef $function; } else { $function->[1] .= $_; } } $function = [$1, ''] if m{^DPPP_\(my_(\w+)\)}; $replace = $1 if m{^\s*$rccs\s+Replace:\s+(\d+)\s+$rcce\s*$}; $replace{$2} = $1 if $replace and m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(\w+)}; $replace{$2} = $1 if m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(\w+).*$rccs\s+Replace\s+$rcce}; $replace{$1} = $2 if m{^\s*$rccs\s+Replace (\w+) with (\w+)\s+$rcce\s*$}; if (m{^\s*$rccs\s+(\w+(\s*,\s*\w+)*)\s+depends\s+on\s+(\w+(\s*,\s*\w+)*)\s+$rcce\s*$}) { my @deps = map { s/\s+//g; $_ } split /,/, $3; my $d; for $d (map { s/\s+//g; $_ } split /,/, $1) { push @{$depends{$d}}, @deps; } } $need{$1} = 1 if m{^#if\s+defined\(NEED_(\w+)(?:_GLOBAL)?\)}; } for (values %depends) { my %s; $_ = [sort grep !$s{$_}++, @$_]; } if (exists $opt{'api-info'}) { my $f; my $count = 0; my $match = $opt{'api-info'} =~ m!^/(.*)/$! ? $1 : "^\Q$opt{'api-info'}\E\$"; for $f (sort { lc $a cmp lc $b } keys %API) { next unless $f =~ /$match/; print "\n=== $f ===\n\n"; my $info = 0; if ($API{$f}{base} || $API{$f}{todo}) { my $base = format_version($API{$f}{base} || $API{$f}{todo}); print "Supported at least starting from perl-$base.\n"; $info++; } if ($API{$f}{provided}) { my $todo = $API{$f}{todo} ? format_version($API{$f}{todo}) : "5.003"; print "Support by $ppport provided back to perl-$todo.\n"; print "Support needs to be explicitly requested by NEED_$f.\n" if exists $need{$f}; print "Depends on: ", join(', ', @{$depends{$f}}), ".\n" if exists $depends{$f}; print "\n$hints{$f}" if exists $hints{$f}; print "\nWARNING:\n$warnings{$f}" if exists $warnings{$f}; $info++; } print "No portability information available.\n" unless $info; $count++; } $count or print "Found no API matching '$opt{'api-info'}'."; print "\n"; exit 0; } if (exists $opt{'list-provided'}) { my $f; for $f (sort { lc $a cmp lc $b } keys %API) { next unless $API{$f}{provided}; my @flags; push @flags, 'explicit' if exists $need{$f}; push @flags, 'depend' if exists $depends{$f}; push @flags, 'hint' if exists $hints{$f}; push @flags, 'warning' if exists $warnings{$f}; my $flags = @flags ? ' ['.join(', ', @flags).']' : ''; print "$f$flags\n"; } exit 0; } my @files; my @srcext = qw( .xs .c .h .cc .cpp -c.inc -xs.inc ); my $srcext = join '|', map { quotemeta $_ } @srcext; if (@ARGV) { my %seen; for (@ARGV) { if (-e) { if (-f) { push @files, $_ unless $seen{$_}++; } else { warn "'$_' is not a file.\n" } } else { my @new = grep { -f } glob $_ or warn "'$_' does not exist.\n"; push @files, grep { !$seen{$_}++ } @new; } } } else { eval { require File::Find; File::Find::find(sub { $File::Find::name =~ /($srcext)$/i and push @files, $File::Find::name; }, '.'); }; if ($@) { @files = map { glob "*$_" } @srcext; } } if (!@ARGV || $opt{filter}) { my(@in, @out); my %xsc = map { /(.*)\.xs$/ ? ("$1.c" => 1, "$1.cc" => 1) : () } @files; for (@files) { my $out = exists $xsc{$_} || /\b\Q$ppport\E$/i || !/($srcext)$/i; push @{ $out ? \@out : \@in }, $_; } if (@ARGV && @out) { warning("Skipping the following files (use --nofilter to avoid this):\n| ", join "\n| ", @out); } @files = @in; } die "No input files given!\n" unless @files; my(%files, %global, %revreplace); %revreplace = reverse %replace; my $filename; my $patch_opened = 0; for $filename (@files) { unless (open IN, "<$filename") { warn "Unable to read from $filename: $!\n"; next; } info("Scanning $filename ..."); my $c = do { local $/; }; close IN; my %file = (orig => $c, changes => 0); # Temporarily remove C/XS comments and strings from the code my @ccom; $c =~ s{ ( ^$HS*\#$HS*include\b[^\r\n]+\b(?:\Q$ppport\E|XSUB\.h)\b[^\r\n]* | ^$HS*\#$HS*(?:define|elif|if(?:def)?)\b[^\r\n]* ) | ( ^$HS*\#[^\r\n]* | "[^"\\]*(?:\\.[^"\\]*)*" | '[^'\\]*(?:\\.[^'\\]*)*' | / (?: \*[^*]*\*+(?:[^$ccs][^*]*\*+)* / | /[^\r\n]* ) ) }{ defined $2 and push @ccom, $2; defined $1 ? $1 : "$ccs$#ccom$cce" }mgsex; $file{ccom} = \@ccom; $file{code} = $c; $file{has_inc_ppport} = $c =~ /^$HS*#$HS*include[^\r\n]+\b\Q$ppport\E\b/m; my $func; for $func (keys %API) { my $match = $func; $match .= "|$revreplace{$func}" if exists $revreplace{$func}; if ($c =~ /\b(?:Perl_)?($match)\b/) { $file{uses_replace}{$1}++ if exists $revreplace{$func} && $1 eq $revreplace{$func}; $file{uses_Perl}{$func}++ if $c =~ /\bPerl_$func\b/; if (exists $API{$func}{provided}) { $file{uses_provided}{$func}++; if (!exists $API{$func}{base} || $API{$func}{base} > $opt{'compat-version'}) { $file{uses}{$func}++; my @deps = rec_depend($func); if (@deps) { $file{uses_deps}{$func} = \@deps; for (@deps) { $file{uses}{$_} = 0 unless exists $file{uses}{$_}; } } for ($func, @deps) { $file{needs}{$_} = 'static' if exists $need{$_}; } } } if (exists $API{$func}{todo} && $API{$func}{todo} > $opt{'compat-version'}) { if ($c =~ /\b$func\b/) { $file{uses_todo}{$func}++; } } } } while ($c =~ /^$HS*#$HS*define$HS+(NEED_(\w+?)(_GLOBAL)?)\b/mg) { if (exists $need{$2}) { $file{defined $3 ? 'needed_global' : 'needed_static'}{$2}++; } else { warning("Possibly wrong #define $1 in $filename") } } for (qw(uses needs uses_todo needed_global needed_static)) { for $func (keys %{$file{$_}}) { push @{$global{$_}{$func}}, $filename; } } $files{$filename} = \%file; } # Globally resolve NEED_'s my $need; for $need (keys %{$global{needs}}) { if (@{$global{needs}{$need}} > 1) { my @targets = @{$global{needs}{$need}}; my @t = grep $files{$_}{needed_global}{$need}, @targets; @targets = @t if @t; @t = grep /\.xs$/i, @targets; @targets = @t if @t; my $target = shift @targets; $files{$target}{needs}{$need} = 'global'; for (@{$global{needs}{$need}}) { $files{$_}{needs}{$need} = 'extern' if $_ ne $target; } } } for $filename (@files) { exists $files{$filename} or next; info("=== Analyzing $filename ==="); my %file = %{$files{$filename}}; my $func; my $c = $file{code}; my $warnings = 0; for $func (sort keys %{$file{uses_Perl}}) { if ($API{$func}{varargs}) { unless ($API{$func}{nothxarg}) { my $changes = ($c =~ s{\b(Perl_$func\s*\(\s*)(?!aTHX_?)(\)|[^\s)]*\))} { $1 . ($2 eq ')' ? 'aTHX' : 'aTHX_ ') . $2 }ge); if ($changes) { warning("Doesn't pass interpreter argument aTHX to Perl_$func"); $file{changes} += $changes; } } } else { warning("Uses Perl_$func instead of $func"); $file{changes} += ($c =~ s{\bPerl_$func(\s*)\((\s*aTHX_?)?\s*} {$func$1(}g); } } for $func (sort keys %{$file{uses_replace}}) { warning("Uses $func instead of $replace{$func}"); $file{changes} += ($c =~ s/\b$func\b/$replace{$func}/g); } for $func (sort keys %{$file{uses_provided}}) { if ($file{uses}{$func}) { if (exists $file{uses_deps}{$func}) { diag("Uses $func, which depends on ", join(', ', @{$file{uses_deps}{$func}})); } else { diag("Uses $func"); } } $warnings += hint($func); } unless ($opt{quiet}) { for $func (sort keys %{$file{uses_todo}}) { print "*** WARNING: Uses $func, which may not be portable below perl ", format_version($API{$func}{todo}), ", even with '$ppport'\n"; $warnings++; } } for $func (sort keys %{$file{needed_static}}) { my $message = ''; if (not exists $file{uses}{$func}) { $message = "No need to define NEED_$func if $func is never used"; } elsif (exists $file{needs}{$func} && $file{needs}{$func} ne 'static') { $message = "No need to define NEED_$func when already needed globally"; } if ($message) { diag($message); $file{changes} += ($c =~ s/^$HS*#$HS*define$HS+NEED_$func\b.*$LF//mg); } } for $func (sort keys %{$file{needed_global}}) { my $message = ''; if (not exists $global{uses}{$func}) { $message = "No need to define NEED_${func}_GLOBAL if $func is never used"; } elsif (exists $file{needs}{$func}) { if ($file{needs}{$func} eq 'extern') { $message = "No need to define NEED_${func}_GLOBAL when already needed globally"; } elsif ($file{needs}{$func} eq 'static') { $message = "No need to define NEED_${func}_GLOBAL when only used in this file"; } } if ($message) { diag($message); $file{changes} += ($c =~ s/^$HS*#$HS*define$HS+NEED_${func}_GLOBAL\b.*$LF//mg); } } $file{needs_inc_ppport} = keys %{$file{uses}}; if ($file{needs_inc_ppport}) { my $pp = ''; for $func (sort keys %{$file{needs}}) { my $type = $file{needs}{$func}; next if $type eq 'extern'; my $suffix = $type eq 'global' ? '_GLOBAL' : ''; unless (exists $file{"needed_$type"}{$func}) { if ($type eq 'global') { diag("Files [@{$global{needs}{$func}}] need $func, adding global request"); } else { diag("File needs $func, adding static request"); } $pp .= "#define NEED_$func$suffix\n"; } } if ($pp && ($c =~ s/^(?=$HS*#$HS*define$HS+NEED_\w+)/$pp/m)) { $pp = ''; $file{changes}++; } unless ($file{has_inc_ppport}) { diag("Needs to include '$ppport'"); $pp .= qq(#include "$ppport"\n) } if ($pp) { $file{changes} += ($c =~ s/^($HS*#$HS*define$HS+NEED_\w+.*?)^/$1$pp/ms) || ($c =~ s/^(?=$HS*#$HS*include.*\Q$ppport\E)/$pp/m) || ($c =~ s/^($HS*#$HS*include.*XSUB.*\s*?)^/$1$pp/m) || ($c =~ s/^/$pp/); } } else { if ($file{has_inc_ppport}) { diag("No need to include '$ppport'"); $file{changes} += ($c =~ s/^$HS*?#$HS*include.*\Q$ppport\E.*?$LF//m); } } # put back in our C comments my $ix; my $cppc = 0; my @ccom = @{$file{ccom}}; for $ix (0 .. $#ccom) { if (!$opt{cplusplus} && $ccom[$ix] =~ s!^//!!) { $cppc++; $file{changes} += $c =~ s/$rccs$ix$rcce/$ccs$ccom[$ix] $cce/; } else { $c =~ s/$rccs$ix$rcce/$ccom[$ix]/; } } if ($cppc) { my $s = $cppc != 1 ? 's' : ''; warning("Uses $cppc C++ style comment$s, which is not portable"); } my $s = $warnings != 1 ? 's' : ''; my $warn = $warnings ? " ($warnings warning$s)" : ''; info("Analysis completed$warn"); if ($file{changes}) { if (exists $opt{copy}) { my $newfile = "$filename$opt{copy}"; if (-e $newfile) { error("'$newfile' already exists, refusing to write copy of '$filename'"); } else { local *F; if (open F, ">$newfile") { info("Writing copy of '$filename' with changes to '$newfile'"); print F $c; close F; } else { error("Cannot open '$newfile' for writing: $!"); } } } elsif (exists $opt{patch} || $opt{changes}) { if (exists $opt{patch}) { unless ($patch_opened) { if (open PATCH, ">$opt{patch}") { $patch_opened = 1; } else { error("Cannot open '$opt{patch}' for writing: $!"); delete $opt{patch}; $opt{changes} = 1; goto fallback; } } mydiff(\*PATCH, $filename, $c); } else { fallback: info("Suggested changes:"); mydiff(\*STDOUT, $filename, $c); } } else { my $s = $file{changes} == 1 ? '' : 's'; info("$file{changes} potentially required change$s detected"); } } else { info("Looks good"); } } close PATCH if $patch_opened; exit 0; sub try_use { eval "use @_;"; return $@ eq '' } sub mydiff { local *F = shift; my($file, $str) = @_; my $diff; if (exists $opt{diff}) { $diff = run_diff($opt{diff}, $file, $str); } if (!defined $diff and try_use('Text::Diff')) { $diff = Text::Diff::diff($file, \$str, { STYLE => 'Unified' }); $diff = <
$tmp") { print F $str; close F; if (open F, "$prog $file $tmp |") { while () { s/\Q$tmp\E/$file.patched/; $diff .= $_; } close F; unlink $tmp; return $diff; } unlink $tmp; } else { error("Cannot open '$tmp' for writing: $!"); } return undef; } sub rec_depend { my($func, $seen) = @_; return () unless exists $depends{$func}; $seen = {%{$seen||{}}}; return () if $seen->{$func}++; my %s; grep !$s{$_}++, map { ($_, rec_depend($_, $seen)) } @{$depends{$func}}; } sub parse_version { my $ver = shift; if ($ver =~ /^(\d+)\.(\d+)\.(\d+)$/) { return ($1, $2, $3); } elsif ($ver !~ /^\d+\.[\d_]+$/) { die "cannot parse version '$ver'\n"; } $ver =~ s/_//g; $ver =~ s/$/000000/; my($r,$v,$s) = $ver =~ /(\d+)\.(\d{3})(\d{3})/; $v = int $v; $s = int $s; if ($r < 5 || ($r == 5 && $v < 6)) { if ($s % 10) { die "cannot parse version '$ver'\n"; } } return ($r, $v, $s); } sub format_version { my $ver = shift; $ver =~ s/$/000000/; my($r,$v,$s) = $ver =~ /(\d+)\.(\d{3})(\d{3})/; $v = int $v; $s = int $s; if ($r < 5 || ($r == 5 && $v < 6)) { if ($s % 10) { die "invalid version '$ver'\n"; } $s /= 10; $ver = sprintf "%d.%03d", $r, $v; $s > 0 and $ver .= sprintf "_%02d", $s; return $ver; } return sprintf "%d.%d.%d", $r, $v, $s; } sub info { $opt{quiet} and return; print @_, "\n"; } sub diag { $opt{quiet} and return; $opt{diag} and print @_, "\n"; } sub warning { $opt{quiet} and return; print "*** ", @_, "\n"; } sub error { print "*** ERROR: ", @_, "\n"; } my %given_hints; my %given_warnings; sub hint { $opt{quiet} and return; my $func = shift; my $rv = 0; if (exists $warnings{$func} && !$given_warnings{$func}++) { my $warn = $warnings{$func}; $warn =~ s!^!*** !mg; print "*** WARNING: $func\n", $warn; $rv++; } if ($opt{hints} && exists $hints{$func} && !$given_hints{$func}++) { my $hint = $hints{$func}; $hint =~ s/^/ /mg; print " --- hint for $func ---\n", $hint; } $rv; } sub usage { my($usage) = do { local(@ARGV,$/)=($0); <> } =~ /^=head\d$HS+SYNOPSIS\s*^(.*?)\s*^=/ms; my %M = ( 'I' => '*' ); $usage =~ s/^\s*perl\s+\S+/$^X $0/; $usage =~ s/([A-Z])<([^>]+)>/$M{$1}$2$M{$1}/g; print < }; my($copy) = $self =~ /^=head\d\s+COPYRIGHT\s*^(.*?)^=\w+/ms; $copy =~ s/^(?=\S+)/ /gms; $self =~ s/^$HS+Do NOT edit.*?(?=^-)/$copy/ms; $self =~ s/^SKIP.*(?=^__DATA__)/SKIP if (\@ARGV && \$ARGV[0] eq '--unstrip') { eval { require Devel::PPPort }; \$@ and die "Cannot require Devel::PPPort, please install.\\n"; if (eval \$Devel::PPPort::VERSION < $VERSION) { die "$0 was originally generated with Devel::PPPort $VERSION.\\n" . "Your Devel::PPPort is only version \$Devel::PPPort::VERSION.\\n" . "Please install a newer version, or --unstrip will not work.\\n"; } Devel::PPPort::WriteFile(\$0); exit 0; } print <$0" or die "cannot strip $0: $!\n"; print OUT "$pl$c\n"; exit 0; } __DATA__ */ #ifndef _P_P_PORTABILITY_H_ #define _P_P_PORTABILITY_H_ #ifndef DPPP_NAMESPACE # define DPPP_NAMESPACE DPPP_ #endif #define DPPP_CAT2(x,y) CAT2(x,y) #define DPPP_(name) DPPP_CAT2(DPPP_NAMESPACE, name) #ifndef PERL_REVISION # if !defined(__PATCHLEVEL_H_INCLUDED__) && !(defined(PATCHLEVEL) && defined(SUBVERSION)) # define PERL_PATCHLEVEL_H_IMPLICIT # include # endif # if !(defined(PERL_VERSION) || (defined(SUBVERSION) && defined(PATCHLEVEL))) # include # endif # ifndef PERL_REVISION # define PERL_REVISION (5) /* Replace: 1 */ # define PERL_VERSION PATCHLEVEL # define PERL_SUBVERSION SUBVERSION /* Replace PERL_PATCHLEVEL with PERL_VERSION */ /* Replace: 0 */ # endif #endif #define _dpppDEC2BCD(dec) ((((dec)/100)<<8)|((((dec)%100)/10)<<4)|((dec)%10)) #define PERL_BCDVERSION ((_dpppDEC2BCD(PERL_REVISION)<<24)|(_dpppDEC2BCD(PERL_VERSION)<<12)|_dpppDEC2BCD(PERL_SUBVERSION)) /* It is very unlikely that anyone will try to use this with Perl 6 (or greater), but who knows. */ #if PERL_REVISION != 5 # error ppport.h only works with Perl version 5 #endif /* PERL_REVISION != 5 */ #ifndef dTHR # define dTHR dNOOP #endif #ifndef dTHX # define dTHX dNOOP #endif #ifndef dTHXa # define dTHXa(x) dNOOP #endif #ifndef pTHX # define pTHX void #endif #ifndef pTHX_ # define pTHX_ #endif #ifndef aTHX # define aTHX #endif #ifndef aTHX_ # define aTHX_ #endif #if (PERL_BCDVERSION < 0x5006000) # ifdef USE_THREADS # define aTHXR thr # define aTHXR_ thr, # else # define aTHXR # define aTHXR_ # endif # define dTHXR dTHR #else # define aTHXR aTHX # define aTHXR_ aTHX_ # define dTHXR dTHX #endif #ifndef dTHXoa # define dTHXoa(x) dTHXa(x) #endif #ifdef I_LIMITS # include #endif #ifndef PERL_UCHAR_MIN # define PERL_UCHAR_MIN ((unsigned char)0) #endif #ifndef PERL_UCHAR_MAX # ifdef UCHAR_MAX # define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX) # else # ifdef MAXUCHAR # define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR) # else # define PERL_UCHAR_MAX ((unsigned char)~(unsigned)0) # endif # endif #endif #ifndef PERL_USHORT_MIN # define PERL_USHORT_MIN ((unsigned short)0) #endif #ifndef PERL_USHORT_MAX # ifdef USHORT_MAX # define PERL_USHORT_MAX ((unsigned short)USHORT_MAX) # else # ifdef MAXUSHORT # define PERL_USHORT_MAX ((unsigned short)MAXUSHORT) # else # ifdef USHRT_MAX # define PERL_USHORT_MAX ((unsigned short)USHRT_MAX) # else # define PERL_USHORT_MAX ((unsigned short)~(unsigned)0) # endif # endif # endif #endif #ifndef PERL_SHORT_MAX # ifdef SHORT_MAX # define PERL_SHORT_MAX ((short)SHORT_MAX) # else # ifdef MAXSHORT /* Often used in */ # define PERL_SHORT_MAX ((short)MAXSHORT) # else # ifdef SHRT_MAX # define PERL_SHORT_MAX ((short)SHRT_MAX) # else # define PERL_SHORT_MAX ((short) (PERL_USHORT_MAX >> 1)) # endif # endif # endif #endif #ifndef PERL_SHORT_MIN # ifdef SHORT_MIN # define PERL_SHORT_MIN ((short)SHORT_MIN) # else # ifdef MINSHORT # define PERL_SHORT_MIN ((short)MINSHORT) # else # ifdef SHRT_MIN # define PERL_SHORT_MIN ((short)SHRT_MIN) # else # define PERL_SHORT_MIN (-PERL_SHORT_MAX - ((3 & -1) == 3)) # endif # endif # endif #endif #ifndef PERL_UINT_MAX # ifdef UINT_MAX # define PERL_UINT_MAX ((unsigned int)UINT_MAX) # else # ifdef MAXUINT # define PERL_UINT_MAX ((unsigned int)MAXUINT) # else # define PERL_UINT_MAX (~(unsigned int)0) # endif # endif #endif #ifndef PERL_UINT_MIN # define PERL_UINT_MIN ((unsigned int)0) #endif #ifndef PERL_INT_MAX # ifdef INT_MAX # define PERL_INT_MAX ((int)INT_MAX) # else # ifdef MAXINT /* Often used in */ # define PERL_INT_MAX ((int)MAXINT) # else # define PERL_INT_MAX ((int)(PERL_UINT_MAX >> 1)) # endif # endif #endif #ifndef PERL_INT_MIN # ifdef INT_MIN # define PERL_INT_MIN ((int)INT_MIN) # else # ifdef MININT # define PERL_INT_MIN ((int)MININT) # else # define PERL_INT_MIN (-PERL_INT_MAX - ((3 & -1) == 3)) # endif # endif #endif #ifndef PERL_ULONG_MAX # ifdef ULONG_MAX # define PERL_ULONG_MAX ((unsigned long)ULONG_MAX) # else # ifdef MAXULONG # define PERL_ULONG_MAX ((unsigned long)MAXULONG) # else # define PERL_ULONG_MAX (~(unsigned long)0) # endif # endif #endif #ifndef PERL_ULONG_MIN # define PERL_ULONG_MIN ((unsigned long)0L) #endif #ifndef PERL_LONG_MAX # ifdef LONG_MAX # define PERL_LONG_MAX ((long)LONG_MAX) # else # ifdef MAXLONG # define PERL_LONG_MAX ((long)MAXLONG) # else # define PERL_LONG_MAX ((long) (PERL_ULONG_MAX >> 1)) # endif # endif #endif #ifndef PERL_LONG_MIN # ifdef LONG_MIN # define PERL_LONG_MIN ((long)LONG_MIN) # else # ifdef MINLONG # define PERL_LONG_MIN ((long)MINLONG) # else # define PERL_LONG_MIN (-PERL_LONG_MAX - ((3 & -1) == 3)) # endif # endif #endif #if defined(HAS_QUAD) && (defined(convex) || defined(uts)) # ifndef PERL_UQUAD_MAX # ifdef ULONGLONG_MAX # define PERL_UQUAD_MAX ((unsigned long long)ULONGLONG_MAX) # else # ifdef MAXULONGLONG # define PERL_UQUAD_MAX ((unsigned long long)MAXULONGLONG) # else # define PERL_UQUAD_MAX (~(unsigned long long)0) # endif # endif # endif # ifndef PERL_UQUAD_MIN # define PERL_UQUAD_MIN ((unsigned long long)0L) # endif # ifndef PERL_QUAD_MAX # ifdef LONGLONG_MAX # define PERL_QUAD_MAX ((long long)LONGLONG_MAX) # else # ifdef MAXLONGLONG # define PERL_QUAD_MAX ((long long)MAXLONGLONG) # else # define PERL_QUAD_MAX ((long long) (PERL_UQUAD_MAX >> 1)) # endif # endif # endif # ifndef PERL_QUAD_MIN # ifdef LONGLONG_MIN # define PERL_QUAD_MIN ((long long)LONGLONG_MIN) # else # ifdef MINLONGLONG # define PERL_QUAD_MIN ((long long)MINLONGLONG) # else # define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3)) # endif # endif # endif #endif /* This is based on code from 5.003 perl.h */ #ifdef HAS_QUAD # ifdef cray #ifndef IVTYPE # define IVTYPE int #endif #ifndef IV_MIN # define IV_MIN PERL_INT_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_INT_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_UINT_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_UINT_MAX #endif # ifdef INTSIZE #ifndef IVSIZE # define IVSIZE INTSIZE #endif # endif # else # if defined(convex) || defined(uts) #ifndef IVTYPE # define IVTYPE long long #endif #ifndef IV_MIN # define IV_MIN PERL_QUAD_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_QUAD_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_UQUAD_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_UQUAD_MAX #endif # ifdef LONGLONGSIZE #ifndef IVSIZE # define IVSIZE LONGLONGSIZE #endif # endif # else #ifndef IVTYPE # define IVTYPE long #endif #ifndef IV_MIN # define IV_MIN PERL_LONG_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_LONG_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_ULONG_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_ULONG_MAX #endif # ifdef LONGSIZE #ifndef IVSIZE # define IVSIZE LONGSIZE #endif # endif # endif # endif #ifndef IVSIZE # define IVSIZE 8 #endif #ifndef PERL_QUAD_MIN # define PERL_QUAD_MIN IV_MIN #endif #ifndef PERL_QUAD_MAX # define PERL_QUAD_MAX IV_MAX #endif #ifndef PERL_UQUAD_MIN # define PERL_UQUAD_MIN UV_MIN #endif #ifndef PERL_UQUAD_MAX # define PERL_UQUAD_MAX UV_MAX #endif #else #ifndef IVTYPE # define IVTYPE long #endif #ifndef IV_MIN # define IV_MIN PERL_LONG_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_LONG_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_ULONG_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_ULONG_MAX #endif #endif #ifndef IVSIZE # ifdef LONGSIZE # define IVSIZE LONGSIZE # else # define IVSIZE 4 /* A bold guess, but the best we can make. */ # endif #endif #ifndef UVTYPE # define UVTYPE unsigned IVTYPE #endif #ifndef UVSIZE # define UVSIZE IVSIZE #endif #ifndef sv_setuv # define sv_setuv(sv, uv) \ STMT_START { \ UV TeMpUv = uv; \ if (TeMpUv <= IV_MAX) \ sv_setiv(sv, TeMpUv); \ else \ sv_setnv(sv, (double)TeMpUv); \ } STMT_END #endif #ifndef newSVuv # define newSVuv(uv) ((uv) <= IV_MAX ? newSViv((IV)uv) : newSVnv((NV)uv)) #endif #ifndef sv_2uv # define sv_2uv(sv) ((PL_Sv = (sv)), (UV) (SvNOK(PL_Sv) ? SvNV(PL_Sv) : sv_2nv(PL_Sv))) #endif #ifndef SvUVX # define SvUVX(sv) ((UV)SvIVX(sv)) #endif #ifndef SvUVXx # define SvUVXx(sv) SvUVX(sv) #endif #ifndef SvUV # define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv)) #endif #ifndef SvUVx # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv)) #endif /* Hint: sv_uv * Always use the SvUVx() macro instead of sv_uv(). */ #ifndef sv_uv # define sv_uv(sv) SvUVx(sv) #endif #if !defined(SvUOK) && defined(SvIOK_UV) # define SvUOK(sv) SvIOK_UV(sv) #endif #ifndef XST_mUV # define XST_mUV(i,v) (ST(i) = sv_2mortal(newSVuv(v)) ) #endif #ifndef XSRETURN_UV # define XSRETURN_UV(v) STMT_START { XST_mUV(0,v); XSRETURN(1); } STMT_END #endif #ifndef PUSHu # define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END #endif #ifndef XPUSHu # define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END #endif #ifdef HAS_MEMCMP #ifndef memNE # define memNE(s1,s2,l) (memcmp(s1,s2,l)) #endif #ifndef memEQ # define memEQ(s1,s2,l) (!memcmp(s1,s2,l)) #endif #else #ifndef memNE # define memNE(s1,s2,l) (bcmp(s1,s2,l)) #endif #ifndef memEQ # define memEQ(s1,s2,l) (!bcmp(s1,s2,l)) #endif #endif #ifndef MoveD # define MoveD(s,d,n,t) memmove((char*)(d),(char*)(s), (n) * sizeof(t)) #endif #ifndef CopyD # define CopyD(s,d,n,t) memcpy((char*)(d),(char*)(s), (n) * sizeof(t)) #endif #ifdef HAS_MEMSET #ifndef ZeroD # define ZeroD(d,n,t) memzero((char*)(d), (n) * sizeof(t)) #endif #else #ifndef ZeroD # define ZeroD(d,n,t) ((void)memzero((char*)(d), (n) * sizeof(t)), d) #endif #endif #ifndef PoisonWith # define PoisonWith(d,n,t,b) (void)memset((char*)(d), (U8)(b), (n) * sizeof(t)) #endif #ifndef PoisonNew # define PoisonNew(d,n,t) PoisonWith(d,n,t,0xAB) #endif #ifndef PoisonFree # define PoisonFree(d,n,t) PoisonWith(d,n,t,0xEF) #endif #ifndef Poison # define Poison(d,n,t) PoisonFree(d,n,t) #endif #ifndef Newx # define Newx(v,n,t) New(0,v,n,t) #endif #ifndef Newxc # define Newxc(v,n,t,c) Newc(0,v,n,t,c) #endif #ifndef Newxz # define Newxz(v,n,t) Newz(0,v,n,t) #endif #ifndef PERL_UNUSED_DECL # ifdef HASATTRIBUTE # if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER) # define PERL_UNUSED_DECL # else # define PERL_UNUSED_DECL __attribute__((unused)) # endif # else # define PERL_UNUSED_DECL # endif #endif #ifndef PERL_UNUSED_ARG # if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */ # include # define PERL_UNUSED_ARG(x) NOTE(ARGUNUSED(x)) # else # define PERL_UNUSED_ARG(x) ((void)x) # endif #endif #ifndef PERL_UNUSED_VAR # define PERL_UNUSED_VAR(x) ((void)x) #endif #ifndef PERL_UNUSED_CONTEXT # ifdef USE_ITHREADS # define PERL_UNUSED_CONTEXT PERL_UNUSED_ARG(my_perl) # else # define PERL_UNUSED_CONTEXT # endif #endif #ifndef NOOP # define NOOP /*EMPTY*/(void)0 #endif #ifndef dNOOP # define dNOOP extern int /*@unused@*/ Perl___notused PERL_UNUSED_DECL #endif #ifndef NVTYPE # if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE) # define NVTYPE long double # else # define NVTYPE double # endif typedef NVTYPE NV; #endif #ifndef INT2PTR # if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE) # define PTRV UV # define INT2PTR(any,d) (any)(d) # else # if PTRSIZE == LONGSIZE # define PTRV unsigned long # else # define PTRV unsigned # endif # define INT2PTR(any,d) (any)(PTRV)(d) # endif #endif #ifndef PTR2ul # if PTRSIZE == LONGSIZE # define PTR2ul(p) (unsigned long)(p) # else # define PTR2ul(p) INT2PTR(unsigned long,p) # endif #endif #ifndef PTR2nat # define PTR2nat(p) (PTRV)(p) #endif #ifndef NUM2PTR # define NUM2PTR(any,d) (any)PTR2nat(d) #endif #ifndef PTR2IV # define PTR2IV(p) INT2PTR(IV,p) #endif #ifndef PTR2UV # define PTR2UV(p) INT2PTR(UV,p) #endif #ifndef PTR2NV # define PTR2NV(p) NUM2PTR(NV,p) #endif #undef START_EXTERN_C #undef END_EXTERN_C #undef EXTERN_C #ifdef __cplusplus # define START_EXTERN_C extern "C" { # define END_EXTERN_C } # define EXTERN_C extern "C" #else # define START_EXTERN_C # define END_EXTERN_C # define EXTERN_C extern #endif #if defined(PERL_GCC_PEDANTIC) # ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN # define PERL_GCC_BRACE_GROUPS_FORBIDDEN # endif #endif #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus) # ifndef PERL_USE_GCC_BRACE_GROUPS # define PERL_USE_GCC_BRACE_GROUPS # endif #endif #undef STMT_START #undef STMT_END #ifdef PERL_USE_GCC_BRACE_GROUPS # define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */ # define STMT_END ) #else # if defined(VOIDFLAGS) && (VOIDFLAGS) && (defined(sun) || defined(__sun__)) && !defined(__GNUC__) # define STMT_START if (1) # define STMT_END else (void)0 # else # define STMT_START do # define STMT_END while (0) # endif #endif #ifndef boolSV # define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no) #endif /* DEFSV appears first in 5.004_56 */ #ifndef DEFSV # define DEFSV GvSV(PL_defgv) #endif #ifndef SAVE_DEFSV # define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv)) #endif #ifndef DEFSV_set # define DEFSV_set(sv) (DEFSV = (sv)) #endif /* Older perls (<=5.003) lack AvFILLp */ #ifndef AvFILLp # define AvFILLp AvFILL #endif #ifndef ERRSV # define ERRSV get_sv("@",FALSE) #endif /* Hint: gv_stashpvn * This function's backport doesn't support the length parameter, but * rather ignores it. Portability can only be ensured if the length * parameter is used for speed reasons, but the length can always be * correctly computed from the string argument. */ #ifndef gv_stashpvn # define gv_stashpvn(str,len,create) gv_stashpv(str,create) #endif /* Replace: 1 */ #ifndef get_cv # define get_cv perl_get_cv #endif #ifndef get_sv # define get_sv perl_get_sv #endif #ifndef get_av # define get_av perl_get_av #endif #ifndef get_hv # define get_hv perl_get_hv #endif /* Replace: 0 */ #ifndef dUNDERBAR # define dUNDERBAR dNOOP #endif #ifndef UNDERBAR # define UNDERBAR DEFSV #endif #ifndef dAX # define dAX I32 ax = MARK - PL_stack_base + 1 #endif #ifndef dITEMS # define dITEMS I32 items = SP - MARK #endif #ifndef dXSTARG # define dXSTARG SV * targ = sv_newmortal() #endif #ifndef dAXMARK # define dAXMARK I32 ax = POPMARK; \ register SV ** const mark = PL_stack_base + ax++ #endif #ifndef XSprePUSH # define XSprePUSH (sp = PL_stack_base + ax - 1) #endif #if (PERL_BCDVERSION < 0x5005000) # undef XSRETURN # define XSRETURN(off) \ STMT_START { \ PL_stack_sp = PL_stack_base + ax + ((off) - 1); \ return; \ } STMT_END #endif #ifndef XSPROTO # define XSPROTO(name) void name(pTHX_ CV* cv) #endif #ifndef SVfARG # define SVfARG(p) ((void*)(p)) #endif #ifndef PERL_ABS # define PERL_ABS(x) ((x) < 0 ? -(x) : (x)) #endif #ifndef dVAR # define dVAR dNOOP #endif #ifndef SVf # define SVf "_" #endif #ifndef UTF8_MAXBYTES # define UTF8_MAXBYTES UTF8_MAXLEN #endif #ifndef CPERLscope # define CPERLscope(x) x #endif #ifndef PERL_HASH # define PERL_HASH(hash,str,len) \ STMT_START { \ const char *s_PeRlHaSh = str; \ I32 i_PeRlHaSh = len; \ U32 hash_PeRlHaSh = 0; \ while (i_PeRlHaSh--) \ hash_PeRlHaSh = hash_PeRlHaSh * 33 + *s_PeRlHaSh++; \ (hash) = hash_PeRlHaSh; \ } STMT_END #endif #ifndef PERLIO_FUNCS_DECL # ifdef PERLIO_FUNCS_CONST # define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs # define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs) # else # define PERLIO_FUNCS_DECL(funcs) PerlIO_funcs funcs # define PERLIO_FUNCS_CAST(funcs) (funcs) # endif #endif /* provide these typedefs for older perls */ #if (PERL_BCDVERSION < 0x5009003) # ifdef ARGSproto typedef OP* (CPERLscope(*Perl_ppaddr_t))(ARGSproto); # else typedef OP* (CPERLscope(*Perl_ppaddr_t))(pTHX); # endif typedef OP* (CPERLscope(*Perl_check_t)) (pTHX_ OP*); #endif #ifndef isPSXSPC # define isPSXSPC(c) (isSPACE(c) || (c) == '\v') #endif #ifndef isBLANK # define isBLANK(c) ((c) == ' ' || (c) == '\t') #endif #ifdef EBCDIC #ifndef isALNUMC # define isALNUMC(c) isalnum(c) #endif #ifndef isASCII # define isASCII(c) isascii(c) #endif #ifndef isCNTRL # define isCNTRL(c) iscntrl(c) #endif #ifndef isGRAPH # define isGRAPH(c) isgraph(c) #endif #ifndef isPRINT # define isPRINT(c) isprint(c) #endif #ifndef isPUNCT # define isPUNCT(c) ispunct(c) #endif #ifndef isXDIGIT # define isXDIGIT(c) isxdigit(c) #endif #else # if (PERL_BCDVERSION < 0x5010000) /* Hint: isPRINT * The implementation in older perl versions includes all of the * isSPACE() characters, which is wrong. The version provided by * Devel::PPPort always overrides a present buggy version. */ # undef isPRINT # endif #ifndef isALNUMC # define isALNUMC(c) (isALPHA(c) || isDIGIT(c)) #endif #ifndef isASCII # define isASCII(c) ((c) <= 127) #endif #ifndef isCNTRL # define isCNTRL(c) ((c) < ' ' || (c) == 127) #endif #ifndef isGRAPH # define isGRAPH(c) (isALNUM(c) || isPUNCT(c)) #endif #ifndef isPRINT # define isPRINT(c) (((c) >= 32 && (c) < 127)) #endif #ifndef isPUNCT # define isPUNCT(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126)) #endif #ifndef isXDIGIT # define isXDIGIT(c) (isDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) #endif #endif #ifndef PERL_SIGNALS_UNSAFE_FLAG #define PERL_SIGNALS_UNSAFE_FLAG 0x0001 #if (PERL_BCDVERSION < 0x5008000) # define D_PPP_PERL_SIGNALS_INIT PERL_SIGNALS_UNSAFE_FLAG #else # define D_PPP_PERL_SIGNALS_INIT 0 #endif #if defined(NEED_PL_signals) static U32 DPPP_(my_PL_signals) = D_PPP_PERL_SIGNALS_INIT; #elif defined(NEED_PL_signals_GLOBAL) U32 DPPP_(my_PL_signals) = D_PPP_PERL_SIGNALS_INIT; #else extern U32 DPPP_(my_PL_signals); #endif #define PL_signals DPPP_(my_PL_signals) #endif /* Hint: PL_ppaddr * Calling an op via PL_ppaddr requires passing a context argument * for threaded builds. Since the context argument is different for * 5.005 perls, you can use aTHXR (supplied by ppport.h), which will * automatically be defined as the correct argument. */ #if (PERL_BCDVERSION <= 0x5005005) /* Replace: 1 */ # define PL_ppaddr ppaddr # define PL_no_modify no_modify /* Replace: 0 */ #endif #if (PERL_BCDVERSION <= 0x5004005) /* Replace: 1 */ # define PL_DBsignal DBsignal # define PL_DBsingle DBsingle # define PL_DBsub DBsub # define PL_DBtrace DBtrace # define PL_Sv Sv # define PL_bufend bufend # define PL_bufptr bufptr # define PL_compiling compiling # define PL_copline copline # define PL_curcop curcop # define PL_curstash curstash # define PL_debstash debstash # define PL_defgv defgv # define PL_diehook diehook # define PL_dirty dirty # define PL_dowarn dowarn # define PL_errgv errgv # define PL_error_count error_count # define PL_expect expect # define PL_hexdigit hexdigit # define PL_hints hints # define PL_in_my in_my # define PL_laststatval laststatval # define PL_lex_state lex_state # define PL_lex_stuff lex_stuff # define PL_linestr linestr # define PL_na na # define PL_perl_destruct_level perl_destruct_level # define PL_perldb perldb # define PL_rsfp_filters rsfp_filters # define PL_rsfp rsfp # define PL_stack_base stack_base # define PL_stack_sp stack_sp # define PL_statcache statcache # define PL_stdingv stdingv # define PL_sv_arenaroot sv_arenaroot # define PL_sv_no sv_no # define PL_sv_undef sv_undef # define PL_sv_yes sv_yes # define PL_tainted tainted # define PL_tainting tainting # define PL_tokenbuf tokenbuf /* Replace: 0 */ #endif /* Warning: PL_parser * For perl versions earlier than 5.9.5, this is an always * non-NULL dummy. Also, it cannot be dereferenced. Don't * use it if you can avoid is and unless you absolutely know * what you're doing. * If you always check that PL_parser is non-NULL, you can * define DPPP_PL_parser_NO_DUMMY to avoid the creation of * a dummy parser structure. */ #if (PERL_BCDVERSION >= 0x5009005) # ifdef DPPP_PL_parser_NO_DUMMY # define D_PPP_my_PL_parser_var(var) ((PL_parser ? PL_parser : \ (croak("panic: PL_parser == NULL in %s:%d", \ __FILE__, __LINE__), (yy_parser *) NULL))->var) # else # ifdef DPPP_PL_parser_NO_DUMMY_WARNING # define D_PPP_parser_dummy_warning(var) # else # define D_PPP_parser_dummy_warning(var) \ warn("warning: dummy PL_" #var " used in %s:%d", __FILE__, __LINE__), # endif # define D_PPP_my_PL_parser_var(var) ((PL_parser ? PL_parser : \ (D_PPP_parser_dummy_warning(var) &DPPP_(dummy_PL_parser)))->var) #if defined(NEED_PL_parser) static yy_parser DPPP_(dummy_PL_parser); #elif defined(NEED_PL_parser_GLOBAL) yy_parser DPPP_(dummy_PL_parser); #else extern yy_parser DPPP_(dummy_PL_parser); #endif # endif /* PL_expect, PL_copline, PL_rsfp, PL_rsfp_filters, PL_linestr, PL_bufptr, PL_bufend, PL_lex_state, PL_lex_stuff, PL_tokenbuf depends on PL_parser */ /* Warning: PL_expect, PL_copline, PL_rsfp, PL_rsfp_filters, PL_linestr, PL_bufptr, PL_bufend, PL_lex_state, PL_lex_stuff, PL_tokenbuf * Do not use this variable unless you know exactly what you're * doint. It is internal to the perl parser and may change or even * be removed in the future. As of perl 5.9.5, you have to check * for (PL_parser != NULL) for this variable to have any effect. * An always non-NULL PL_parser dummy is provided for earlier * perl versions. * If PL_parser is NULL when you try to access this variable, a * dummy is being accessed instead and a warning is issued unless * you define DPPP_PL_parser_NO_DUMMY_WARNING. * If DPPP_PL_parser_NO_DUMMY is defined, the code trying to access * this variable will croak with a panic message. */ # define PL_expect D_PPP_my_PL_parser_var(expect) # define PL_copline D_PPP_my_PL_parser_var(copline) # define PL_rsfp D_PPP_my_PL_parser_var(rsfp) # define PL_rsfp_filters D_PPP_my_PL_parser_var(rsfp_filters) # define PL_linestr D_PPP_my_PL_parser_var(linestr) # define PL_bufptr D_PPP_my_PL_parser_var(bufptr) # define PL_bufend D_PPP_my_PL_parser_var(bufend) # define PL_lex_state D_PPP_my_PL_parser_var(lex_state) # define PL_lex_stuff D_PPP_my_PL_parser_var(lex_stuff) # define PL_tokenbuf D_PPP_my_PL_parser_var(tokenbuf) # define PL_in_my D_PPP_my_PL_parser_var(in_my) # define PL_in_my_stash D_PPP_my_PL_parser_var(in_my_stash) # define PL_error_count D_PPP_my_PL_parser_var(error_count) #else /* ensure that PL_parser != NULL and cannot be dereferenced */ # define PL_parser ((void *) 1) #endif #ifndef mPUSHs # define mPUSHs(s) PUSHs(sv_2mortal(s)) #endif #ifndef PUSHmortal # define PUSHmortal PUSHs(sv_newmortal()) #endif #ifndef mPUSHp # define mPUSHp(p,l) sv_setpvn(PUSHmortal, (p), (l)) #endif #ifndef mPUSHn # define mPUSHn(n) sv_setnv(PUSHmortal, (NV)(n)) #endif #ifndef mPUSHi # define mPUSHi(i) sv_setiv(PUSHmortal, (IV)(i)) #endif #ifndef mPUSHu # define mPUSHu(u) sv_setuv(PUSHmortal, (UV)(u)) #endif #ifndef mXPUSHs # define mXPUSHs(s) XPUSHs(sv_2mortal(s)) #endif #ifndef XPUSHmortal # define XPUSHmortal XPUSHs(sv_newmortal()) #endif #ifndef mXPUSHp # define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); sv_setpvn(PUSHmortal, (p), (l)); } STMT_END #endif #ifndef mXPUSHn # define mXPUSHn(n) STMT_START { EXTEND(sp,1); sv_setnv(PUSHmortal, (NV)(n)); } STMT_END #endif #ifndef mXPUSHi # define mXPUSHi(i) STMT_START { EXTEND(sp,1); sv_setiv(PUSHmortal, (IV)(i)); } STMT_END #endif #ifndef mXPUSHu # define mXPUSHu(u) STMT_START { EXTEND(sp,1); sv_setuv(PUSHmortal, (UV)(u)); } STMT_END #endif /* Replace: 1 */ #ifndef call_sv # define call_sv perl_call_sv #endif #ifndef call_pv # define call_pv perl_call_pv #endif #ifndef call_argv # define call_argv perl_call_argv #endif #ifndef call_method # define call_method perl_call_method #endif #ifndef eval_sv # define eval_sv perl_eval_sv #endif /* Replace: 0 */ #ifndef PERL_LOADMOD_DENY # define PERL_LOADMOD_DENY 0x1 #endif #ifndef PERL_LOADMOD_NOIMPORT # define PERL_LOADMOD_NOIMPORT 0x2 #endif #ifndef PERL_LOADMOD_IMPORT_OPS # define PERL_LOADMOD_IMPORT_OPS 0x4 #endif #ifndef G_METHOD # define G_METHOD 64 # ifdef call_sv # undef call_sv # endif # if (PERL_BCDVERSION < 0x5006000) # define call_sv(sv, flags) ((flags) & G_METHOD ? perl_call_method((char *) SvPV_nolen_const(sv), \ (flags) & ~G_METHOD) : perl_call_sv(sv, flags)) # else # define call_sv(sv, flags) ((flags) & G_METHOD ? Perl_call_method(aTHX_ (char *) SvPV_nolen_const(sv), \ (flags) & ~G_METHOD) : Perl_call_sv(aTHX_ sv, flags)) # endif #endif /* Replace perl_eval_pv with eval_pv */ #ifndef eval_pv #if defined(NEED_eval_pv) static SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error); static #else extern SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error); #endif #ifdef eval_pv # undef eval_pv #endif #define eval_pv(a,b) DPPP_(my_eval_pv)(aTHX_ a,b) #define Perl_eval_pv DPPP_(my_eval_pv) #if defined(NEED_eval_pv) || defined(NEED_eval_pv_GLOBAL) SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error) { dSP; SV* sv = newSVpv(p, 0); PUSHMARK(sp); eval_sv(sv, G_SCALAR); SvREFCNT_dec(sv); SPAGAIN; sv = POPs; PUTBACK; if (croak_on_error && SvTRUE(GvSV(errgv))) croak(SvPVx(GvSV(errgv), na)); return sv; } #endif #endif #ifndef vload_module #if defined(NEED_vload_module) static void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args); static #else extern void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args); #endif #ifdef vload_module # undef vload_module #endif #define vload_module(a,b,c,d) DPPP_(my_vload_module)(aTHX_ a,b,c,d) #define Perl_vload_module DPPP_(my_vload_module) #if defined(NEED_vload_module) || defined(NEED_vload_module_GLOBAL) void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args) { dTHR; dVAR; OP *veop, *imop; OP * const modname = newSVOP(OP_CONST, 0, name); /* 5.005 has a somewhat hacky force_normal that doesn't croak on SvREADONLY() if PL_compling is true. Current perls take care in ck_require() to correctly turn off SvREADONLY before calling force_normal_flags(). This seems a better fix than fudging PL_compling */ SvREADONLY_off(((SVOP*)modname)->op_sv); modname->op_private |= OPpCONST_BARE; if (ver) { veop = newSVOP(OP_CONST, 0, ver); } else veop = NULL; if (flags & PERL_LOADMOD_NOIMPORT) { imop = sawparens(newNULLLIST()); } else if (flags & PERL_LOADMOD_IMPORT_OPS) { imop = va_arg(*args, OP*); } else { SV *sv; imop = NULL; sv = va_arg(*args, SV*); while (sv) { imop = append_elem(OP_LIST, imop, newSVOP(OP_CONST, 0, sv)); sv = va_arg(*args, SV*); } } { const line_t ocopline = PL_copline; COP * const ocurcop = PL_curcop; const int oexpect = PL_expect; #if (PERL_BCDVERSION >= 0x5004000) utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(FALSE, 0), veop, modname, imop); #else utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(), modname, imop); #endif PL_expect = oexpect; PL_copline = ocopline; PL_curcop = ocurcop; } } #endif #endif #ifndef load_module #if defined(NEED_load_module) static void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...); static #else extern void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...); #endif #ifdef load_module # undef load_module #endif #define load_module DPPP_(my_load_module) #define Perl_load_module DPPP_(my_load_module) #if defined(NEED_load_module) || defined(NEED_load_module_GLOBAL) void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...) { va_list args; va_start(args, ver); vload_module(flags, name, ver, &args); va_end(args); } #endif #endif #ifndef newRV_inc # define newRV_inc(sv) newRV(sv) /* Replace */ #endif #ifndef newRV_noinc #if defined(NEED_newRV_noinc) static SV * DPPP_(my_newRV_noinc)(SV *sv); static #else extern SV * DPPP_(my_newRV_noinc)(SV *sv); #endif #ifdef newRV_noinc # undef newRV_noinc #endif #define newRV_noinc(a) DPPP_(my_newRV_noinc)(aTHX_ a) #define Perl_newRV_noinc DPPP_(my_newRV_noinc) #if defined(NEED_newRV_noinc) || defined(NEED_newRV_noinc_GLOBAL) SV * DPPP_(my_newRV_noinc)(SV *sv) { SV *rv = (SV *)newRV(sv); SvREFCNT_dec(sv); return rv; } #endif #endif /* Hint: newCONSTSUB * Returns a CV* as of perl-5.7.1. This return value is not supported * by Devel::PPPort. */ /* newCONSTSUB from IO.xs is in the core starting with 5.004_63 */ #if (PERL_BCDVERSION < 0x5004063) && (PERL_BCDVERSION != 0x5004005) #if defined(NEED_newCONSTSUB) static void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv); static #else extern void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv); #endif #ifdef newCONSTSUB # undef newCONSTSUB #endif #define newCONSTSUB(a,b,c) DPPP_(my_newCONSTSUB)(aTHX_ a,b,c) #define Perl_newCONSTSUB DPPP_(my_newCONSTSUB) #if defined(NEED_newCONSTSUB) || defined(NEED_newCONSTSUB_GLOBAL) /* This is just a trick to avoid a dependency of newCONSTSUB on PL_parser */ /* (There's no PL_parser in perl < 5.005, so this is completely safe) */ #define D_PPP_PL_copline PL_copline void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv) { U32 oldhints = PL_hints; HV *old_cop_stash = PL_curcop->cop_stash; HV *old_curstash = PL_curstash; line_t oldline = PL_curcop->cop_line; PL_curcop->cop_line = D_PPP_PL_copline; PL_hints &= ~HINT_BLOCK_SCOPE; if (stash) PL_curstash = PL_curcop->cop_stash = stash; newSUB( #if (PERL_BCDVERSION < 0x5003022) start_subparse(), #elif (PERL_BCDVERSION == 0x5003022) start_subparse(0), #else /* 5.003_23 onwards */ start_subparse(FALSE, 0), #endif newSVOP(OP_CONST, 0, newSVpv((char *) name, 0)), newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */ newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv)) ); PL_hints = oldhints; PL_curcop->cop_stash = old_cop_stash; PL_curstash = old_curstash; PL_curcop->cop_line = oldline; } #endif #endif /* * Boilerplate macros for initializing and accessing interpreter-local * data from C. All statics in extensions should be reworked to use * this, if you want to make the extension thread-safe. See ext/re/re.xs * for an example of the use of these macros. * * Code that uses these macros is responsible for the following: * 1. #define MY_CXT_KEY to a unique string, e.g. "DynaLoader_guts" * 2. Declare a typedef named my_cxt_t that is a structure that contains * all the data that needs to be interpreter-local. * 3. Use the START_MY_CXT macro after the declaration of my_cxt_t. * 4. Use the MY_CXT_INIT macro such that it is called exactly once * (typically put in the BOOT: section). * 5. Use the members of the my_cxt_t structure everywhere as * MY_CXT.member. * 6. Use the dMY_CXT macro (a declaration) in all the functions that * access MY_CXT. */ #if defined(MULTIPLICITY) || defined(PERL_OBJECT) || \ defined(PERL_CAPI) || defined(PERL_IMPLICIT_CONTEXT) #ifndef START_MY_CXT /* This must appear in all extensions that define a my_cxt_t structure, * right after the definition (i.e. at file scope). The non-threads * case below uses it to declare the data as static. */ #define START_MY_CXT #if (PERL_BCDVERSION < 0x5004068) /* Fetches the SV that keeps the per-interpreter data. */ #define dMY_CXT_SV \ SV *my_cxt_sv = get_sv(MY_CXT_KEY, FALSE) #else /* >= perl5.004_68 */ #define dMY_CXT_SV \ SV *my_cxt_sv = *hv_fetch(PL_modglobal, MY_CXT_KEY, \ sizeof(MY_CXT_KEY)-1, TRUE) #endif /* < perl5.004_68 */ /* This declaration should be used within all functions that use the * interpreter-local data. */ #define dMY_CXT \ dMY_CXT_SV; \ my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*,SvUV(my_cxt_sv)) /* Creates and zeroes the per-interpreter data. * (We allocate my_cxtp in a Perl SV so that it will be released when * the interpreter goes away.) */ #define MY_CXT_INIT \ dMY_CXT_SV; \ /* newSV() allocates one more than needed */ \ my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\ Zero(my_cxtp, 1, my_cxt_t); \ sv_setuv(my_cxt_sv, PTR2UV(my_cxtp)) /* This macro must be used to access members of the my_cxt_t structure. * e.g. MYCXT.some_data */ #define MY_CXT (*my_cxtp) /* Judicious use of these macros can reduce the number of times dMY_CXT * is used. Use is similar to pTHX, aTHX etc. */ #define pMY_CXT my_cxt_t *my_cxtp #define pMY_CXT_ pMY_CXT, #define _pMY_CXT ,pMY_CXT #define aMY_CXT my_cxtp #define aMY_CXT_ aMY_CXT, #define _aMY_CXT ,aMY_CXT #endif /* START_MY_CXT */ #ifndef MY_CXT_CLONE /* Clones the per-interpreter data. */ #define MY_CXT_CLONE \ dMY_CXT_SV; \ my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\ Copy(INT2PTR(my_cxt_t*, SvUV(my_cxt_sv)), my_cxtp, 1, my_cxt_t);\ sv_setuv(my_cxt_sv, PTR2UV(my_cxtp)) #endif #else /* single interpreter */ #ifndef START_MY_CXT #define START_MY_CXT static my_cxt_t my_cxt; #define dMY_CXT_SV dNOOP #define dMY_CXT dNOOP #define MY_CXT_INIT NOOP #define MY_CXT my_cxt #define pMY_CXT void #define pMY_CXT_ #define _pMY_CXT #define aMY_CXT #define aMY_CXT_ #define _aMY_CXT #endif /* START_MY_CXT */ #ifndef MY_CXT_CLONE #define MY_CXT_CLONE NOOP #endif #endif #ifndef IVdf # if IVSIZE == LONGSIZE # define IVdf "ld" # define UVuf "lu" # define UVof "lo" # define UVxf "lx" # define UVXf "lX" # else # if IVSIZE == INTSIZE # define IVdf "d" # define UVuf "u" # define UVof "o" # define UVxf "x" # define UVXf "X" # endif # endif #endif #ifndef NVef # if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE) && \ defined(PERL_PRIfldbl) && (PERL_BCDVERSION != 0x5006000) /* Not very likely, but let's try anyway. */ # define NVef PERL_PRIeldbl # define NVff PERL_PRIfldbl # define NVgf PERL_PRIgldbl # else # define NVef "e" # define NVff "f" # define NVgf "g" # endif #endif #ifndef SvREFCNT_inc # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ if (_sv) \ (SvREFCNT(_sv))++; \ _sv; \ }) # else # define SvREFCNT_inc(sv) \ ((PL_Sv=(SV*)(sv)) ? (++(SvREFCNT(PL_Sv)),PL_Sv) : NULL) # endif #endif #ifndef SvREFCNT_inc_simple # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc_simple(sv) \ ({ \ if (sv) \ (SvREFCNT(sv))++; \ (SV *)(sv); \ }) # else # define SvREFCNT_inc_simple(sv) \ ((sv) ? (SvREFCNT(sv)++,(SV*)(sv)) : NULL) # endif #endif #ifndef SvREFCNT_inc_NN # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc_NN(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ SvREFCNT(_sv)++; \ _sv; \ }) # else # define SvREFCNT_inc_NN(sv) \ (PL_Sv=(SV*)(sv),++(SvREFCNT(PL_Sv)),PL_Sv) # endif #endif #ifndef SvREFCNT_inc_void # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc_void(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ if (_sv) \ (void)(SvREFCNT(_sv)++); \ }) # else # define SvREFCNT_inc_void(sv) \ (void)((PL_Sv=(SV*)(sv)) ? ++(SvREFCNT(PL_Sv)) : 0) # endif #endif #ifndef SvREFCNT_inc_simple_void # define SvREFCNT_inc_simple_void(sv) STMT_START { if (sv) SvREFCNT(sv)++; } STMT_END #endif #ifndef SvREFCNT_inc_simple_NN # define SvREFCNT_inc_simple_NN(sv) (++SvREFCNT(sv), (SV*)(sv)) #endif #ifndef SvREFCNT_inc_void_NN # define SvREFCNT_inc_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) #endif #ifndef SvREFCNT_inc_simple_void_NN # define SvREFCNT_inc_simple_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) #endif #ifndef newSV_type #if defined(NEED_newSV_type) static SV* DPPP_(my_newSV_type)(pTHX_ svtype const t); static #else extern SV* DPPP_(my_newSV_type)(pTHX_ svtype const t); #endif #ifdef newSV_type # undef newSV_type #endif #define newSV_type(a) DPPP_(my_newSV_type)(aTHX_ a) #define Perl_newSV_type DPPP_(my_newSV_type) #if defined(NEED_newSV_type) || defined(NEED_newSV_type_GLOBAL) SV* DPPP_(my_newSV_type)(pTHX_ svtype const t) { SV* const sv = newSV(0); sv_upgrade(sv, t); return sv; } #endif #endif #if (PERL_BCDVERSION < 0x5006000) # define D_PPP_CONSTPV_ARG(x) ((char *) (x)) #else # define D_PPP_CONSTPV_ARG(x) (x) #endif #ifndef newSVpvn # define newSVpvn(data,len) ((data) \ ? ((len) ? newSVpv((data), (len)) : newSVpv("", 0)) \ : newSV(0)) #endif #ifndef newSVpvn_utf8 # define newSVpvn_utf8(s, len, u) newSVpvn_flags((s), (len), (u) ? SVf_UTF8 : 0) #endif #ifndef SVf_UTF8 # define SVf_UTF8 0 #endif #ifndef newSVpvn_flags #if defined(NEED_newSVpvn_flags) static SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags); static #else extern SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags); #endif #ifdef newSVpvn_flags # undef newSVpvn_flags #endif #define newSVpvn_flags(a,b,c) DPPP_(my_newSVpvn_flags)(aTHX_ a,b,c) #define Perl_newSVpvn_flags DPPP_(my_newSVpvn_flags) #if defined(NEED_newSVpvn_flags) || defined(NEED_newSVpvn_flags_GLOBAL) SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags) { SV *sv = newSVpvn(D_PPP_CONSTPV_ARG(s), len); SvFLAGS(sv) |= (flags & SVf_UTF8); return (flags & SVs_TEMP) ? sv_2mortal(sv) : sv; } #endif #endif /* Backwards compatibility stuff... :-( */ #if !defined(NEED_sv_2pv_flags) && defined(NEED_sv_2pv_nolen) # define NEED_sv_2pv_flags #endif #if !defined(NEED_sv_2pv_flags_GLOBAL) && defined(NEED_sv_2pv_nolen_GLOBAL) # define NEED_sv_2pv_flags_GLOBAL #endif /* Hint: sv_2pv_nolen * Use the SvPV_nolen() or SvPV_nolen_const() macros instead of sv_2pv_nolen(). */ #ifndef sv_2pv_nolen # define sv_2pv_nolen(sv) SvPV_nolen(sv) #endif #ifdef SvPVbyte /* Hint: SvPVbyte * Does not work in perl-5.6.1, ppport.h implements a version * borrowed from perl-5.7.3. */ #if (PERL_BCDVERSION < 0x5007000) #if defined(NEED_sv_2pvbyte) static char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp); static #else extern char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp); #endif #ifdef sv_2pvbyte # undef sv_2pvbyte #endif #define sv_2pvbyte(a,b) DPPP_(my_sv_2pvbyte)(aTHX_ a,b) #define Perl_sv_2pvbyte DPPP_(my_sv_2pvbyte) #if defined(NEED_sv_2pvbyte) || defined(NEED_sv_2pvbyte_GLOBAL) char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp) { sv_utf8_downgrade(sv,0); return SvPV(sv,*lp); } #endif /* Hint: sv_2pvbyte * Use the SvPVbyte() macro instead of sv_2pvbyte(). */ #undef SvPVbyte #define SvPVbyte(sv, lp) \ ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp)) #endif #else # define SvPVbyte SvPV # define sv_2pvbyte sv_2pv #endif #ifndef sv_2pvbyte_nolen # define sv_2pvbyte_nolen(sv) sv_2pv_nolen(sv) #endif /* Hint: sv_pvn * Always use the SvPV() macro instead of sv_pvn(). */ /* Hint: sv_pvn_force * Always use the SvPV_force() macro instead of sv_pvn_force(). */ /* If these are undefined, they're not handled by the core anyway */ #ifndef SV_IMMEDIATE_UNREF # define SV_IMMEDIATE_UNREF 0 #endif #ifndef SV_GMAGIC # define SV_GMAGIC 0 #endif #ifndef SV_COW_DROP_PV # define SV_COW_DROP_PV 0 #endif #ifndef SV_UTF8_NO_ENCODING # define SV_UTF8_NO_ENCODING 0 #endif #ifndef SV_NOSTEAL # define SV_NOSTEAL 0 #endif #ifndef SV_CONST_RETURN # define SV_CONST_RETURN 0 #endif #ifndef SV_MUTABLE_RETURN # define SV_MUTABLE_RETURN 0 #endif #ifndef SV_SMAGIC # define SV_SMAGIC 0 #endif #ifndef SV_HAS_TRAILING_NUL # define SV_HAS_TRAILING_NUL 0 #endif #ifndef SV_COW_SHARED_HASH_KEYS # define SV_COW_SHARED_HASH_KEYS 0 #endif #if (PERL_BCDVERSION < 0x5007002) #if defined(NEED_sv_2pv_flags) static char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); static #else extern char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); #endif #ifdef sv_2pv_flags # undef sv_2pv_flags #endif #define sv_2pv_flags(a,b,c) DPPP_(my_sv_2pv_flags)(aTHX_ a,b,c) #define Perl_sv_2pv_flags DPPP_(my_sv_2pv_flags) #if defined(NEED_sv_2pv_flags) || defined(NEED_sv_2pv_flags_GLOBAL) char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags) { STRLEN n_a = (STRLEN) flags; return sv_2pv(sv, lp ? lp : &n_a); } #endif #if defined(NEED_sv_pvn_force_flags) static char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); static #else extern char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); #endif #ifdef sv_pvn_force_flags # undef sv_pvn_force_flags #endif #define sv_pvn_force_flags(a,b,c) DPPP_(my_sv_pvn_force_flags)(aTHX_ a,b,c) #define Perl_sv_pvn_force_flags DPPP_(my_sv_pvn_force_flags) #if defined(NEED_sv_pvn_force_flags) || defined(NEED_sv_pvn_force_flags_GLOBAL) char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags) { STRLEN n_a = (STRLEN) flags; return sv_pvn_force(sv, lp ? lp : &n_a); } #endif #endif #if (PERL_BCDVERSION < 0x5008008) || ( (PERL_BCDVERSION >= 0x5009000) && (PERL_BCDVERSION < 0x5009003) ) # define DPPP_SVPV_NOLEN_LP_ARG &PL_na #else # define DPPP_SVPV_NOLEN_LP_ARG 0 #endif #ifndef SvPV_const # define SvPV_const(sv, lp) SvPV_flags_const(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_mutable # define SvPV_mutable(sv, lp) SvPV_flags_mutable(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_flags # define SvPV_flags(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags)) #endif #ifndef SvPV_flags_const # define SvPV_flags_const(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_const(sv)) : \ (const char*) sv_2pv_flags(sv, &lp, flags|SV_CONST_RETURN)) #endif #ifndef SvPV_flags_const_nolen # define SvPV_flags_const_nolen(sv, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX_const(sv) : \ (const char*) sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, flags|SV_CONST_RETURN)) #endif #ifndef SvPV_flags_mutable # define SvPV_flags_mutable(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) : \ sv_2pv_flags(sv, &lp, flags|SV_MUTABLE_RETURN)) #endif #ifndef SvPV_force # define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_force_nolen # define SvPV_force_nolen(sv) SvPV_force_flags_nolen(sv, SV_GMAGIC) #endif #ifndef SvPV_force_mutable # define SvPV_force_mutable(sv, lp) SvPV_force_flags_mutable(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_force_nomg # define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0) #endif #ifndef SvPV_force_nomg_nolen # define SvPV_force_nomg_nolen(sv) SvPV_force_flags_nolen(sv, 0) #endif #ifndef SvPV_force_flags # define SvPV_force_flags(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags)) #endif #ifndef SvPV_force_flags_nolen # define SvPV_force_flags_nolen(sv, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? SvPVX(sv) : sv_pvn_force_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, flags)) #endif #ifndef SvPV_force_flags_mutable # define SvPV_force_flags_mutable(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) \ : sv_pvn_force_flags(sv, &lp, flags|SV_MUTABLE_RETURN)) #endif #ifndef SvPV_nolen # define SvPV_nolen(sv) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC)) #endif #ifndef SvPV_nolen_const # define SvPV_nolen_const(sv) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX_const(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC|SV_CONST_RETURN)) #endif #ifndef SvPV_nomg # define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0) #endif #ifndef SvPV_nomg_const # define SvPV_nomg_const(sv, lp) SvPV_flags_const(sv, lp, 0) #endif #ifndef SvPV_nomg_const_nolen # define SvPV_nomg_const_nolen(sv) SvPV_flags_const_nolen(sv, 0) #endif #ifndef SvPV_renew # define SvPV_renew(sv,n) STMT_START { SvLEN_set(sv, n); \ SvPV_set((sv), (char *) saferealloc( \ (Malloc_t)SvPVX(sv), (MEM_SIZE)((n)))); \ } STMT_END #endif #ifndef SvMAGIC_set # define SvMAGIC_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \ (((XPVMG*) SvANY(sv))->xmg_magic = (val)); } STMT_END #endif #if (PERL_BCDVERSION < 0x5009003) #ifndef SvPVX_const # define SvPVX_const(sv) ((const char*) (0 + SvPVX(sv))) #endif #ifndef SvPVX_mutable # define SvPVX_mutable(sv) (0 + SvPVX(sv)) #endif #ifndef SvRV_set # define SvRV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_RV); \ (((XRV*) SvANY(sv))->xrv_rv = (val)); } STMT_END #endif #else #ifndef SvPVX_const # define SvPVX_const(sv) ((const char*)((sv)->sv_u.svu_pv)) #endif #ifndef SvPVX_mutable # define SvPVX_mutable(sv) ((sv)->sv_u.svu_pv) #endif #ifndef SvRV_set # define SvRV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_RV); \ ((sv)->sv_u.svu_rv = (val)); } STMT_END #endif #endif #ifndef SvSTASH_set # define SvSTASH_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \ (((XPVMG*) SvANY(sv))->xmg_stash = (val)); } STMT_END #endif #if (PERL_BCDVERSION < 0x5004000) #ifndef SvUV_set # define SvUV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ (((XPVIV*) SvANY(sv))->xiv_iv = (IV) (val)); } STMT_END #endif #else #ifndef SvUV_set # define SvUV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ (((XPVUV*) SvANY(sv))->xuv_uv = (val)); } STMT_END #endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(vnewSVpvf) #if defined(NEED_vnewSVpvf) static SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args); static #else extern SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args); #endif #ifdef vnewSVpvf # undef vnewSVpvf #endif #define vnewSVpvf(a,b) DPPP_(my_vnewSVpvf)(aTHX_ a,b) #define Perl_vnewSVpvf DPPP_(my_vnewSVpvf) #if defined(NEED_vnewSVpvf) || defined(NEED_vnewSVpvf_GLOBAL) SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args) { register SV *sv = newSV(0); sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); return sv; } #endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vcatpvf) # define sv_vcatpvf(sv, pat, args) sv_vcatpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)) #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vsetpvf) # define sv_vsetpvf(sv, pat, args) sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)) #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_catpvf_mg) #if defined(NEED_sv_catpvf_mg) static void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...); #endif #define Perl_sv_catpvf_mg DPPP_(my_sv_catpvf_mg) #if defined(NEED_sv_catpvf_mg) || defined(NEED_sv_catpvf_mg_GLOBAL) void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...) { va_list args; va_start(args, pat); sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #ifdef PERL_IMPLICIT_CONTEXT #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_catpvf_mg_nocontext) #if defined(NEED_sv_catpvf_mg_nocontext) static void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...); #endif #define sv_catpvf_mg_nocontext DPPP_(my_sv_catpvf_mg_nocontext) #define Perl_sv_catpvf_mg_nocontext DPPP_(my_sv_catpvf_mg_nocontext) #if defined(NEED_sv_catpvf_mg_nocontext) || defined(NEED_sv_catpvf_mg_nocontext_GLOBAL) void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...) { dTHX; va_list args; va_start(args, pat); sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #endif /* sv_catpvf_mg depends on sv_catpvf_mg_nocontext */ #ifndef sv_catpvf_mg # ifdef PERL_IMPLICIT_CONTEXT # define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext # else # define sv_catpvf_mg Perl_sv_catpvf_mg # endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vcatpvf_mg) # define sv_vcatpvf_mg(sv, pat, args) \ STMT_START { \ sv_vcatpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); \ SvSETMAGIC(sv); \ } STMT_END #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_setpvf_mg) #if defined(NEED_sv_setpvf_mg) static void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...); #endif #define Perl_sv_setpvf_mg DPPP_(my_sv_setpvf_mg) #if defined(NEED_sv_setpvf_mg) || defined(NEED_sv_setpvf_mg_GLOBAL) void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...) { va_list args; va_start(args, pat); sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #ifdef PERL_IMPLICIT_CONTEXT #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_setpvf_mg_nocontext) #if defined(NEED_sv_setpvf_mg_nocontext) static void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...); #endif #define sv_setpvf_mg_nocontext DPPP_(my_sv_setpvf_mg_nocontext) #define Perl_sv_setpvf_mg_nocontext DPPP_(my_sv_setpvf_mg_nocontext) #if defined(NEED_sv_setpvf_mg_nocontext) || defined(NEED_sv_setpvf_mg_nocontext_GLOBAL) void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...) { dTHX; va_list args; va_start(args, pat); sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #endif /* sv_setpvf_mg depends on sv_setpvf_mg_nocontext */ #ifndef sv_setpvf_mg # ifdef PERL_IMPLICIT_CONTEXT # define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext # else # define sv_setpvf_mg Perl_sv_setpvf_mg # endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vsetpvf_mg) # define sv_vsetpvf_mg(sv, pat, args) \ STMT_START { \ sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); \ SvSETMAGIC(sv); \ } STMT_END #endif #ifndef newSVpvn_share #if defined(NEED_newSVpvn_share) static SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash); static #else extern SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash); #endif #ifdef newSVpvn_share # undef newSVpvn_share #endif #define newSVpvn_share(a,b,c) DPPP_(my_newSVpvn_share)(aTHX_ a,b,c) #define Perl_newSVpvn_share DPPP_(my_newSVpvn_share) #if defined(NEED_newSVpvn_share) || defined(NEED_newSVpvn_share_GLOBAL) SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash) { SV *sv; if (len < 0) len = -len; if (!hash) PERL_HASH(hash, (char*) src, len); sv = newSVpvn((char *) src, len); sv_upgrade(sv, SVt_PVIV); SvIVX(sv) = hash; SvREADONLY_on(sv); SvPOK_on(sv); return sv; } #endif #endif #ifndef SvSHARED_HASH # define SvSHARED_HASH(sv) (0 + SvUVX(sv)) #endif #ifndef HvNAME_get # define HvNAME_get(hv) HvNAME(hv) #endif #ifndef HvNAMELEN_get # define HvNAMELEN_get(hv) (HvNAME_get(hv) ? (I32)strlen(HvNAME_get(hv)) : 0) #endif #ifndef GvSVn # define GvSVn(gv) GvSV(gv) #endif #ifndef isGV_with_GP # define isGV_with_GP(gv) isGV(gv) #endif #ifndef WARN_ALL # define WARN_ALL 0 #endif #ifndef WARN_CLOSURE # define WARN_CLOSURE 1 #endif #ifndef WARN_DEPRECATED # define WARN_DEPRECATED 2 #endif #ifndef WARN_EXITING # define WARN_EXITING 3 #endif #ifndef WARN_GLOB # define WARN_GLOB 4 #endif #ifndef WARN_IO # define WARN_IO 5 #endif #ifndef WARN_CLOSED # define WARN_CLOSED 6 #endif #ifndef WARN_EXEC # define WARN_EXEC 7 #endif #ifndef WARN_LAYER # define WARN_LAYER 8 #endif #ifndef WARN_NEWLINE # define WARN_NEWLINE 9 #endif #ifndef WARN_PIPE # define WARN_PIPE 10 #endif #ifndef WARN_UNOPENED # define WARN_UNOPENED 11 #endif #ifndef WARN_MISC # define WARN_MISC 12 #endif #ifndef WARN_NUMERIC # define WARN_NUMERIC 13 #endif #ifndef WARN_ONCE # define WARN_ONCE 14 #endif #ifndef WARN_OVERFLOW # define WARN_OVERFLOW 15 #endif #ifndef WARN_PACK # define WARN_PACK 16 #endif #ifndef WARN_PORTABLE # define WARN_PORTABLE 17 #endif #ifndef WARN_RECURSION # define WARN_RECURSION 18 #endif #ifndef WARN_REDEFINE # define WARN_REDEFINE 19 #endif #ifndef WARN_REGEXP # define WARN_REGEXP 20 #endif #ifndef WARN_SEVERE # define WARN_SEVERE 21 #endif #ifndef WARN_DEBUGGING # define WARN_DEBUGGING 22 #endif #ifndef WARN_INPLACE # define WARN_INPLACE 23 #endif #ifndef WARN_INTERNAL # define WARN_INTERNAL 24 #endif #ifndef WARN_MALLOC # define WARN_MALLOC 25 #endif #ifndef WARN_SIGNAL # define WARN_SIGNAL 26 #endif #ifndef WARN_SUBSTR # define WARN_SUBSTR 27 #endif #ifndef WARN_SYNTAX # define WARN_SYNTAX 28 #endif #ifndef WARN_AMBIGUOUS # define WARN_AMBIGUOUS 29 #endif #ifndef WARN_BAREWORD # define WARN_BAREWORD 30 #endif #ifndef WARN_DIGIT # define WARN_DIGIT 31 #endif #ifndef WARN_PARENTHESIS # define WARN_PARENTHESIS 32 #endif #ifndef WARN_PRECEDENCE # define WARN_PRECEDENCE 33 #endif #ifndef WARN_PRINTF # define WARN_PRINTF 34 #endif #ifndef WARN_PROTOTYPE # define WARN_PROTOTYPE 35 #endif #ifndef WARN_QW # define WARN_QW 36 #endif #ifndef WARN_RESERVED # define WARN_RESERVED 37 #endif #ifndef WARN_SEMICOLON # define WARN_SEMICOLON 38 #endif #ifndef WARN_TAINT # define WARN_TAINT 39 #endif #ifndef WARN_THREADS # define WARN_THREADS 40 #endif #ifndef WARN_UNINITIALIZED # define WARN_UNINITIALIZED 41 #endif #ifndef WARN_UNPACK # define WARN_UNPACK 42 #endif #ifndef WARN_UNTIE # define WARN_UNTIE 43 #endif #ifndef WARN_UTF8 # define WARN_UTF8 44 #endif #ifndef WARN_VOID # define WARN_VOID 45 #endif #ifndef WARN_ASSERTIONS # define WARN_ASSERTIONS 46 #endif #ifndef packWARN # define packWARN(a) (a) #endif #ifndef ckWARN # ifdef G_WARN_ON # define ckWARN(a) (PL_dowarn & G_WARN_ON) # else # define ckWARN(a) PL_dowarn # endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(warner) #if defined(NEED_warner) static void DPPP_(my_warner)(U32 err, const char *pat, ...); static #else extern void DPPP_(my_warner)(U32 err, const char *pat, ...); #endif #define Perl_warner DPPP_(my_warner) #if defined(NEED_warner) || defined(NEED_warner_GLOBAL) void DPPP_(my_warner)(U32 err, const char *pat, ...) { SV *sv; va_list args; PERL_UNUSED_ARG(err); va_start(args, pat); sv = vnewSVpvf(pat, &args); va_end(args); sv_2mortal(sv); warn("%s", SvPV_nolen(sv)); } #define warner Perl_warner #define Perl_warner_nocontext Perl_warner #endif #endif /* concatenating with "" ensures that only literal strings are accepted as argument * note that STR_WITH_LEN() can't be used as argument to macros or functions that * under some configurations might be macros */ #ifndef STR_WITH_LEN # define STR_WITH_LEN(s) (s ""), (sizeof(s)-1) #endif #ifndef newSVpvs # define newSVpvs(str) newSVpvn(str "", sizeof(str) - 1) #endif #ifndef newSVpvs_flags # define newSVpvs_flags(str, flags) newSVpvn_flags(str "", sizeof(str) - 1, flags) #endif #ifndef sv_catpvs # define sv_catpvs(sv, str) sv_catpvn(sv, str "", sizeof(str) - 1) #endif #ifndef sv_setpvs # define sv_setpvs(sv, str) sv_setpvn(sv, str "", sizeof(str) - 1) #endif #ifndef hv_fetchs # define hv_fetchs(hv, key, lval) hv_fetch(hv, key "", sizeof(key) - 1, lval) #endif #ifndef hv_stores # define hv_stores(hv, key, val) hv_store(hv, key "", sizeof(key) - 1, val, 0) #endif #ifndef gv_fetchpvn_flags # define gv_fetchpvn_flags(name, len, flags, svt) gv_fetchpv(name, flags, svt) #endif #ifndef gv_fetchpvs # define gv_fetchpvs(name, flags, svt) gv_fetchpvn_flags(name "", sizeof(name) - 1, flags, svt) #endif #ifndef gv_stashpvs # define gv_stashpvs(name, flags) gv_stashpvn(name "", sizeof(name) - 1, flags) #endif #ifndef SvGETMAGIC # define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END #endif #ifndef PERL_MAGIC_sv # define PERL_MAGIC_sv '\0' #endif #ifndef PERL_MAGIC_overload # define PERL_MAGIC_overload 'A' #endif #ifndef PERL_MAGIC_overload_elem # define PERL_MAGIC_overload_elem 'a' #endif #ifndef PERL_MAGIC_overload_table # define PERL_MAGIC_overload_table 'c' #endif #ifndef PERL_MAGIC_bm # define PERL_MAGIC_bm 'B' #endif #ifndef PERL_MAGIC_regdata # define PERL_MAGIC_regdata 'D' #endif #ifndef PERL_MAGIC_regdatum # define PERL_MAGIC_regdatum 'd' #endif #ifndef PERL_MAGIC_env # define PERL_MAGIC_env 'E' #endif #ifndef PERL_MAGIC_envelem # define PERL_MAGIC_envelem 'e' #endif #ifndef PERL_MAGIC_fm # define PERL_MAGIC_fm 'f' #endif #ifndef PERL_MAGIC_regex_global # define PERL_MAGIC_regex_global 'g' #endif #ifndef PERL_MAGIC_isa # define PERL_MAGIC_isa 'I' #endif #ifndef PERL_MAGIC_isaelem # define PERL_MAGIC_isaelem 'i' #endif #ifndef PERL_MAGIC_nkeys # define PERL_MAGIC_nkeys 'k' #endif #ifndef PERL_MAGIC_dbfile # define PERL_MAGIC_dbfile 'L' #endif #ifndef PERL_MAGIC_dbline # define PERL_MAGIC_dbline 'l' #endif #ifndef PERL_MAGIC_mutex # define PERL_MAGIC_mutex 'm' #endif #ifndef PERL_MAGIC_shared # define PERL_MAGIC_shared 'N' #endif #ifndef PERL_MAGIC_shared_scalar # define PERL_MAGIC_shared_scalar 'n' #endif #ifndef PERL_MAGIC_collxfrm # define PERL_MAGIC_collxfrm 'o' #endif #ifndef PERL_MAGIC_tied # define PERL_MAGIC_tied 'P' #endif #ifndef PERL_MAGIC_tiedelem # define PERL_MAGIC_tiedelem 'p' #endif #ifndef PERL_MAGIC_tiedscalar # define PERL_MAGIC_tiedscalar 'q' #endif #ifndef PERL_MAGIC_qr # define PERL_MAGIC_qr 'r' #endif #ifndef PERL_MAGIC_sig # define PERL_MAGIC_sig 'S' #endif #ifndef PERL_MAGIC_sigelem # define PERL_MAGIC_sigelem 's' #endif #ifndef PERL_MAGIC_taint # define PERL_MAGIC_taint 't' #endif #ifndef PERL_MAGIC_uvar # define PERL_MAGIC_uvar 'U' #endif #ifndef PERL_MAGIC_uvar_elem # define PERL_MAGIC_uvar_elem 'u' #endif #ifndef PERL_MAGIC_vstring # define PERL_MAGIC_vstring 'V' #endif #ifndef PERL_MAGIC_vec # define PERL_MAGIC_vec 'v' #endif #ifndef PERL_MAGIC_utf8 # define PERL_MAGIC_utf8 'w' #endif #ifndef PERL_MAGIC_substr # define PERL_MAGIC_substr 'x' #endif #ifndef PERL_MAGIC_defelem # define PERL_MAGIC_defelem 'y' #endif #ifndef PERL_MAGIC_glob # define PERL_MAGIC_glob '*' #endif #ifndef PERL_MAGIC_arylen # define PERL_MAGIC_arylen '#' #endif #ifndef PERL_MAGIC_pos # define PERL_MAGIC_pos '.' #endif #ifndef PERL_MAGIC_backref # define PERL_MAGIC_backref '<' #endif #ifndef PERL_MAGIC_ext # define PERL_MAGIC_ext '~' #endif /* That's the best we can do... */ #ifndef sv_catpvn_nomg # define sv_catpvn_nomg sv_catpvn #endif #ifndef sv_catsv_nomg # define sv_catsv_nomg sv_catsv #endif #ifndef sv_setsv_nomg # define sv_setsv_nomg sv_setsv #endif #ifndef sv_pvn_nomg # define sv_pvn_nomg sv_pvn #endif #ifndef SvIV_nomg # define SvIV_nomg SvIV #endif #ifndef SvUV_nomg # define SvUV_nomg SvUV #endif #ifndef sv_catpv_mg # define sv_catpv_mg(sv, ptr) \ STMT_START { \ SV *TeMpSv = sv; \ sv_catpv(TeMpSv,ptr); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_catpvn_mg # define sv_catpvn_mg(sv, ptr, len) \ STMT_START { \ SV *TeMpSv = sv; \ sv_catpvn(TeMpSv,ptr,len); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_catsv_mg # define sv_catsv_mg(dsv, ssv) \ STMT_START { \ SV *TeMpSv = dsv; \ sv_catsv(TeMpSv,ssv); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setiv_mg # define sv_setiv_mg(sv, i) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setiv(TeMpSv,i); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setnv_mg # define sv_setnv_mg(sv, num) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setnv(TeMpSv,num); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setpv_mg # define sv_setpv_mg(sv, ptr) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setpv(TeMpSv,ptr); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setpvn_mg # define sv_setpvn_mg(sv, ptr, len) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setpvn(TeMpSv,ptr,len); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setsv_mg # define sv_setsv_mg(dsv, ssv) \ STMT_START { \ SV *TeMpSv = dsv; \ sv_setsv(TeMpSv,ssv); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setuv_mg # define sv_setuv_mg(sv, i) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setuv(TeMpSv,i); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_usepvn_mg # define sv_usepvn_mg(sv, ptr, len) \ STMT_START { \ SV *TeMpSv = sv; \ sv_usepvn(TeMpSv,ptr,len); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef SvVSTRING_mg # define SvVSTRING_mg(sv) (SvMAGICAL(sv) ? mg_find(sv, PERL_MAGIC_vstring) : NULL) #endif /* Hint: sv_magic_portable * This is a compatibility function that is only available with * Devel::PPPort. It is NOT in the perl core. * Its purpose is to mimic the 5.8.0 behaviour of sv_magic() when * it is being passed a name pointer with namlen == 0. In that * case, perl 5.8.0 and later store the pointer, not a copy of it. * The compatibility can be provided back to perl 5.004. With * earlier versions, the code will not compile. */ #if (PERL_BCDVERSION < 0x5004000) /* code that uses sv_magic_portable will not compile */ #elif (PERL_BCDVERSION < 0x5008000) # define sv_magic_portable(sv, obj, how, name, namlen) \ STMT_START { \ SV *SvMp_sv = (sv); \ char *SvMp_name = (char *) (name); \ I32 SvMp_namlen = (namlen); \ if (SvMp_name && SvMp_namlen == 0) \ { \ MAGIC *mg; \ sv_magic(SvMp_sv, obj, how, 0, 0); \ mg = SvMAGIC(SvMp_sv); \ mg->mg_len = -42; /* XXX: this is the tricky part */ \ mg->mg_ptr = SvMp_name; \ } \ else \ { \ sv_magic(SvMp_sv, obj, how, SvMp_name, SvMp_namlen); \ } \ } STMT_END #else # define sv_magic_portable(a, b, c, d, e) sv_magic(a, b, c, d, e) #endif #ifdef USE_ITHREADS #ifndef CopFILE # define CopFILE(c) ((c)->cop_file) #endif #ifndef CopFILEGV # define CopFILEGV(c) (CopFILE(c) ? gv_fetchfile(CopFILE(c)) : Nullgv) #endif #ifndef CopFILE_set # define CopFILE_set(c,pv) ((c)->cop_file = savepv(pv)) #endif #ifndef CopFILESV # define CopFILESV(c) (CopFILE(c) ? GvSV(gv_fetchfile(CopFILE(c))) : Nullsv) #endif #ifndef CopFILEAV # define CopFILEAV(c) (CopFILE(c) ? GvAV(gv_fetchfile(CopFILE(c))) : Nullav) #endif #ifndef CopSTASHPV # define CopSTASHPV(c) ((c)->cop_stashpv) #endif #ifndef CopSTASHPV_set # define CopSTASHPV_set(c,pv) ((c)->cop_stashpv = ((pv) ? savepv(pv) : Nullch)) #endif #ifndef CopSTASH # define CopSTASH(c) (CopSTASHPV(c) ? gv_stashpv(CopSTASHPV(c),GV_ADD) : Nullhv) #endif #ifndef CopSTASH_set # define CopSTASH_set(c,hv) CopSTASHPV_set(c, (hv) ? HvNAME(hv) : Nullch) #endif #ifndef CopSTASH_eq # define CopSTASH_eq(c,hv) ((hv) && (CopSTASHPV(c) == HvNAME(hv) \ || (CopSTASHPV(c) && HvNAME(hv) \ && strEQ(CopSTASHPV(c), HvNAME(hv))))) #endif #else #ifndef CopFILEGV # define CopFILEGV(c) ((c)->cop_filegv) #endif #ifndef CopFILEGV_set # define CopFILEGV_set(c,gv) ((c)->cop_filegv = (GV*)SvREFCNT_inc(gv)) #endif #ifndef CopFILE_set # define CopFILE_set(c,pv) CopFILEGV_set((c), gv_fetchfile(pv)) #endif #ifndef CopFILESV # define CopFILESV(c) (CopFILEGV(c) ? GvSV(CopFILEGV(c)) : Nullsv) #endif #ifndef CopFILEAV # define CopFILEAV(c) (CopFILEGV(c) ? GvAV(CopFILEGV(c)) : Nullav) #endif #ifndef CopFILE # define CopFILE(c) (CopFILESV(c) ? SvPVX(CopFILESV(c)) : Nullch) #endif #ifndef CopSTASH # define CopSTASH(c) ((c)->cop_stash) #endif #ifndef CopSTASH_set # define CopSTASH_set(c,hv) ((c)->cop_stash = (hv)) #endif #ifndef CopSTASHPV # define CopSTASHPV(c) (CopSTASH(c) ? HvNAME(CopSTASH(c)) : Nullch) #endif #ifndef CopSTASHPV_set # define CopSTASHPV_set(c,pv) CopSTASH_set((c), gv_stashpv(pv,GV_ADD)) #endif #ifndef CopSTASH_eq # define CopSTASH_eq(c,hv) (CopSTASH(c) == (hv)) #endif #endif /* USE_ITHREADS */ #ifndef IN_PERL_COMPILETIME # define IN_PERL_COMPILETIME (PL_curcop == &PL_compiling) #endif #ifndef IN_LOCALE_RUNTIME # define IN_LOCALE_RUNTIME (PL_curcop->op_private & HINT_LOCALE) #endif #ifndef IN_LOCALE_COMPILETIME # define IN_LOCALE_COMPILETIME (PL_hints & HINT_LOCALE) #endif #ifndef IN_LOCALE # define IN_LOCALE (IN_PERL_COMPILETIME ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME) #endif #ifndef IS_NUMBER_IN_UV # define IS_NUMBER_IN_UV 0x01 #endif #ifndef IS_NUMBER_GREATER_THAN_UV_MAX # define IS_NUMBER_GREATER_THAN_UV_MAX 0x02 #endif #ifndef IS_NUMBER_NOT_INT # define IS_NUMBER_NOT_INT 0x04 #endif #ifndef IS_NUMBER_NEG # define IS_NUMBER_NEG 0x08 #endif #ifndef IS_NUMBER_INFINITY # define IS_NUMBER_INFINITY 0x10 #endif #ifndef IS_NUMBER_NAN # define IS_NUMBER_NAN 0x20 #endif #ifndef GROK_NUMERIC_RADIX # define GROK_NUMERIC_RADIX(sp, send) grok_numeric_radix(sp, send) #endif #ifndef PERL_SCAN_GREATER_THAN_UV_MAX # define PERL_SCAN_GREATER_THAN_UV_MAX 0x02 #endif #ifndef PERL_SCAN_SILENT_ILLDIGIT # define PERL_SCAN_SILENT_ILLDIGIT 0x04 #endif #ifndef PERL_SCAN_ALLOW_UNDERSCORES # define PERL_SCAN_ALLOW_UNDERSCORES 0x01 #endif #ifndef PERL_SCAN_DISALLOW_PREFIX # define PERL_SCAN_DISALLOW_PREFIX 0x02 #endif #ifndef grok_numeric_radix #if defined(NEED_grok_numeric_radix) static bool DPPP_(my_grok_numeric_radix)(pTHX_ const char ** sp, const char * send); static #else extern bool DPPP_(my_grok_numeric_radix)(pTHX_ const char ** sp, const char * send); #endif #ifdef grok_numeric_radix # undef grok_numeric_radix #endif #define grok_numeric_radix(a,b) DPPP_(my_grok_numeric_radix)(aTHX_ a,b) #define Perl_grok_numeric_radix DPPP_(my_grok_numeric_radix) #if defined(NEED_grok_numeric_radix) || defined(NEED_grok_numeric_radix_GLOBAL) bool DPPP_(my_grok_numeric_radix)(pTHX_ const char **sp, const char *send) { #ifdef USE_LOCALE_NUMERIC #ifdef PL_numeric_radix_sv if (PL_numeric_radix_sv && IN_LOCALE) { STRLEN len; char* radix = SvPV(PL_numeric_radix_sv, len); if (*sp + len <= send && memEQ(*sp, radix, len)) { *sp += len; return TRUE; } } #else /* older perls don't have PL_numeric_radix_sv so the radix * must manually be requested from locale.h */ #include dTHR; /* needed for older threaded perls */ struct lconv *lc = localeconv(); char *radix = lc->decimal_point; if (radix && IN_LOCALE) { STRLEN len = strlen(radix); if (*sp + len <= send && memEQ(*sp, radix, len)) { *sp += len; return TRUE; } } #endif #endif /* USE_LOCALE_NUMERIC */ /* always try "." if numeric radix didn't match because * we may have data from different locales mixed */ if (*sp < send && **sp == '.') { ++*sp; return TRUE; } return FALSE; } #endif #endif #ifndef grok_number #if defined(NEED_grok_number) static int DPPP_(my_grok_number)(pTHX_ const char * pv, STRLEN len, UV * valuep); static #else extern int DPPP_(my_grok_number)(pTHX_ const char * pv, STRLEN len, UV * valuep); #endif #ifdef grok_number # undef grok_number #endif #define grok_number(a,b,c) DPPP_(my_grok_number)(aTHX_ a,b,c) #define Perl_grok_number DPPP_(my_grok_number) #if defined(NEED_grok_number) || defined(NEED_grok_number_GLOBAL) int DPPP_(my_grok_number)(pTHX_ const char *pv, STRLEN len, UV *valuep) { const char *s = pv; const char *send = pv + len; const UV max_div_10 = UV_MAX / 10; const char max_mod_10 = UV_MAX % 10; int numtype = 0; int sawinf = 0; int sawnan = 0; while (s < send && isSPACE(*s)) s++; if (s == send) { return 0; } else if (*s == '-') { s++; numtype = IS_NUMBER_NEG; } else if (*s == '+') s++; if (s == send) return 0; /* next must be digit or the radix separator or beginning of infinity */ if (isDIGIT(*s)) { /* UVs are at least 32 bits, so the first 9 decimal digits cannot overflow. */ UV value = *s - '0'; /* This construction seems to be more optimiser friendly. (without it gcc does the isDIGIT test and the *s - '0' separately) With it gcc on arm is managing 6 instructions (6 cycles) per digit. In theory the optimiser could deduce how far to unroll the loop before checking for overflow. */ if (++s < send) { int digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { /* Now got 9 digits, so need to check each time for overflow. */ digit = *s - '0'; while (digit >= 0 && digit <= 9 && (value < max_div_10 || (value == max_div_10 && digit <= max_mod_10))) { value = value * 10 + digit; if (++s < send) digit = *s - '0'; else break; } if (digit >= 0 && digit <= 9 && (s < send)) { /* value overflowed. skip the remaining digits, don't worry about setting *valuep. */ do { s++; } while (s < send && isDIGIT(*s)); numtype |= IS_NUMBER_GREATER_THAN_UV_MAX; goto skip_value; } } } } } } } } } } } } } } } } } } numtype |= IS_NUMBER_IN_UV; if (valuep) *valuep = value; skip_value: if (GROK_NUMERIC_RADIX(&s, send)) { numtype |= IS_NUMBER_NOT_INT; while (s < send && isDIGIT(*s)) /* optional digits after the radix */ s++; } } else if (GROK_NUMERIC_RADIX(&s, send)) { numtype |= IS_NUMBER_NOT_INT | IS_NUMBER_IN_UV; /* valuep assigned below */ /* no digits before the radix means we need digits after it */ if (s < send && isDIGIT(*s)) { do { s++; } while (s < send && isDIGIT(*s)); if (valuep) { /* integer approximation is valid - it's 0. */ *valuep = 0; } } else return 0; } else if (*s == 'I' || *s == 'i') { s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; s++; if (s == send || (*s != 'F' && *s != 'f')) return 0; s++; if (s < send && (*s == 'I' || *s == 'i')) { s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; s++; if (s == send || (*s != 'I' && *s != 'i')) return 0; s++; if (s == send || (*s != 'T' && *s != 't')) return 0; s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0; s++; } sawinf = 1; } else if (*s == 'N' || *s == 'n') { /* XXX TODO: There are signaling NaNs and quiet NaNs. */ s++; if (s == send || (*s != 'A' && *s != 'a')) return 0; s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; s++; sawnan = 1; } else return 0; if (sawinf) { numtype &= IS_NUMBER_NEG; /* Keep track of sign */ numtype |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT; } else if (sawnan) { numtype &= IS_NUMBER_NEG; /* Keep track of sign */ numtype |= IS_NUMBER_NAN | IS_NUMBER_NOT_INT; } else if (s < send) { /* we can have an optional exponent part */ if (*s == 'e' || *s == 'E') { /* The only flag we keep is sign. Blow away any "it's UV" */ numtype &= IS_NUMBER_NEG; numtype |= IS_NUMBER_NOT_INT; s++; if (s < send && (*s == '-' || *s == '+')) s++; if (s < send && isDIGIT(*s)) { do { s++; } while (s < send && isDIGIT(*s)); } else return 0; } } while (s < send && isSPACE(*s)) s++; if (s >= send) return numtype; if (len == 10 && memEQ(pv, "0 but true", 10)) { if (valuep) *valuep = 0; return IS_NUMBER_IN_UV; } return 0; } #endif #endif /* * The grok_* routines have been modified to use warn() instead of * Perl_warner(). Also, 'hexdigit' was the former name of PL_hexdigit, * which is why the stack variable has been renamed to 'xdigit'. */ #ifndef grok_bin #if defined(NEED_grok_bin) static UV DPPP_(my_grok_bin)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); static #else extern UV DPPP_(my_grok_bin)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); #endif #ifdef grok_bin # undef grok_bin #endif #define grok_bin(a,b,c,d) DPPP_(my_grok_bin)(aTHX_ a,b,c,d) #define Perl_grok_bin DPPP_(my_grok_bin) #if defined(NEED_grok_bin) || defined(NEED_grok_bin_GLOBAL) UV DPPP_(my_grok_bin)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) { const char *s = start; STRLEN len = *len_p; UV value = 0; NV value_nv = 0; const UV max_div_2 = UV_MAX / 2; bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; bool overflowed = FALSE; if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) { /* strip off leading b or 0b. for compatibility silently suffer "b" and "0b" as valid binary numbers. */ if (len >= 1) { if (s[0] == 'b') { s++; len--; } else if (len >= 2 && s[0] == '0' && s[1] == 'b') { s+=2; len-=2; } } } for (; len-- && *s; s++) { char bit = *s; if (bit == '0' || bit == '1') { /* Write it in this wonky order with a goto to attempt to get the compiler to make the common case integer-only loop pretty tight. With gcc seems to be much straighter code than old scan_bin. */ redo: if (!overflowed) { if (value <= max_div_2) { value = (value << 1) | (bit - '0'); continue; } /* Bah. We're just overflowed. */ warn("Integer overflow in binary number"); overflowed = TRUE; value_nv = (NV) value; } value_nv *= 2.0; /* If an NV has not enough bits in its mantissa to * represent a UV this summing of small low-order numbers * is a waste of time (because the NV cannot preserve * the low-order bits anyway): we could just remember when * did we overflow and in the end just multiply value_nv by the * right amount. */ value_nv += (NV)(bit - '0'); continue; } if (bit == '_' && len && allow_underscores && (bit = s[1]) && (bit == '0' || bit == '1')) { --len; ++s; goto redo; } if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) warn("Illegal binary digit '%c' ignored", *s); break; } if ( ( overflowed && value_nv > 4294967295.0) #if UVSIZE > 4 || (!overflowed && value > 0xffffffff ) #endif ) { warn("Binary number > 0b11111111111111111111111111111111 non-portable"); } *len_p = s - start; if (!overflowed) { *flags = 0; return value; } *flags = PERL_SCAN_GREATER_THAN_UV_MAX; if (result) *result = value_nv; return UV_MAX; } #endif #endif #ifndef grok_hex #if defined(NEED_grok_hex) static UV DPPP_(my_grok_hex)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); static #else extern UV DPPP_(my_grok_hex)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); #endif #ifdef grok_hex # undef grok_hex #endif #define grok_hex(a,b,c,d) DPPP_(my_grok_hex)(aTHX_ a,b,c,d) #define Perl_grok_hex DPPP_(my_grok_hex) #if defined(NEED_grok_hex) || defined(NEED_grok_hex_GLOBAL) UV DPPP_(my_grok_hex)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) { const char *s = start; STRLEN len = *len_p; UV value = 0; NV value_nv = 0; const UV max_div_16 = UV_MAX / 16; bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; bool overflowed = FALSE; const char *xdigit; if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) { /* strip off leading x or 0x. for compatibility silently suffer "x" and "0x" as valid hex numbers. */ if (len >= 1) { if (s[0] == 'x') { s++; len--; } else if (len >= 2 && s[0] == '0' && s[1] == 'x') { s+=2; len-=2; } } } for (; len-- && *s; s++) { xdigit = strchr((char *) PL_hexdigit, *s); if (xdigit) { /* Write it in this wonky order with a goto to attempt to get the compiler to make the common case integer-only loop pretty tight. With gcc seems to be much straighter code than old scan_hex. */ redo: if (!overflowed) { if (value <= max_div_16) { value = (value << 4) | ((xdigit - PL_hexdigit) & 15); continue; } warn("Integer overflow in hexadecimal number"); overflowed = TRUE; value_nv = (NV) value; } value_nv *= 16.0; /* If an NV has not enough bits in its mantissa to * represent a UV this summing of small low-order numbers * is a waste of time (because the NV cannot preserve * the low-order bits anyway): we could just remember when * did we overflow and in the end just multiply value_nv by the * right amount of 16-tuples. */ value_nv += (NV)((xdigit - PL_hexdigit) & 15); continue; } if (*s == '_' && len && allow_underscores && s[1] && (xdigit = strchr((char *) PL_hexdigit, s[1]))) { --len; ++s; goto redo; } if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) warn("Illegal hexadecimal digit '%c' ignored", *s); break; } if ( ( overflowed && value_nv > 4294967295.0) #if UVSIZE > 4 || (!overflowed && value > 0xffffffff ) #endif ) { warn("Hexadecimal number > 0xffffffff non-portable"); } *len_p = s - start; if (!overflowed) { *flags = 0; return value; } *flags = PERL_SCAN_GREATER_THAN_UV_MAX; if (result) *result = value_nv; return UV_MAX; } #endif #endif #ifndef grok_oct #if defined(NEED_grok_oct) static UV DPPP_(my_grok_oct)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); static #else extern UV DPPP_(my_grok_oct)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); #endif #ifdef grok_oct # undef grok_oct #endif #define grok_oct(a,b,c,d) DPPP_(my_grok_oct)(aTHX_ a,b,c,d) #define Perl_grok_oct DPPP_(my_grok_oct) #if defined(NEED_grok_oct) || defined(NEED_grok_oct_GLOBAL) UV DPPP_(my_grok_oct)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) { const char *s = start; STRLEN len = *len_p; UV value = 0; NV value_nv = 0; const UV max_div_8 = UV_MAX / 8; bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; bool overflowed = FALSE; for (; len-- && *s; s++) { /* gcc 2.95 optimiser not smart enough to figure that this subtraction out front allows slicker code. */ int digit = *s - '0'; if (digit >= 0 && digit <= 7) { /* Write it in this wonky order with a goto to attempt to get the compiler to make the common case integer-only loop pretty tight. */ redo: if (!overflowed) { if (value <= max_div_8) { value = (value << 3) | digit; continue; } /* Bah. We're just overflowed. */ warn("Integer overflow in octal number"); overflowed = TRUE; value_nv = (NV) value; } value_nv *= 8.0; /* If an NV has not enough bits in its mantissa to * represent a UV this summing of small low-order numbers * is a waste of time (because the NV cannot preserve * the low-order bits anyway): we could just remember when * did we overflow and in the end just multiply value_nv by the * right amount of 8-tuples. */ value_nv += (NV)digit; continue; } if (digit == ('_' - '0') && len && allow_underscores && (digit = s[1] - '0') && (digit >= 0 && digit <= 7)) { --len; ++s; goto redo; } /* Allow \octal to work the DWIM way (that is, stop scanning * as soon as non-octal characters are seen, complain only iff * someone seems to want to use the digits eight and nine). */ if (digit == 8 || digit == 9) { if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) warn("Illegal octal digit '%c' ignored", *s); } break; } if ( ( overflowed && value_nv > 4294967295.0) #if UVSIZE > 4 || (!overflowed && value > 0xffffffff ) #endif ) { warn("Octal number > 037777777777 non-portable"); } *len_p = s - start; if (!overflowed) { *flags = 0; return value; } *flags = PERL_SCAN_GREATER_THAN_UV_MAX; if (result) *result = value_nv; return UV_MAX; } #endif #endif #if !defined(my_snprintf) #if defined(NEED_my_snprintf) static int DPPP_(my_my_snprintf)(char * buffer, const Size_t len, const char * format, ...); static #else extern int DPPP_(my_my_snprintf)(char * buffer, const Size_t len, const char * format, ...); #endif #define my_snprintf DPPP_(my_my_snprintf) #define Perl_my_snprintf DPPP_(my_my_snprintf) #if defined(NEED_my_snprintf) || defined(NEED_my_snprintf_GLOBAL) int DPPP_(my_my_snprintf)(char *buffer, const Size_t len, const char *format, ...) { dTHX; int retval; va_list ap; va_start(ap, format); #ifdef HAS_VSNPRINTF retval = vsnprintf(buffer, len, format, ap); #else retval = vsprintf(buffer, format, ap); #endif va_end(ap); if (retval < 0 || (len > 0 && (Size_t)retval >= len)) Perl_croak(aTHX_ "panic: my_snprintf buffer overflow"); return retval; } #endif #endif #if !defined(my_sprintf) #if defined(NEED_my_sprintf) static int DPPP_(my_my_sprintf)(char * buffer, const char * pat, ...); static #else extern int DPPP_(my_my_sprintf)(char * buffer, const char * pat, ...); #endif #define my_sprintf DPPP_(my_my_sprintf) #define Perl_my_sprintf DPPP_(my_my_sprintf) #if defined(NEED_my_sprintf) || defined(NEED_my_sprintf_GLOBAL) int DPPP_(my_my_sprintf)(char *buffer, const char* pat, ...) { va_list args; va_start(args, pat); vsprintf(buffer, pat, args); va_end(args); return strlen(buffer); } #endif #endif #ifdef NO_XSLOCKS # ifdef dJMPENV # define dXCPT dJMPENV; int rEtV = 0 # define XCPT_TRY_START JMPENV_PUSH(rEtV); if (rEtV == 0) # define XCPT_TRY_END JMPENV_POP; # define XCPT_CATCH if (rEtV != 0) # define XCPT_RETHROW JMPENV_JUMP(rEtV) # else # define dXCPT Sigjmp_buf oldTOP; int rEtV = 0 # define XCPT_TRY_START Copy(top_env, oldTOP, 1, Sigjmp_buf); rEtV = Sigsetjmp(top_env, 1); if (rEtV == 0) # define XCPT_TRY_END Copy(oldTOP, top_env, 1, Sigjmp_buf); # define XCPT_CATCH if (rEtV != 0) # define XCPT_RETHROW Siglongjmp(top_env, rEtV) # endif #endif #if !defined(my_strlcat) #if defined(NEED_my_strlcat) static Size_t DPPP_(my_my_strlcat)(char * dst, const char * src, Size_t size); static #else extern Size_t DPPP_(my_my_strlcat)(char * dst, const char * src, Size_t size); #endif #define my_strlcat DPPP_(my_my_strlcat) #define Perl_my_strlcat DPPP_(my_my_strlcat) #if defined(NEED_my_strlcat) || defined(NEED_my_strlcat_GLOBAL) Size_t DPPP_(my_my_strlcat)(char *dst, const char *src, Size_t size) { Size_t used, length, copy; used = strlen(dst); length = strlen(src); if (size > 0 && used < size - 1) { copy = (length >= size - used) ? size - used - 1 : length; memcpy(dst + used, src, copy); dst[used + copy] = '\0'; } return used + length; } #endif #endif #if !defined(my_strlcpy) #if defined(NEED_my_strlcpy) static Size_t DPPP_(my_my_strlcpy)(char * dst, const char * src, Size_t size); static #else extern Size_t DPPP_(my_my_strlcpy)(char * dst, const char * src, Size_t size); #endif #define my_strlcpy DPPP_(my_my_strlcpy) #define Perl_my_strlcpy DPPP_(my_my_strlcpy) #if defined(NEED_my_strlcpy) || defined(NEED_my_strlcpy_GLOBAL) Size_t DPPP_(my_my_strlcpy)(char *dst, const char *src, Size_t size) { Size_t length, copy; length = strlen(src); if (size > 0) { copy = (length >= size) ? size - 1 : length; memcpy(dst, src, copy); dst[copy] = '\0'; } return length; } #endif #endif #ifndef PERL_PV_ESCAPE_QUOTE # define PERL_PV_ESCAPE_QUOTE 0x0001 #endif #ifndef PERL_PV_PRETTY_QUOTE # define PERL_PV_PRETTY_QUOTE PERL_PV_ESCAPE_QUOTE #endif #ifndef PERL_PV_PRETTY_ELLIPSES # define PERL_PV_PRETTY_ELLIPSES 0x0002 #endif #ifndef PERL_PV_PRETTY_LTGT # define PERL_PV_PRETTY_LTGT 0x0004 #endif #ifndef PERL_PV_ESCAPE_FIRSTCHAR # define PERL_PV_ESCAPE_FIRSTCHAR 0x0008 #endif #ifndef PERL_PV_ESCAPE_UNI # define PERL_PV_ESCAPE_UNI 0x0100 #endif #ifndef PERL_PV_ESCAPE_UNI_DETECT # define PERL_PV_ESCAPE_UNI_DETECT 0x0200 #endif #ifndef PERL_PV_ESCAPE_ALL # define PERL_PV_ESCAPE_ALL 0x1000 #endif #ifndef PERL_PV_ESCAPE_NOBACKSLASH # define PERL_PV_ESCAPE_NOBACKSLASH 0x2000 #endif #ifndef PERL_PV_ESCAPE_NOCLEAR # define PERL_PV_ESCAPE_NOCLEAR 0x4000 #endif #ifndef PERL_PV_ESCAPE_RE # define PERL_PV_ESCAPE_RE 0x8000 #endif #ifndef PERL_PV_PRETTY_NOCLEAR # define PERL_PV_PRETTY_NOCLEAR PERL_PV_ESCAPE_NOCLEAR #endif #ifndef PERL_PV_PRETTY_DUMP # define PERL_PV_PRETTY_DUMP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_QUOTE #endif #ifndef PERL_PV_PRETTY_REGPROP # define PERL_PV_PRETTY_REGPROP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_LTGT|PERL_PV_ESCAPE_RE #endif /* Hint: pv_escape * Note that unicode functionality is only backported to * those perl versions that support it. For older perl * versions, the implementation will fall back to bytes. */ #ifndef pv_escape #if defined(NEED_pv_escape) static char * DPPP_(my_pv_escape)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags); static #else extern char * DPPP_(my_pv_escape)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags); #endif #ifdef pv_escape # undef pv_escape #endif #define pv_escape(a,b,c,d,e,f) DPPP_(my_pv_escape)(aTHX_ a,b,c,d,e,f) #define Perl_pv_escape DPPP_(my_pv_escape) #if defined(NEED_pv_escape) || defined(NEED_pv_escape_GLOBAL) char * DPPP_(my_pv_escape)(pTHX_ SV *dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags) { const char esc = flags & PERL_PV_ESCAPE_RE ? '%' : '\\'; const char dq = flags & PERL_PV_ESCAPE_QUOTE ? '"' : esc; char octbuf[32] = "%123456789ABCDF"; STRLEN wrote = 0; STRLEN chsize = 0; STRLEN readsize = 1; #if defined(is_utf8_string) && defined(utf8_to_uvchr) bool isuni = flags & PERL_PV_ESCAPE_UNI ? 1 : 0; #endif const char *pv = str; const char * const end = pv + count; octbuf[0] = esc; if (!(flags & PERL_PV_ESCAPE_NOCLEAR)) sv_setpvs(dsv, ""); #if defined(is_utf8_string) && defined(utf8_to_uvchr) if ((flags & PERL_PV_ESCAPE_UNI_DETECT) && is_utf8_string((U8*)pv, count)) isuni = 1; #endif for (; pv < end && (!max || wrote < max) ; pv += readsize) { const UV u = #if defined(is_utf8_string) && defined(utf8_to_uvchr) isuni ? utf8_to_uvchr((U8*)pv, &readsize) : #endif (U8)*pv; const U8 c = (U8)u & 0xFF; if (u > 255 || (flags & PERL_PV_ESCAPE_ALL)) { if (flags & PERL_PV_ESCAPE_FIRSTCHAR) chsize = my_snprintf(octbuf, sizeof octbuf, "%"UVxf, u); else chsize = my_snprintf(octbuf, sizeof octbuf, "%cx{%"UVxf"}", esc, u); } else if (flags & PERL_PV_ESCAPE_NOBACKSLASH) { chsize = 1; } else { if (c == dq || c == esc || !isPRINT(c)) { chsize = 2; switch (c) { case '\\' : /* fallthrough */ case '%' : if (c == esc) octbuf[1] = esc; else chsize = 1; break; case '\v' : octbuf[1] = 'v'; break; case '\t' : octbuf[1] = 't'; break; case '\r' : octbuf[1] = 'r'; break; case '\n' : octbuf[1] = 'n'; break; case '\f' : octbuf[1] = 'f'; break; case '"' : if (dq == '"') octbuf[1] = '"'; else chsize = 1; break; default: chsize = my_snprintf(octbuf, sizeof octbuf, pv < end && isDIGIT((U8)*(pv+readsize)) ? "%c%03o" : "%c%o", esc, c); } } else { chsize = 1; } } if (max && wrote + chsize > max) { break; } else if (chsize > 1) { sv_catpvn(dsv, octbuf, chsize); wrote += chsize; } else { char tmp[2]; my_snprintf(tmp, sizeof tmp, "%c", c); sv_catpvn(dsv, tmp, 1); wrote++; } if (flags & PERL_PV_ESCAPE_FIRSTCHAR) break; } if (escaped != NULL) *escaped= pv - str; return SvPVX(dsv); } #endif #endif #ifndef pv_pretty #if defined(NEED_pv_pretty) static char * DPPP_(my_pv_pretty)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags); static #else extern char * DPPP_(my_pv_pretty)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags); #endif #ifdef pv_pretty # undef pv_pretty #endif #define pv_pretty(a,b,c,d,e,f,g) DPPP_(my_pv_pretty)(aTHX_ a,b,c,d,e,f,g) #define Perl_pv_pretty DPPP_(my_pv_pretty) #if defined(NEED_pv_pretty) || defined(NEED_pv_pretty_GLOBAL) char * DPPP_(my_pv_pretty)(pTHX_ SV *dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags) { const U8 dq = (flags & PERL_PV_PRETTY_QUOTE) ? '"' : '%'; STRLEN escaped; if (!(flags & PERL_PV_PRETTY_NOCLEAR)) sv_setpvs(dsv, ""); if (dq == '"') sv_catpvs(dsv, "\""); else if (flags & PERL_PV_PRETTY_LTGT) sv_catpvs(dsv, "<"); if (start_color != NULL) sv_catpv(dsv, D_PPP_CONSTPV_ARG(start_color)); pv_escape(dsv, str, count, max, &escaped, flags | PERL_PV_ESCAPE_NOCLEAR); if (end_color != NULL) sv_catpv(dsv, D_PPP_CONSTPV_ARG(end_color)); if (dq == '"') sv_catpvs(dsv, "\""); else if (flags & PERL_PV_PRETTY_LTGT) sv_catpvs(dsv, ">"); if ((flags & PERL_PV_PRETTY_ELLIPSES) && escaped < count) sv_catpvs(dsv, "..."); return SvPVX(dsv); } #endif #endif #ifndef pv_display #if defined(NEED_pv_display) static char * DPPP_(my_pv_display)(pTHX_ SV * dsv, const char * pv, STRLEN cur, STRLEN len, STRLEN pvlim); static #else extern char * DPPP_(my_pv_display)(pTHX_ SV * dsv, const char * pv, STRLEN cur, STRLEN len, STRLEN pvlim); #endif #ifdef pv_display # undef pv_display #endif #define pv_display(a,b,c,d,e) DPPP_(my_pv_display)(aTHX_ a,b,c,d,e) #define Perl_pv_display DPPP_(my_pv_display) #if defined(NEED_pv_display) || defined(NEED_pv_display_GLOBAL) char * DPPP_(my_pv_display)(pTHX_ SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pvlim) { pv_pretty(dsv, pv, cur, pvlim, NULL, NULL, PERL_PV_PRETTY_DUMP); if (len > cur && pv[cur] == '\0') sv_catpvs(dsv, "\\0"); return SvPVX(dsv); } #endif #endif #endif /* _P_P_PORTABILITY_H_ */ /* End of File ppport.h */ Math-Clipper-1.29/t000755001750001750 013467455703 13250 5ustar00mikemike000000000000Math-Clipper-1.29/t/001compile.t000444001750001750 14313467455703 15421 0ustar00mikemike000000000000use strict; use warnings; use File::Spec; use Test::More tests => 1; use Math::Clipper; pass(); Math-Clipper-1.29/t/002basic.t000444001750001750 236113467455703 15077 0ustar00mikemike000000000000use strict; use warnings; use Test::More tests => 1+6+3*2; use constant EPS => 1.e-9; sub approx_eq { return ($_[0]+EPS() < $_[1] && $_[0]-EPS() > $_[1]); } use Math::Clipper qw/:all/; pass(); foreach my $const ( qw/CT_INTERSECTION CT_UNION CT_DIFFERENCE CT_XOR/, #qw/PT_SUBJECT PT_CLIP/, qw/PFT_EVENODD PFT_NONZERO/, ) { ok(defined eval $const); } SCOPE: { my $c = Math::Clipper->new; isa_ok($c, 'Math::Clipper'); $c->add_subject_polygon( [ [0, 0], [10, 0], [10, 10], [0, 10], ], ); $c->add_clip_polygon( my $clip = [ [0, 0], [5, 0], [5, 10], [0, 10], ], ); my $ppoly = $c->execute(CT_INTERSECTION); ok(ref($ppoly) eq 'ARRAY'); is area($ppoly->[0]), area($clip); } SCOPE: { my $c = Math::Clipper->new; isa_ok($c, 'Math::Clipper'); $c->add_subject_polygon( [ [0, 0], [10, 0], [10, 10], [0, 10], ], ); $c->add_clip_polygon( [ [50, 0.], [55, 0.], [55, 10], [50, 10], [60, 20], [80, 30], [100, 40], [120, 50], [140, 60], [160, 70], ], ); my $ppoly = $c->execute(CT_INTERSECTION); ok(ref($ppoly) eq 'ARRAY'); is_deeply($ppoly, [] ); } Math-Clipper-1.29/t/003boolops.t000444001750001750 352413467455703 15476 0ustar00mikemike000000000000use Math::Clipper ':all'; use Test::More tests=>7; #my $ai = [ #[-900359890780731,536870912000000], #[0,-1073741824000000], #[900359890780731,536870912000000] #]; #my $bi = [ #[-900359890780731,-536870912000000], #[900359890780731,-536870912000000], #[0,1073741824000000] #]; my $ai = [ [-15 , 20], [ 0 , -40], [ 15 , 20] ]; my $bi = [ [-15 , -20], [ 15 , -20], [ 0 , 40] ]; my $triarea=100; my $clipper = Math::Clipper->new; $clipper->use_full_coordinate_range(1); $clipper->add_subject_polygon($ai); $clipper->add_clip_polygon($bi); my $result = $clipper->execute(CT_DIFFERENCE); ok( scalar(@{$result})==3, 'DIFFERENCE should give three polygons' ); ok( 3*$triarea == area_sum($result) , 'DIFFERENCE areas are reasonable' ); $clipper->clear(); $clipper->add_subject_polygon($ai); $clipper->add_clip_polygon($bi); $result = $clipper->execute(CT_UNION); ok( scalar(@{$result})==1, 'UNION should give one polygon' ); ok( 12*$triarea == area_sum($result) , 'UNION area is reasonable' ); $clipper->clear(); $clipper->add_subject_polygon($ai); $clipper->add_clip_polygon($bi); $result = $clipper->execute(CT_XOR); # xor of test gives two polygons, each with two shared points between triangles, but that might # not be reliable or desired. It's a Clipper issue though, and might change with new versions # so don't want to count result polygons for xor ok( 6*$triarea == area_sum($result) , 'XOR area is reasonable' ); $clipper->clear(); $clipper->add_subject_polygon($ai); $clipper->add_clip_polygon($bi); $result = $clipper->execute(CT_INTERSECTION); ok( scalar(@{$result})==1, 'INTERSECTION should give one polygon' ); ok( 6*$triarea == area_sum($result) , 'INTERSECTION area is reasonable' ); sub area_sum { my $polys=shift; my $ret = 0; map {$ret+=Math::Clipper::area($_)} @{$polys}; return $ret; }Math-Clipper-1.29/t/004filltype.t000444001750001750 261613467455703 15653 0ustar00mikemike000000000000use Math::Clipper ':all'; use Test::More tests=>4; my $ai = [ #area = 16 [0,0], [4,0], [4,4], [0,4] ]; my $bi = [#area = 4, is inside $ai [1,1], [3,1], [3,3], [1,3] ]; my $bir = [#area = 4 (negative if PFT_NONZERO), is inside $ai [1,3], [3,3], [3,1], [1,1] ]; my $clipper = Math::Clipper->new; $clipper->use_full_coordinate_range(1); $clipper->add_subject_polygon($ai); $clipper->add_subject_polygon($bi); my $result = $clipper->execute(CT_DIFFERENCE,PFT_EVENODD,PFT_EVENODD); # PFT_EVENODD is default, just being explicit here ok(scalar(@{$result}) == 2,'EVENODD begets hole'); $clipper->clear(); $clipper->add_subject_polygon($ai); $clipper->add_subject_polygon($bir); $result = $clipper->execute(CT_DIFFERENCE,PFT_EVENODD,PFT_EVENODD); # PFT_EVENODD is default, just being explicit here ok(scalar(@{$result}) == 2,'EVENODD still begets hole despite reversed inner polygon winding'); $clipper->clear(); $clipper->add_subject_polygon($ai); $clipper->add_subject_polygon($bir); $result = $clipper->execute(CT_DIFFERENCE,PFT_NONZERO,PFT_NONZERO); ok(scalar(@{$result}) == 2,'NONZERO begets hole with inner polygon wound opposite to outer'); $clipper->clear(); $clipper->add_subject_polygon($ai); $clipper->add_subject_polygon($bi); $result = $clipper->execute(CT_DIFFERENCE,PFT_NONZERO,PFT_NONZERO); ok(scalar(@{$result}) == 1,'NONZERO begets one polygon, when inner poly wound same as outside'); $clipper->clear(); Math-Clipper-1.29/t/005offset.t000444001750001750 523413467455703 15311 0ustar00mikemike000000000000use Math::Clipper ':all'; use Test::More tests => 19; my $ccw = [ [0,0], [4,0], [4,4], [0,4] ]; my $cw = [ [0,0], [0,4], [4,4], [4,0] ]; my $offpolys1 = Math::Clipper::offset([$ccw], 1.0, 1); #diag("\ncnt:\n",scalar(@{$offpolys1}),"\n\n"); ok(scalar(@{$offpolys1})==1,'positive offset, on ccw'); is(Math::Clipper::area($offpolys1->[0]),(16 + 20),'area check for positive ccw off'); #diag("\ngoing in wind1:".Math::Clipper::is_counter_clockwise($ccw) . " vs " .Math::Clipper::is_counter_clockwise($offpolys1->[0])); my $offpolys2 = Math::Clipper::offset([$offpolys1->[0] , $cw], 1.0, 1); # $cw works as a hole inside $offpolys1->[0] ok(scalar(@{$offpolys2})==2,'positive offset, on cw'); my $asum=0; map { #diag("\n".Math::Clipper::area($_)); $asum+=Math::Clipper::area($_) } @{$offpolys2}; is($asum,((16 + 20) + (28) - (16 - 12)),'area check for positive cw off'); my $offpolys3 = Math::Clipper::offset([$ccw], -1.0, 1); #diag("\ngoing in wind2:".Math::Clipper::is_counter_clockwise($ccw) . " vs " .Math::Clipper::is_counter_clockwise($offpolys3->[0])); ok(scalar(@{$offpolys3})==1,'negative offset, on ccw'); is(Math::Clipper::area($offpolys3->[0]),(16 - 12),'area check for negative ccw off'); my $offpolys4 = Math::Clipper::offset([$offpolys2->[0],$offpolys2->[1]], -1.0, 1); ok(scalar(@{$offpolys4})==2,'negative offset, on cw'); $asum=0; map { #diag("\n".Math::Clipper::area($_)); $asum+=Math::Clipper::area($_) } @{$offpolys4}; is($asum,((16 + 20) - 16),'area check for negative cw off'); { my $res = Math::Clipper::int_offset([$ccw], 1.0, 1, JT_MITER, 2); ok @$res == 1, 'positive int_offset, on ccw'; is Math::Clipper::area($res->[0]), (16 + 20), 'area check for positive ccw int_offset'; } { my $res = Math::Clipper::int_offset([$ccw], -1.0, 1, JT_MITER, 2); ok @$res == 1, 'negative int_offset, on ccw'; is Math::Clipper::area($res->[0]), 2*2, 'area check for negative ccw int_offset'; } { my $res = Math::Clipper::int_offset2([$ccw], 1.0, -1.0, 1, JT_MITER, 2); ok @$res == 1, 'int_offset2 returned one item'; is Math::Clipper::area($ccw), Math::Clipper::area($res->[0]), 'int_offset2 performed double offset'; } { my $res = Math::Clipper::ex_int_offset([$ccw, $cw], 1.0, 1, JT_MITER, 2); ok @$res == 1, 'ex_int_offset returned one item'; isa_ok $res->[0], 'HASH', 'ex_int_offset returned one ExPolygon'; } { my $res = Math::Clipper::ex_int_offset2([$ccw], 1.0, -1.0, 1, JT_MITER, 2); ok @$res == 1, 'ex_int_offset2 returned one item'; isa_ok $res->[0], 'HASH', 'ex_int_offset2 returned one ExPolygon'; is Math::Clipper::area($ccw), Math::Clipper::area($res->[0]{outer}), 'ex_int_offset2 performed double offset'; } __END__ Math-Clipper-1.29/t/006winding.t000444001750001750 73613467455703 15445 0ustar00mikemike000000000000use Math::Clipper ':all'; use Test::More tests => 4; my $ccw = [ [0,0], [4,0], [4,4], [0,4] ]; my $cw = [ [0,0], [0,4], [4,4], [4,0] ]; my $tricky = [ [0,0], [40,40], [40,0], [0,41] ]; ok( orientation($ccw) , 'is_ccw on a counter-clockwise polygon'); ok( ! orientation($cw) , 'is_ccw on a clockwise polygon'); ok( orientation($tricky) , 'is_ccw on a bowtie polygon'); is( is_counter_clockwise($ccw), orientation($ccw), 'is_counter_clockwise() === orientation()'); Math-Clipper-1.29/t/007usefullrange.t000444001750001750 20713467455703 16474 0ustar00mikemike000000000000use Math::Clipper ':all'; use Test::More tests=>1; my $clipper = Math::Clipper->new; $clipper->use_full_coordinate_range(1); pass(); Math-Clipper-1.29/t/008integerize.t000444001750001750 1736613467455703 16224 0ustar00mikemike000000000000use Math::Clipper ':all'; use Config; use Test::More tests=>15; use Test::Deep; my $diagnostics=0; my $maxint_64 =4611686018427387902; # Clipper-imposed max (minus 1) when using 64 bit integer math my $maxint_53 = 9007199254740992; # for integers stored in double precision floats with 53 bit mantissa my $maxint; my $extraexp = 0; my $is64safe = 0; if ( ((defined($Config{use64bitint}) && $Config{use64bitint} eq 'define') || $Config{longsize} >= 8 ) && ((defined($Config{uselongdouble}) && $Config{uselongdouble} eq 'define') || $Config{doublesize} >= 10) ) { $maxint = $maxint_64; $extraexp = 3; $is64safe = 1; } else { $maxint = $maxint_53; } note('Using ' . ($maxint==$maxint_53 ? '53' : '64') . ' bit integers max'); { local $SIG{__WARN__} = sub { die @_; }; eval { integerize_coordinate_sets([ [0,0,0] ]); }; is $@, '', 'no warnings from integerize_coordinate_sets()'; } ####################################### # huge diamond, points at limits, as # subject, do dummy bool op, then # is_deeply on first-and-only of result my $big_diamond = [ [-$maxint, 1], [1, -$maxint], [$maxint, -1], [1, $maxint] ]; my $clipper = Math::Clipper->new; $clipper->use_full_coordinate_range(1); $clipper->add_subject_polygon($big_diamond); my $result = $clipper->execute(CT_UNION); is(scalar(@{$result}),1,'round-tripped polygon preserved. a'); if ($diagnostics) {diag("\n\npoints at limits:\ngot\n".join("\n",map {"[$_->[0],$_->[1]]"} @{$result->[0]})."\nexpected\n".join("\n",map {"[$_->[0],$_->[1]]"} @{$big_diamond})."\n\n");} cmp_deeply( $result->[0], bag(@{$big_diamond}), 'round-tripped coords at integer limits preserved' ); $clipper->clear; ####################################### # set up some test data and expected # results my $A = [ [-0.00000000000002 , -5.67999999999999], [ 0.00000000000000000000000001234,-56.78888888888888], [ 0.00000000000000000000000001234, 56.77777777777777] ]; my $Aexpect = [ # in 32 bit environment, we get 53 bit integers back from Clipper, in floats, which may be in sci. notation, or not [ -0.00000000000002 * 10**(14+$extraexp), -5.67999999999999 * 10**(14+$extraexp)], [ 0, -56.78888888888888 * 10**(14+$extraexp)], [ 0, 56.77777777777777 * 10**(14+$extraexp)] ]; my $A2expect = [ [ -0.00000000000002 * 10**(29+$extraexp), -5.67999999999999 * 10**(14+$extraexp)], [ 1234, -56.78888888888888 * 10**(14+$extraexp)], [ 1234, 56.77777777777777 * 10**(14+$extraexp)] ]; my $Aexpect_string = [ # in 64 bit environment, we get real integers back from Clipper, expect always in integer form, no exponents [ '-2'.('0' x ($extraexp - 1)), '-567'.('9' x 12).('0' x ($extraexp - 1))], [ 0, '-5678'.('8' x 12).('0' x ($extraexp - 1))], [ 0, '5677'.('7' x 12).('0' x ($extraexp - 1))] ]; my $A2expect_string = [ [ '-2'.('0' x (15+$extraexp)), '-567'.('9' x 12).('0' x ($extraexp - 1))], [ '1234'.('0' x $extraexp), '-5678'.('8' x 12).('0' x ($extraexp - 1))], [ '1234'.('0' x $extraexp), '5677'.('7' x 12).('0' x ($extraexp - 1))] ]; my $AexpectUnscaled = [ [ -0.00000000000002, -5.67999999999999], [ 0, -56.78888888888888], [ 0, 56.77777777777777] ]; my $B = [ [ 1000000000000001, -1000000000000001], [ 0.5, 0.4], [-0.5,-0.4] ]; my $Bexpect = [ [ 1000000000000001, -1000000000000001], [ 1, 0], [-1, 0] ]; if ($is64safe) { $Aexpect = $Aexpect_string; $A2expect = $A2expect_string; } ####################################### # not enough sig figs, even with int64, # to hold original coords in integers # so some coords become plain zero my $Ac = clone($A); my $scalevec = integerize_coordinate_sets({constrain=>1},$Ac); if ($diagnostics) {diag("\n\nintegerized constrained:\ngot\n".join("\n",map {"[$_->[0],$_->[1]]"} @{f1($Ac)})."\nexpected\n".join("\n",map {"[$_->[0],$_->[1]]"} @{f1($Aexpect)})."\n\n");} cmp_deeply( f1($Ac), bag( @{f1($Aexpect)} ), 'lose smallest digits when integerized constrained' ); $clipper->add_subject_polygon($Ac); $result = $clipper->execute(CT_UNION); is(scalar(@{$result}), 1, 'round-tripped polygon preserved. b'); if ($diagnostics) {diag("\n\nintegerized constrained roundtripped:\ngot\n".join("\n",map {"[$_->[0],$_->[1]]"} @{f1($result->[0])})."\nexpected\n".join("\n",map {"[$_->[0],$_->[1]]"} @{f1($Aexpect)})."\n\n");} cmp_deeply( f1($result->[0]), bag( @{f1($Aexpect)} ), 'lose smallest digits when integerized constrained - roundtripped' ); unscale_coordinate_sets($scalevec, $result); if ($diagnostics) {diag("\n\nintegerized constrained - unscaled:\n".join("\n",map {"[$_->[0],$_->[1]]"} @{$result->[0]})."\nand\n".join("\n",map {"[$_->[0],$_->[1]]"} @{$AexpectUnscaled})."\n\n");} cmp_deeply( $result->[0], bag( @{$AexpectUnscaled} ), 'lose smallest digits when integerized constrained - unscaled' ); $clipper->clear; ####################################### # use non-constrained scaling to # preserve digits that wouldn't be # preserved with constrained $Ac = clone($A); $scalevec = integerize_coordinate_sets({constrain=>0}, $Ac); if ($diagnostics) {diag("\n\nintegerized not constrained:\ngot\n".join("\n",map {"[$_->[0],$_->[1]]"} @{f1($Ac)})."\nexpected\n".join("\n",map {"[$_->[0],$_->[1]]"} @{f1($A2expect)})."\n\n");} cmp_deeply( f1($Ac), bag( @{f1($A2expect)} ), 'keep smallest digits when integerized not constrained' ); $clipper->add_subject_polygon($Ac); $result = $clipper->execute(CT_UNION); is(scalar(@{$result}), 1, 'round-tripped polygon preserved. c'); if ($diagnostics) {diag("\n\nintegerized not constrained roundtripped:\ngot\n".join("\n",map {"[$_->[0],$_->[1]]"} @{f1($result->[0])})."\nexpected\n".join("\n",map {"[$_->[0],$_->[1]]"} @{f1($A2expect)})."\n\n");} cmp_deeply( f1($result->[0]), bag( @{f1($A2expect)} ), 'keep smallest digits when integerized not constrained - roundtripped' ); unscale_coordinate_sets($scalevec,$result); if ($diagnostics) {diag("\n\nintegerized not constrained - unscaled:\n".join("\n",map {"[$_->[0],$_->[1]]"} @{$result->[0]})."\nand\n".join("\n",map {"[$_->[0],$_->[1]]"} @{$A})."\n\n");} cmp_deeply( $result->[0], bag( @{$A} ), 'keep smallest digits when integerized not constrained - unscaled' ); $clipper->clear; ####################################### # two coordinate sets (polygons) # scale-to-integer factors determined # to handle all coords in both sets $scalevec=integerize_coordinate_sets({constrain=>0,bits=>53},[[1,2,3],[2,3,1],[3,2,1]],[[10,200,3000],[20,300,1000],[30,200,1000]]); is_deeply($scalevec,[10**14,10**13,10**12],'scaling vector accommodates all polygon coordinates'); ####################################### # rounding of ones place for n < 1 my $Bc = clone($B); $scalevec = integerize_coordinate_sets({constrain=>0, bits=>53}, $Bc); if ($diagnostics) {diag("\n\nrounding:\ngot\n".join("\n",map {"[$_->[0],$_->[1]]"} @{f1($Bc)})."\nexpected\n".join("\n",map {"[$_->[0],$_->[1]]"} @{f1($Bexpect)})."\n\n");} cmp_deeply( f1($Bc), bag( @{f1($Bexpect)} ), 'rounding' ); ####################################### # unscaling coordinate sets my $S = [ [1,2,3,4], [5,6,7,8] ]; my $Sexpect = [ [10,20,30,40], [50,60,70,80] ]; my $S2expect = [ [10,10, -6,400], [50,30,-14,800] ]; unscale_coordinate_sets(1/10, [$S]); is_deeply( $S, $Sexpect, 'uniform scale'); unscale_coordinate_sets([1, 2, -5, 0.1], [$S]); is_deeply( $S, $S2expect, 'scale with vector'); sub clone {return [(map {[(@{$_})]} @{$_[0]})]} sub f1 { return [ map { my $x = sprintf("%.0f", $_->[0]); my $y = sprintf("%.0f", $_->[1]); $x = '0' if $x eq '-0'; $y = '0' if $y eq '-0'; [ $x, $y ] } @{$_[0]} ]; } Math-Clipper-1.29/t/009expolygon.t000444001750001750 235013467455703 16047 0ustar00mikemike000000000000use Math::Clipper ':all'; use Test::More tests=>6; use Test::Deep; my $ai = [ #area = 16 [0,0], [4,0], [4,4], [0,4] ]; my $bi = [#area = 4, is inside $ai [1,1], [3,1], [3,3], [1,3] ]; my $bir = [#area = 4 (negative if PFT_NONZERO), is inside $ai [1,3], [3,3], [3,1], [1,1] ]; my $clipper = Math::Clipper->new; $clipper->add_subject_polygon($ai); $clipper->add_subject_polygon($bi); my $result = $clipper->ex_execute(CT_DIFFERENCE,PFT_EVENODD,PFT_EVENODD); # PFT_EVENODD is default, just being explicit here is(scalar(@{$result}),1,'one expolygon with outer and holes'); cmp_bag($result->[0]->{outer},$ai,'outer same as original outer'); #diag("\nmany?:".scalar(@{$result->[0]->{holes}})."\n"); cmp_bag($result->[0]->{holes}->[0],$bi,'holes[0] same as original hole'); $clipper->clear(); #same, but with PFT_NONZERO fill strategy $clipper->add_subject_polygon($ai); $clipper->add_subject_polygon($bir); $result = $clipper->ex_execute(CT_DIFFERENCE,PFT_NONZERO,PFT_NONZERO); is(scalar(@{$result}),1,'one expolygon with outer and holes'); cmp_bag($result->[0]->{outer},$ai,'outer same as original outer'); #diag("\nmany?:".scalar(@{$result->[0]->{holes}})."\n"); cmp_bag($result->[0]->{holes}->[0],$bi,'holes[0] same as original hole'); $clipper->clear();Math-Clipper-1.29/t/010simplify.t000444001750001750 133113467455703 15645 0ustar00mikemike000000000000use strict; use warnings; use Math::Clipper ':all'; use Test::More tests => 4; my $p1 = [ [1,1], [3,3], [3,1], [1,3] ]; my $p2 = [ [0,0], [4,0], [4,4], [0,4], ]; { my $simplified = simplify_polygon($p1, PFT_EVENODD); is scalar(@$simplified), 2, 'simplify_polygon returned 2 polygons'; is scalar(grep !orientation($_), @$simplified), 0, 'simplified polygons are ccw'; } # check that the same simplified polygons are returned as holes now { my $simplified = simplify_polygons([$p1, $p2], PFT_EVENODD); is scalar(@$simplified), 3, 'simplify_polygon returned 3 polygons'; is scalar(grep !orientation($_), @$simplified), 2, '2 out of 3 polygons are cw (holes)'; } __END__ Math-Clipper-1.29/t/011Int128Comparison.t000444001750001750 211713467455703 17035 0ustar00mikemike000000000000use strict; use warnings; use Math::Clipper ':all'; use Test::More tests => 1; # The following polygon with a -10000000000 offset # triggers an overloaded comparison operator in # Clipper's Int128 class that is suseptible to # giving wrong results in the 2^63 to 2^64 range # if it's args aren't cast to unsigned 64 bit ints. # This test is to guard against regression in that # section of code which might be suseptible to # overzealous tidying, and to make sure we don't lose # this interim fix while waiting for the upstream # version that includes the author's fix. # see: http://sourceforge.net/p/polyclipping/bugs/47/ my $p1 = [ [715322100000 , 7451240000000], [713848100000 , 7450925400000], [549678100000 , 7416033200000], [1048842200000, 7416347200000], [884673700000 , 7451240000000] ]; my $winding_before = Math::Clipper::orientation($p1); my $offsets = Math::Clipper::offset([$p1], -10000000000, 1); my $winding_after = Math::Clipper::orientation($offsets->[0]); ok($winding_before eq $winding_after, "http://sourceforge.net/p/polyclipping/bugs/47/"); __END__ Math-Clipper-1.29/t/012_polytree.t000444001750001750 307013467455703 16017 0ustar00mikemike000000000000use Math::Clipper ':all'; use Test::More tests => 9; { my $square1 = [ [0,0], [10,0], [10,10], [0,10], ]; my $hole1 = [ [2,2], [2,8], [8,8], [8,2], ]; my $square2 = [ [4,4], [6,4], [6,6], [4,6], ]; my $clipper = Math::Clipper->new; $clipper->add_subject_polygons([ $square1, $hole1, $square2 ]); my $polytree = $clipper->pt_execute(CT_UNION); is scalar(@$polytree), 1, 'only one top-level polygon'; ok exists $polytree->[0]{outer}, 'top-level polygon has outer type'; is area($polytree->[0]{outer}), area($square1), 'top-level polygon has expected area'; is scalar(@{ $polytree->[0]{children} }), 1, 'top-level polygon has one child'; ok exists $polytree->[0]{children}[0]{hole}, 'top-level polygon child is hole'; is scalar(@{ $polytree->[0]{children}[0]{children} }), 1, 'hole has one child'; ok exists $polytree->[0]{children}[0]{children}[0]{outer}, 'hole child has outer type'; is area($polytree->[0]{children}[0]{children}[0]{outer}), area($square2), 'hole child has expected area'; } { my $square1 = [ [0,0], [10,0], [10,10], [0,10], ]; my $square2 = [ [20,20], [30,20], [30,30], [20,30], ]; my $clipper = Math::Clipper->new; $clipper->add_subject_polygons([ $square1, $square2 ]); my $polytree = $clipper->pt_execute(CT_INTERSECTION); is scalar(@$polytree), 0, 'null intersection returned empty arrayref'; } __END__ Math-Clipper-1.29/xsp000755001750001750 013467455703 13617 5ustar00mikemike000000000000Math-Clipper-1.29/xsp/Clipper.xsp000444001750001750 1572113467455703 16134 0ustar00mikemike000000000000 %module{Math::Clipper}; %package{Math::Clipper}; %{ #include PROTOTYPES: DISABLE IV _constant() ALIAS: CT_INTERSECTION = ctIntersection CT_UNION = ctUnion CT_DIFFERENCE = ctDifference CT_XOR = ctXor PT_SUBJECT = ptSubject PT_CLIP = ptClip PFT_EVENODD = pftEvenOdd PFT_NONZERO = pftNonZero PFT_POSITIVE = pftPositive PFT_NEGATIVE = pftNegative JT_MITER = jtMiter JT_ROUND = jtRound JT_SQUARE = jtSquare CODE: RETVAL = ix; OUTPUT: RETVAL %} %name{Math::Clipper} class Clipper { Clipper(); ~Clipper(); %{ ClipperLib::Polygons* execute(THIS, clipType, subjFillType = pftEvenOdd, clipFillType = pftEvenOdd) Clipper* THIS ClipType clipType PolyFillType subjFillType PolyFillType clipFillType CODE: RETVAL = new ClipperLib::Polygons(); THIS->Execute(clipType, *RETVAL, subjFillType, clipFillType); OUTPUT: RETVAL ExPolygons* ex_execute(THIS, clipType, subjFillType = pftEvenOdd, clipFillType = pftEvenOdd) Clipper* THIS ClipType clipType PolyFillType subjFillType PolyFillType clipFillType CODE: PolyTree* polytree = new ClipperLib::PolyTree(); THIS->Execute(clipType, *polytree, subjFillType, clipFillType); RETVAL = new ExPolygons(); PolyTreeToExPolygons(*polytree, *RETVAL); delete polytree; OUTPUT: RETVAL ClipperLib::PolyTree* pt_execute(THIS, clipType, subjFillType = pftEvenOdd, clipFillType = pftEvenOdd) Clipper* THIS ClipType clipType PolyFillType subjFillType PolyFillType clipFillType CODE: RETVAL = new ClipperLib::PolyTree(); THIS->Execute(clipType, *RETVAL, subjFillType, clipFillType); OUTPUT: RETVAL %} // No longer in v4.X // %name{get_force_orientation} // bool ForceOrientation(); // %name{set_force_orientation} // void ForceOrientation(bool value); // We don't expose this since we save the PolyType stuff entirely that way! // %name{add_polygon} // void AddPolygon(const Polygon &pg, PolyType polyType); %{ void add_subject_polygon(self, poly) Clipper* self ClipperLib::Polygon* poly PPCODE: self->AddPolygon(*poly, ptSubject); delete poly; void add_clip_polygon(self, poly) Clipper* self ClipperLib::Polygon* poly PPCODE: self->AddPolygon(*poly, ptClip); delete poly; void add_subject_polygons(self, polys) Clipper* self ClipperLib::Polygons* polys PPCODE: self->AddPolygons(*polys, ptSubject); delete polys; void add_clip_polygons(self, polys) Clipper* self ClipperLib::Polygons* polys PPCODE: self->AddPolygons(*polys, ptClip); delete polys; double orientation(polygon) ClipperLib::Polygon* polygon CODE: RETVAL = ClipperLib::Orientation(*polygon); delete polygon; OUTPUT: RETVAL double area(polygon) ClipperLib::Polygon* polygon CODE: RETVAL = ClipperLib::Area(*polygon); delete polygon; OUTPUT: RETVAL ClipperLib::Polygons* _offset(polygons, delta, jointype, MiterLimit) ClipperLib::Polygons* polygons const float delta JoinType jointype const double MiterLimit CODE: RETVAL = new ClipperLib::Polygons(); ClipperLib::OffsetPolygons(*polygons, *RETVAL, delta, jointype, MiterLimit); delete polygons; OUTPUT: RETVAL ClipperLib::Polygons* int_offset(polygons, delta, scale, jointype, MiterLimit) ClipperLib::Polygons* polygons const float delta const double scale JoinType jointype const double MiterLimit CODE: RETVAL = _int_offset(polygons, delta, scale, jointype, MiterLimit); delete polygons; OUTPUT: RETVAL ClipperLib::Polygons* int_offset2(polygons, delta1, delta2, scale, jointype, MiterLimit) ClipperLib::Polygons* polygons const float delta1 const float delta2 const double scale JoinType jointype const double MiterLimit CODE: // scale _scale_polygons(polygons, scale); // perform first offset ClipperLib::Polygons* offset1 = new ClipperLib::Polygons(); ClipperLib::OffsetPolygons(*polygons, *offset1, (delta1*scale), jointype, MiterLimit); // perform second offset RETVAL = new ClipperLib::Polygons(); ClipperLib::OffsetPolygons(*offset1, *RETVAL, (delta2*scale), jointype, MiterLimit); // unscale _scale_polygons(RETVAL, 1/scale); // cleanup delete offset1; delete polygons; OUTPUT: RETVAL ExPolygons* ex_int_offset(polygons, delta, scale, jointype, MiterLimit) ClipperLib::Polygons* polygons const float delta const double scale JoinType jointype const double MiterLimit CODE: Clipper clpr; clpr.Clear(); ClipperLib::Polygons* offset = _int_offset(polygons, delta, scale, jointype, MiterLimit); clpr.AddPolygons(*offset, ptSubject); PolyTree* polytree = new ClipperLib::PolyTree(); clpr.Execute(ctUnion, *polytree, pftEvenOdd, pftEvenOdd); // offset results work with both EvenOdd and NonZero RETVAL = new ExPolygons(); PolyTreeToExPolygons(*polytree, *RETVAL); // cleanup delete polygons; delete offset; delete polytree; OUTPUT: RETVAL ExPolygons* ex_int_offset2(polygons, delta1, delta2, scale, jointype, MiterLimit) ClipperLib::Polygons* polygons const float delta1 const float delta2 const double scale JoinType jointype const double MiterLimit CODE: // scale _scale_polygons(polygons, scale); // perform first offset ClipperLib::Polygons* offset1 = new ClipperLib::Polygons(); ClipperLib::OffsetPolygons(*polygons, *offset1, (delta1*scale), jointype, MiterLimit); // perform second offset ClipperLib::Polygons* offset2 = new ClipperLib::Polygons(); ClipperLib::OffsetPolygons(*offset1, *offset2, (delta2*scale), jointype, MiterLimit); // unscale _scale_polygons(offset2, 1/scale); // perform UNION Clipper clpr; clpr.Clear(); clpr.AddPolygons(*offset2, ptSubject); PolyTree* polytree = new ClipperLib::PolyTree(); clpr.Execute(ctUnion, *polytree, pftEvenOdd, pftEvenOdd); // offset results work with both EvenOdd and NonZero // convert result to ExPolygons RETVAL = new ExPolygons(); PolyTreeToExPolygons(*polytree, *RETVAL); // cleanup delete polygons; delete offset1; delete offset2; delete polytree; OUTPUT: RETVAL ClipperLib::Polygons* simplify_polygon(polygon, fillType) ClipperLib::Polygon* polygon PolyFillType fillType CODE: RETVAL = new ClipperLib::Polygons(); ClipperLib::SimplifyPolygon(*polygon, *RETVAL, fillType); delete polygon; OUTPUT: RETVAL ClipperLib::Polygons* simplify_polygons(polygons, fillType) ClipperLib::Polygons* polygons PolyFillType fillType CODE: RETVAL = new ClipperLib::Polygons(); ClipperLib::SimplifyPolygons(*polygons, *RETVAL, fillType); delete polygons; OUTPUT: RETVAL SV* _floor(x) SV * x CODE: RETVAL = SvNOK(x) ? newSVnv(Perl_floor(SvNV(x))) : newSViv(SvIV(x)); OUTPUT: RETVAL %} %name{clear} void Clear(); }; Math-Clipper-1.29/xsp/my.map000444001750001750 1162213467455703 15122 0ustar00mikemike000000000000Clipper* O_OBJECT PolyType T_UV ClipType T_UV PolyFillType T_UV JoinType T_UV ClipperLib::Polygon T_VECTOR_POINT ClipperLib::Polygon* T_VECTOR_POINT_PTR ClipperLib::Polygons T_VECTOR_VECTOR_POINT ClipperLib::Polygons* T_VECTOR_VECTOR_POINT_PTR ClipperLib::PolyTree* T_POLYTREE_PTR ExPolygon T_EXPOLY ExPolygon* T_EXPOLY_PTR ExPolygons T_VECTOR_EXPOLY ExPolygons* T_VECTOR_EXPOLY_PTR INPUT T_VECTOR_POINT if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV) { $type* tmp = perl2polygon(aTHX_ (AV*)SvRV($arg)); if (tmp == NULL) { Perl_croak(aTHX_ \"%s: %s is not an array reference or contains invalid data\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); } else { $var = *tmp; delete tmp; } } else Perl_croak(aTHX_ \"%s: %s is not an array reference\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); T_VECTOR_POINT_PTR if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV) { $var = perl2polygon(aTHX_ (AV*)SvRV($arg)); if (($var) == NULL) { Perl_croak(aTHX_ \"%s: %s is not an array reference or contains invalid data\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); } } else Perl_croak(aTHX_ \"%s: %s is not an array reference\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); T_VECTOR_VECTOR_POINT if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV) { $type* tmp = perl2polygons(aTHX_ (AV*)SvRV($arg)); if (tmp == NULL) { Perl_croak(aTHX_ \"%s: %s is not an array reference or contains invalid data\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); } else { $var = *tmp; delete tmp; } } else Perl_croak(aTHX_ \"%s: %s is not an array reference\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); T_VECTOR_VECTOR_POINT_PTR if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV) { $var = perl2polygons(aTHX_ (AV*)SvRV($arg)); if (($var) == NULL) { Perl_croak(aTHX_ \"%s: %s is not an array reference or contains invalid data\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); } } else Perl_croak(aTHX_ \"%s: %s is not an array reference\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); T_EXPOLY if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVHV) { $type* tmp = perl2expolygon(aTHX_ (HV*)SvRV($arg)); if (tmp == NULL) { Perl_croak(aTHX_ \"%s: %s is not a hash reference or contains invalid data\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); } else { $var = *tmp; delete tmp; } } else Perl_croak(aTHX_ \"%s: %s is not a hash reference\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); T_EXPOLY_PTR if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVHV) { $var = perl2expolygon(aTHX_ (HV*)SvRV($arg)); if (($var) == NULL) { Perl_croak(aTHX_ \"%s: %s is not a hash reference or contains invalid data\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); } } else Perl_croak(aTHX_ \"%s: %s is not a hash reference\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); T_VECTOR_EXPOLY if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV) { $type* tmp = perl2expolygons(aTHX_ (AV*)SvRV($arg)); if (tmp == NULL) { Perl_croak(aTHX_ \"%s: %s is not an array reference or contains invalid data\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); } else { $var = *tmp; delete tmp; } } else Perl_croak(aTHX_ \"%s: %s is not an array reference\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); T_VECTOR_EXPOLY_PTR if (SvROK($arg) && SvTYPE(SvRV($arg))==SVt_PVAV) { $var = perl2expolygons(aTHX_ (AV*)SvRV($arg)); if (($var) == NULL) { Perl_croak(aTHX_ \"%s: %s is not an array reference or contains invalid data\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); } } else Perl_croak(aTHX_ \"%s: %s is not an array reference\", ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); OUTPUT T_VECTOR_POINT $arg = polygon2perl(aTHX_ $var); T_VECTOR_POINT_PTR $arg = polygon2perl(aTHX_ *$var); delete $var; T_VECTOR_VECTOR_POINT $arg = polygons2perl(aTHX_ $var); T_VECTOR_VECTOR_POINT_PTR $arg = polygons2perl(aTHX_ *$var); delete $var; T_EXPOLY $arg = expolygon2perl(aTHX_ $var); T_EXPOLY_PTR $arg = expolygon2perl(aTHX_ *$var); delete $var; T_VECTOR_EXPOLY $arg = expolygons2perl(aTHX_ $var); T_VECTOR_EXPOLY_PTR $arg = expolygons2perl(aTHX_ *$var); delete $var; T_POLYTREE_PTR $arg = polytree2perl(aTHX_ *$var); delete $var; Math-Clipper-1.29/xsp/types.xspt000444001750001750 142613467455703 16043 0ustar00mikemike000000000000%typemap{bool}{simple}; %typemap{ClipperLib::Polygon}; %typemap{const ClipperLib::Polygon}; %typemap{ClipperLib::Polygons}; %typemap{const ClipperLib::Polygons}; %typemap{ClipperLib::ExPolygon}; %typemap{const ClipperLib::ExPolygon}; %typemap{ClipperLib::ExPolygons}; %typemap{const ClipperLib::ExPolygons}; %typemap{PolyType}{parsed}{ %cpp_type{PolyType}; %precall_code{% $CVar = (PolyType)SvUV($PerlVar); %}; }; %typemap{ClipType}{parsed}{ %cpp_type{ClipType}; %precall_code{% $CVar = (ClipType)SvUV($PerlVar); %}; }; %typemap{PolyFillType}{parsed}{ %cpp_type{PolyFillType}; %precall_code{% $CVar = (PolyFillType)SvUV($PerlVar); %}; }; %typemap{JoinType}{parsed}{ %cpp_type{JoinType}; %precall_code{% $CVar = (JoinType)SvUV($PerlVar); %}; };