mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	Implement nearest point index and split at index to avoid search for point.
This commit is contained in:
		
							parent
							
								
									35fda7de23
								
							
						
					
					
						commit
						35ecd65e77
					
				
					 4 changed files with 31 additions and 16 deletions
				
			
		|  | @ -5,7 +5,7 @@ use Moo; | |||
| has 'polygon' => ( | ||||
|     is          => 'rw', | ||||
|     required    => 1, | ||||
|     handles     => [qw(is_printable nearest_point_to reverse)], | ||||
|     handles     => [qw(is_printable nearest_point_index_to reverse)], | ||||
| ); | ||||
| 
 | ||||
| has 'flow_spacing' => (is => 'rw'); | ||||
|  | @ -29,6 +29,23 @@ sub shortest_path { | |||
|     return $self; | ||||
| } | ||||
| 
 | ||||
| sub split_at_index { | ||||
|     my $self = shift; | ||||
|     my ($index) = @_; | ||||
| 
 | ||||
|     $self->deserialize; | ||||
| 
 | ||||
|     my @new_points = (); | ||||
|     push @new_points, @{$self->polygon}[$index .. $#{$self->polygon}]; | ||||
|     push @new_points, @{$self->polygon}[0 .. $index]; | ||||
|      | ||||
|     return Slic3r::ExtrusionPath->new( | ||||
|         polyline    => Slic3r::Polyline->new(\@new_points), | ||||
|         role        => $self->role, | ||||
|         flow_spacing => $self->flow_spacing, | ||||
|     ); | ||||
| } | ||||
| 
 | ||||
| sub split_at { | ||||
|     my $self = shift; | ||||
|     my ($point) = @_; | ||||
|  | @ -47,21 +64,12 @@ sub split_at { | |||
|     } | ||||
|     die "Point not found" if $i == -1; | ||||
|      | ||||
|     my @new_points = (); | ||||
|     push @new_points, @{$self->polygon}[$i .. $#{$self->polygon}]; | ||||
|     push @new_points, @{$self->polygon}[0 .. $i]; | ||||
|      | ||||
|     return Slic3r::ExtrusionPath->new( | ||||
|         polyline    => Slic3r::Polyline->new(\@new_points), | ||||
|         role        => $self->role, | ||||
|         flow_spacing => $self->flow_spacing, | ||||
|     ); | ||||
|     return $self->split_at_index($i); | ||||
| } | ||||
| 
 | ||||
| sub split_at_first_point { | ||||
|     my $self = shift; | ||||
|     $self->deserialize; | ||||
|     return $self->split_at($self->polygon->[0]); | ||||
|     return $self->split_at_index(0); | ||||
| } | ||||
| 
 | ||||
| # although a loop doesn't have endpoints, this method is provided to allow | ||||
|  |  | |||
|  | @ -57,10 +57,11 @@ sub fill_surface { | |||
|         $loop->polygon->make_counter_clockwise; | ||||
|          | ||||
|         # find the point of the loop that is closest to the current extruder position | ||||
|         $cur_pos = $loop->nearest_point_to($cur_pos); | ||||
|         my $index = $loop->nearest_point_index_to($cur_pos); | ||||
|         $cur_pos = $loop->polygon->[0]; | ||||
|          | ||||
|         # split the loop at the starting point and make a path | ||||
|         my $path = $loop->split_at($cur_pos); | ||||
|         my $path = $loop->split_at_index($index); | ||||
|         $path->deserialize; | ||||
|          | ||||
|         # clip the path to avoid the extruder to get exactly on the first point of the loop | ||||
|  |  | |||
|  | @ -103,10 +103,10 @@ sub extrude_loop { | |||
|         $last_pos = Slic3r::Point->new(scale $Slic3r::print_center->[X], scale $Slic3r::bed_size->[Y]); | ||||
|         $last_pos->rotate(rand(2*PI), $Slic3r::print_center); | ||||
|     } | ||||
|     my $start_at = $loop->nearest_point_to($last_pos); | ||||
|     my $start_index = $loop->nearest_point_index_to($last_pos); | ||||
|      | ||||
|     # split the loop at the starting point and make a path | ||||
|     my $extrusion_path = $loop->split_at($start_at); | ||||
|     my $extrusion_path = $loop->split_at_index($start_index); | ||||
|     $extrusion_path->deserialize; | ||||
|      | ||||
|     # clip the path to avoid the extruder to get exactly on the first point of the loop; | ||||
|  |  | |||
|  | @ -97,6 +97,12 @@ sub nearest_point_to { | |||
|     return Slic3r::Point->new($point); | ||||
| } | ||||
| 
 | ||||
| sub nearest_point_index_to { | ||||
|     my $self = shift; | ||||
|     my ($point) = @_; | ||||
|     return Slic3r::Geometry::nearest_point_index($point, $self); | ||||
| } | ||||
| 
 | ||||
| sub has_segment { | ||||
|     my $self = shift; | ||||
|     my ($line) = @_; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Mark Hindess
						Mark Hindess