Aetheria/Assets/Plugins/MSAGL/Routing/Visibility/ObstacleSideComparer.cs
Reinier Vens dbc522a224 Weapos Rejiggered
Modified weapon scripts to eliminate specialized projectile behavior - allows charged weapons to have projectiles and modify weapon stats when charged
Added machine gun weapon & VFX
Moved third party code to Plugins folder to improve compile times
2021-01-31 03:52:32 +00:00

49 lines
No EOL
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Msagl.Core.Geometry;
using Microsoft.Msagl.Core;
namespace Microsoft.Msagl.Routing.Visibility {
internal class ObstacleSideComparer : IComparer<SegmentBase> {
readonly LineSweeperBase lineSweeper;
internal ObstacleSideComparer(LineSweeperBase lineSweeper) {
this.lineSweeper = lineSweeper;
}
/// <summary>
/// the intersection of the sweepline and the active segment
/// </summary>
Point x;
public int Compare(SegmentBase a, SegmentBase b) {
ValidateArg.IsNotNull(b, "b");
var orient = Point.GetTriangleOrientation(b.Start, b.End, x);
switch (orient) {
case TriangleOrientation.Collinear:
return 0;
case TriangleOrientation.Clockwise:
return 1;
default:
return -1;
}
}
internal void SetOperand(SegmentBase side) {
x = IntersectionOfSideAndSweepLine(side);
}
internal Point IntersectionOfSideAndSweepLine(SegmentBase obstacleSide) {
var den = obstacleSide.Direction * lineSweeper.SweepDirection;
Debug.Assert(Math.Abs(den) > ApproximateComparer.DistanceEpsilon);
var t = (lineSweeper.Z - obstacleSide.Start * lineSweeper.SweepDirection) / den;
return obstacleSide.Start + t * obstacleSide.Direction;
}
}
}