@@ -385,30 +385,30 @@ public sealed record class ArenaBoundsComplex : ArenaBoundsCustom
385
385
public readonly WPos Center ;
386
386
public bool IsCircle ; // can be used by gaze component for gazes outside of the arena
387
387
388
- public ArenaBoundsComplex ( Shape [ ] UnionShapes , Shape [ ] ? DifferenceShapes = null , Shape [ ] ? AdditionalShapes = null , float MapResolution = 0.5f , float ScaleFactor = 1f , bool AllowObstacleMap = false , float Offset = default )
389
- : base ( BuildBounds ( UnionShapes , DifferenceShapes , AdditionalShapes , MapResolution , ScaleFactor , AllowObstacleMap , Offset , out var center , out var halfWidth , out var halfHeight ) )
388
+ public ArenaBoundsComplex ( Shape [ ] UnionShapes , Shape [ ] ? DifferenceShapes = null , Shape [ ] ? AdditionalShapes = null , float MapResolution = 0.5f , float ScaleFactor = 1f , bool AllowObstacleMap = false , float Offset = default , bool AdjustForHitbox = false )
389
+ : base ( BuildBounds ( UnionShapes , DifferenceShapes , AdditionalShapes , MapResolution , ScaleFactor , AllowObstacleMap , Offset , AdjustForHitbox , out var center , out var halfWidth , out var halfHeight ) )
390
390
{
391
391
Center = center ;
392
392
HalfWidth = halfWidth + Offset ;
393
393
HalfHeight = halfHeight + Offset ;
394
394
}
395
395
396
- private static ArenaBoundsCustom BuildBounds ( Shape [ ] unionShapes , Shape [ ] ? differenceShapes , Shape [ ] ? additionalShapes , float mapResolution , float scalefactor , bool allowObstacleMap , float offset , out WPos center , out float halfWidth , out float halfHeight )
396
+ private static ArenaBoundsCustom BuildBounds ( Shape [ ] unionShapes , Shape [ ] ? differenceShapes , Shape [ ] ? additionalShapes , float mapResolution , float scalefactor , bool allowObstacleMap , float offset , bool adjustForHitbox , out WPos center , out float halfWidth , out float halfHeight )
397
397
{
398
- var properties = CalculatePolygonProperties ( unionShapes , differenceShapes ?? [ ] , additionalShapes ?? [ ] ) ;
398
+ var properties = CalculatePolygonProperties ( unionShapes , differenceShapes ?? [ ] , additionalShapes ?? [ ] , adjustForHitbox ) ;
399
399
center = properties . Center ;
400
400
halfWidth = properties . HalfWidth ;
401
401
halfHeight = properties . HalfHeight ;
402
- return new ( scalefactor == 1 ? properties . Radius : properties . Radius / scalefactor , properties . Poly , mapResolution , scalefactor , allowObstacleMap , offset ) ;
402
+ return new ( scalefactor == 1f ? properties . Radius : properties . Radius / scalefactor , properties . Poly , mapResolution , scalefactor , allowObstacleMap , offset ) ;
403
403
}
404
404
405
- private static ( WPos Center , float HalfWidth , float HalfHeight , float Radius , RelSimplifiedComplexPolygon Poly ) CalculatePolygonProperties ( Shape [ ] unionShapes , Shape [ ] differenceShapes , Shape [ ] additionalShapes )
405
+ private static ( WPos Center , float HalfWidth , float HalfHeight , float Radius , RelSimplifiedComplexPolygon Poly ) CalculatePolygonProperties ( Shape [ ] unionShapes , Shape [ ] differenceShapes , Shape [ ] additionalShapes , bool adjustForHitbox )
406
406
{
407
407
var unionPolygons = ParseShapes ( unionShapes ) ;
408
408
var differencePolygons = ParseShapes ( differenceShapes ) ;
409
409
var additionalPolygons = ParseShapes ( additionalShapes ) ;
410
-
411
- var combinedPoly = CombinePolygons ( unionPolygons , differencePolygons , additionalPolygons ) ;
410
+ var combine = CombinePolygons ( unionPolygons , differencePolygons , additionalPolygons ) ;
411
+ var combinedPoly = adjustForHitbox ? combine . Offset ( - 0.5f , Clipper2Lib . JoinType . Round ) : combine ;
412
412
413
413
float minX = float . MaxValue , maxX = float . MinValue , minZ = float . MaxValue , maxZ = float . MinValue ;
414
414
var combined = combinedPoly . Parts ;
@@ -440,9 +440,20 @@ private static (WPos Center, float HalfWidth, float HalfHeight, float Radius, Re
440
440
var maxDistZ = Math . Max ( Math . Abs ( maxZ - centerZ ) , Math . Abs ( minZ - centerZ ) ) ;
441
441
var halfWidth = ( maxX - minX ) * 0.5f ;
442
442
var halfHeight = ( maxZ - minZ ) * 0.5f ;
443
+ var dir = center . ToWDir ( ) ;
444
+
445
+ for ( var i = 0 ; i < countCombined ; ++ i )
446
+ {
447
+ var verts = CollectionsMarshal . AsSpan ( combined [ i ] . Vertices ) ;
448
+ var len = verts . Length ;
449
+ for ( var j = 0 ; j < len ; ++ j )
450
+ {
451
+ ref var vert = ref verts [ j ] ;
452
+ vert -= dir ;
453
+ }
454
+ }
443
455
444
- var combinedPolyCentered = CombinePolygons ( ParseShapes ( unionShapes , center ) , ParseShapes ( differenceShapes , center ) , ParseShapes ( additionalShapes , center ) ) ;
445
- return ( center , halfWidth , halfHeight , Math . Max ( maxDistX , maxDistZ ) , combinedPolyCentered ) ;
456
+ return ( center , halfWidth , halfHeight , Math . Max ( maxDistX , maxDistZ ) , combinedPoly ) ;
446
457
}
447
458
448
459
private static RelSimplifiedComplexPolygon CombinePolygons ( RelSimplifiedComplexPolygon [ ] unionPolygons , RelSimplifiedComplexPolygon [ ] differencePolygons , RelSimplifiedComplexPolygon [ ] secondUnionPolygons )
@@ -469,13 +480,13 @@ private static RelSimplifiedComplexPolygon CombinePolygons(RelSimplifiedComplexP
469
480
return combinedShape ;
470
481
}
471
482
472
- private static RelSimplifiedComplexPolygon [ ] ParseShapes ( Shape [ ] shapes , WPos center = default )
483
+ private static RelSimplifiedComplexPolygon [ ] ParseShapes ( Shape [ ] shapes )
473
484
{
474
485
var lenght = shapes . Length ;
475
486
var polygons = new RelSimplifiedComplexPolygon [ lenght ] ;
476
487
for ( var i = 0 ; i < lenght ; ++ i )
477
488
{
478
- polygons [ i ] = shapes [ i ] . ToPolygon ( center ) ;
489
+ polygons [ i ] = shapes [ i ] . ToPolygon ( default ) ;
479
490
}
480
491
return polygons ;
481
492
}
0 commit comments