mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 12:11:15 -06:00 
			
		
		
		
	New Polygon::triangulate_convex() method
This commit is contained in:
		
							parent
							
								
									ca4d4211c9
								
							
						
					
					
						commit
						bb0ce3cccd
					
				
					 4 changed files with 34 additions and 1 deletions
				
			
		|  | @ -3,8 +3,11 @@ | |||
| use strict; | ||||
| use warnings; | ||||
| 
 | ||||
| use List::Util qw(first); | ||||
| use Slic3r::XS; | ||||
| use Test::More tests => 17; | ||||
| use Test::More tests => 19; | ||||
| 
 | ||||
| use constant PI => 4 * atan2(1, 1); | ||||
| 
 | ||||
| my $square = [  # ccw | ||||
|     [100, 100], | ||||
|  | @ -53,6 +56,19 @@ ok ref($polygon->first_point) eq 'Slic3r::Point', 'first_point'; | |||
| ok $polygon->contains_point(Slic3r::Point->new(150,150)), 'ccw contains_point'; | ||||
| ok $cw_polygon->contains_point(Slic3r::Point->new(150,150)), 'cw contains_point'; | ||||
| 
 | ||||
| { | ||||
|     my @points = (Slic3r::Point->new(100,0)); | ||||
|     foreach my $i (1..5) { | ||||
|         my $point = $points[0]->clone; | ||||
|         $point->rotate(PI/3*$i, [0,0]); | ||||
|         push @points, $point; | ||||
|     } | ||||
|     my $hexagon = Slic3r::Polygon->new(@points); | ||||
|     my $triangles = $hexagon->triangulate_convex; | ||||
|     is scalar(@$triangles), 4, 'right number of triangles'; | ||||
|     ok !(defined first { $_->is_clockwise } @$triangles), 'all triangles are ccw'; | ||||
| } | ||||
| 
 | ||||
| # this is not a test: this just demonstrates bad usage, where $polygon->clone gets | ||||
| # DESTROY'ed before the derived object ($point), causing bad memory access | ||||
| if (0) { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci