Exclude crop-border scenery from native friend steering
This commit is contained in:
@@ -151,10 +151,11 @@ function BlueFriends([string]$Path){
|
||||
for($y=0;$y-lt$height;$y++){for($x=0;$x-lt$width;$x++){$pixel=$bitmap.GetPixel(530+$x*4,280+$y*4);$mask[$y*$width+$x]=$pixel.R-lt135-and$pixel.B-ge100-and($pixel.B-$pixel.R)-gt45-and($pixel.G-$pixel.R)-gt20}}
|
||||
$friends=[Collections.Generic.List[object]]::new();$queue=[Collections.Generic.Queue[int]]::new()
|
||||
for($index=0;$index-lt$mask.Length;$index++){
|
||||
if(!$mask[$index]){continue};$mask[$index]=$false;$queue.Enqueue($index);$count=0;$sumX=0;$sumY=0
|
||||
if(!$mask[$index]){continue};$mask[$index]=$false;$queue.Enqueue($index);$count=0;$sumX=0;$sumY=0;$touchesBorder=$false
|
||||
while($queue.Count){$cell=$queue.Dequeue();$x=$cell%$width;$y=[int][Math]::Floor($cell/$width);$count++;$sumX+=$x;$sumY+=$y
|
||||
if($x-eq0-or$x-eq($width-1)-or$y-eq0-or$y-eq($height-1)){$touchesBorder=$true}
|
||||
foreach($neighbor in @(($cell-1),($cell+1),($cell-$width),($cell+$width))){if($neighbor-lt0-or$neighbor-ge$mask.Length){continue};if([Math]::Abs(($neighbor%$width)-$x)+[Math]::Abs([int][Math]::Floor($neighbor/$width)-$y)-ne1){continue};if($mask[$neighbor]){$mask[$neighbor]=$false;$queue.Enqueue($neighbor)}}}
|
||||
if($count-ge30){$friends.Add(@{x=530+4*$sumX/$count;y=280+4*$sumY/$count;sampledBluePixels=$count})}
|
||||
if($count-ge30-and!$touchesBorder){$friends.Add(@{x=530+4*$sumX/$count;y=280+4*$sumY/$count;sampledBluePixels=$count})}
|
||||
}
|
||||
return @($friends|Sort-Object sampledBluePixels -Descending|Select-Object -First 2)
|
||||
}finally{$bitmap.Dispose()}
|
||||
|
||||
Reference in New Issue
Block a user