Example #1
0
 /// <summary>
 /// Creates a new Arc
 /// </summary>
 /// <param name="radius">The radius of the arc</param>
 /// <param name="bowLen">The lenght of the arc bow</param>
 /// <param name="baseVector">The base vector of the arc start</param>
 public Arc(double? radius,  double? bowLen, Vector2 baseVector)
 {
     _angle = null;
     _radius = radius;
     _bowlen = bowLen;
     _base = baseVector;
 }
Example #2
0
 /// <summary>
 /// Creates a new Arc
 /// </summary>
 /// <param name="radius">The radius of the arc</param>
 /// <param name="bowLen">The lenght of the arc bow</param>
 /// <param name="baseVector">The base vector of the arc start</param>
 public Arc(double?radius, double?bowLen, Vector2 baseVector)
 {
     _angle  = null;
     _radius = radius;
     _bowlen = bowLen;
     _base   = baseVector;
 }
Example #3
0
 private static RenderOptions GeostationaryOptions(Angle?longitude = null, Angle?endLongitude = null)
 {
     return(new()
     {
         GeostationaryRender = new GeostationaryRenderOptions(longitude, endLongitude, false, 1.0f, 0.9f)
     });
 }
Example #4
0
    protected override void UpdateState(RadarConsoleComponent component)
    {
        var xform  = Transform(component.Owner);
        var onGrid = xform.ParentUid == xform.GridUid;
        EntityCoordinates?coordinates = onGrid ? xform.Coordinates : null;
        Angle?            angle       = onGrid ? xform.LocalRotation : null;

        // Use ourself I guess.
        if (TryComp <IntrinsicUIComponent>(component.Owner, out var intrinsic))
        {
            foreach (var uiKey in intrinsic.UIs)
            {
                if (uiKey.Key?.Equals(RadarConsoleUiKey.Key) == true)
                {
                    coordinates = new EntityCoordinates(component.Owner, Vector2.Zero);
                    angle       = Angle.Zero;
                    break;
                }
            }
        }

        var radarState = new RadarConsoleBoundInterfaceState(
            component.MaxRange,
            coordinates,
            angle,
            new List <DockingInterfaceState>());

        _uiSystem.GetUiOrNull(component.Owner, RadarConsoleUiKey.Key)?.SetState(radarState);
    }
Example #5
0
 /// <summary>
 /// Creates a new Arc
 /// </summary>
 /// <param name="radius">The radius of the arc</param>
 /// <param name="angle">The arc angle</param>
 /// <param name="baseVector">A vector of the arc start</param>
 public Arc(double? radius, Angle? angle, Vector2 baseVector)
 {
     _angle = angle;
     _radius = radius;
     _base = baseVector;
     _bowlen = null;
 }
Example #6
0
 /// <summary>
 /// Creates a new Arc
 /// </summary>
 /// <param name="radius">The radius of the arc</param>
 /// <param name="angle">The arc angle</param>
 /// <param name="baseVector">A vector of the arc start</param>
 public Arc(double?radius, Angle?angle, Vector2 baseVector)
 {
     _angle  = angle;
     _radius = radius;
     _base   = baseVector;
     _bowlen = null;
 }
Example #7
0
 /// <summary>
 /// Constructs a new MDA sentence
 /// </summary>
 public WindDirectionWithRespectToNorth(Angle?trueWindDirection, Angle?magneticWindDirection, Speed?windSpeed)
     : base(OwnTalkerId, Id, DateTimeOffset.UtcNow)
 {
     TrueWindDirection     = trueWindDirection;
     MagneticWindDirection = magneticWindDirection;
     WindSpeed             = windSpeed;
     Valid = true;
 }
Example #8
0
 /// <summary>
 /// Constructs a new HDG sentence
 /// </summary>
 public HeadingAndDeclination(Angle headingTrue, Angle?deviation, Angle?variation)
     : base(OwnTalkerId, Id, DateTimeOffset.UtcNow)
 {
     HeadingTrue = headingTrue;
     Deviation   = deviation;
     Declination = variation;
     Valid       = true;
 }
Example #9
0
 /// <summary>
 /// Constructs a new VTG sentence
 /// </summary>
 public TrackMadeGood(Angle courseOverGroundTrue, Angle?courseOverGroundMagnetic, Speed speed)
     : base(OwnTalkerId, Id, DateTimeOffset.UtcNow)
 {
     CourseOverGroundTrue     = courseOverGroundTrue;
     CourseOverGroundMagnetic = courseOverGroundMagnetic;
     Speed = speed;
     Valid = true;
 }
Example #10
0
 public ShuttleConsoleBoundInterfaceState(
     ShuttleMode mode,
     float maxRange,
     EntityCoordinates?coordinates,
     Angle?angle,
     List <DockingInterfaceState> docks) : base(maxRange, coordinates, angle, docks)
 {
     Mode = mode;
 }
Example #11
0
        /// <summary>
        /// Creates a regular polygon centered at the origin in the XY-plane.
        /// </summary>
        public static Polygon RegularPolygon(int numberOfSides, Distance sideLength, Angle?startingAngle = null, Point centerPoint = null)
        {
            if (numberOfSides < 3)
            {
                throw new ArgumentException("A polygon must have at least 3 sides.");
            }

            Angle step       = (360.0 / numberOfSides) * Unit.Degrees;
            Angle otherAngle = (Unit.StraightAngle - step) / 2;

            //Law of Sines
            Distance length = sideLength * Unit.Sine(otherAngle) / Unit.Sine(step);

            Point firstPoint;

            if (startingAngle == null)
            {   // We want the polygon to be centered at the origin,
                // and lie "flat" from the viewers perspective
                if (numberOfSides % 4 == 0)
                {
                    firstPoint = new Point(length, Unit.ZeroDistance);
                    firstPoint = firstPoint.Rotate2D(step / 2);
                }
                else if (numberOfSides % 2 == 0)
                {
                    firstPoint = new Point(length, Unit.ZeroDistance);
                }
                else
                {
                    firstPoint = new Point(Unit.ZeroDistance, length);
                }
            }
            else
            {
                firstPoint = new Point(length, Unit.ZeroDistance);
                firstPoint = firstPoint.Rotate2D(startingAngle.Value);
            }
            List <Point> points = new List <Point>()
            {
                firstPoint
            };

            for (int i = 1; i < numberOfSides; i++)
            {
                points.Add(firstPoint.Rotate2D(step * i));
            }
            if (centerPoint == null)
            {
                return(new Polygon(points, ValidateOption.Dont));
            }
            else
            {
                return(new Polygon(points.Select(p => centerPoint + p.VectorFromOrigin).ToList(), ValidateOption.Dont));
            }
        }
Example #12
0
 /// <summary>
 /// Creates a new route point.
 /// </summary>
 /// <param name="routeName">Name of the route</param>
 /// <param name="indexInRoute">The index of this point</param>
 /// <param name="totalPointsInRoute">The total number of points on this route</param>
 /// <param name="waypointName">The name of this waypoint</param>
 /// <param name="position">The position of the waypoint</param>
 /// <param name="bearingToNextWaypoint">The direction to the next waypoint (optional, will be calculated when the route is constructed)</param>
 /// <param name="distanceToNextWaypoint">The distance to the next waypoint (optional, will be calculated when the route is constructed)</param>
 /// <remarks>
 /// Route and point names should use ASCII characters only. Some devices may understand the extended ASCII code page (values > 127),
 /// but this is rare. Most devices will silently truncate any names longer than 10 chars.
 /// </remarks>
 public RoutePoint(string routeName, int indexInRoute, int totalPointsInRoute, string waypointName, GeographicPosition position,
                   Angle?bearingToNextWaypoint, Length?distanceToNextWaypoint)
 {
     RouteName              = routeName;
     IndexInRoute           = indexInRoute;
     TotalPointsInRoute     = totalPointsInRoute;
     WaypointName           = waypointName;
     Position               = position;
     BearingToNextWaypoint  = bearingToNextWaypoint;
     DistanceToNextWaypoint = distanceToNextWaypoint;
 }
Example #13
0
 public RadarConsoleBoundInterfaceState(
     float maxRange,
     EntityCoordinates?coordinates,
     Angle?angle,
     List <DockingInterfaceState> docks)
 {
     MaxRange    = maxRange;
     Coordinates = coordinates;
     Angle       = angle;
     Docks       = docks;
 }
            public void NullAngle_ShouldReturnNull()
            {
                // arrange
                Angle?angle = null;

                // act
                var result = -angle;

                // assert
                result.Should().BeNull();
            }
            public void DivideByNull_ShouldThrow()
            {
                // arrange
                var   angle       = CreateAngleInUnitOtherThan(AngleUnit.Turn);
                Angle?denominator = null;

                // act
                Func <number> divideByZero = () => angle / denominator;

                // assert
                divideByZero.Should().Throw <DivideByZeroException>();
            }
Example #16
0
        private void Move(Angle direction1, float speed1, Angle?direction2, float?speed2)
        {
            Moving1.Direction = direction1;
            Moving1.Speed     = speed1;

            if (direction2.HasValue)
            {
                Moving2.Direction = direction2.Value;
            }
            if (speed2.HasValue)
            {
                Moving2.Speed = speed2.Value;
            }

            Vector3 pos1 = Item1.Position;
            Vector3 pos2 = (direction2 != null ? Item2.Position : Vector3.Zero);
            Vector3 pos3 = Item3.Position;

            bool    second   = direction2.HasValue;
            Vector3 velocity = Vector3.Zero;
            float   strenght = 0;

            velocity += Vector3.FromAngleXY(Moving1.Direction) * Math.Min(Moving1.Speed, Moving1.MaximumSpeed);
            strenght += Carrier1.CarrierStrength;
            velocity += Vector3.FromAngleXY(Moving3.Direction) * Math.Min(Moving3.Speed, Moving3.MaximumSpeed);
            if (direction2 != null)
            {
                velocity += Vector3.FromAngleXY(Moving2.Direction) * Math.Min(Moving2.Speed, Moving2.MaximumSpeed);
                strenght += Carrier2.CarrierStrength;
            }

            // Neue Positionen berechnen
            float factor = Portable3.PortableWeight > 0 ? strenght / Portable3.PortableWeight : 1f;

            factor = Math.Min(1f, Math.Max(0f, factor));

            velocity = (velocity / (second ? 3 : 2)) * factor;
            pos1    += velocity;
            pos2    += velocity;
            pos3    += velocity;

            Engine.Update();

            Assert.AreEqual(pos1.X, Item1.Position.X, 0.001f);
            Assert.AreEqual(pos1.Y, Item1.Position.Y, 0.001f);
            if (direction2 != null)
            {
                Assert.AreEqual(pos2.X, Item2.Position.X, 0.001f);
                Assert.AreEqual(pos2.Y, Item2.Position.Y, 0.001f);
            }
            Assert.AreEqual(pos3.X, Item3.Position.X, 0.001f);
            Assert.AreEqual(pos3.Y, Item3.Position.Y, 0.001f);
        }
            public void NullAngles_ShouldReturnNull()
            {
                // arrange
                Angle?nullAngle1 = null;
                Angle?nullAngle2 = null;

                // act
                var result = nullAngle1 - nullAngle2;

                // assert
                result.Should().BeNull();
            }
 public GeostationaryRenderOptions(
     Angle?longitude,
     Angle?endLongitude,
     bool inverseRotation,
     float hazeAmount,
     float hazeOpacity)
 {
     InverseRotation = inverseRotation;
     Longitude       = longitude?.Radians;
     EndLongitude    = endLongitude?.Radians;
     HazeAmount      = hazeAmount;
     HazeOpacity     = hazeOpacity;
 }
            public void NullAngle_ShouldTreatNullAsDefault()
            {
                // arrange
                Angle? nullAngle      = null;
                number factor         = Fixture.Create <number>();
                var    expectedResult = default(Angle) * factor;

                // act
                var result = nullAngle * factor;

                // assert
                result.Should().NotBeNull();
                result.Value.Should().Be(expectedResult);
            }
            public void NullAngle_ShouldTreatNullAsDefault()
            {
                // arrange
                Angle? nullAngle      = null;
                number denominator    = Fixture.CreateNonZeroNumber();
                var    expectedResult = default(Angle) % denominator;

                // act
                var result = nullAngle * denominator;

                // assert
                result.Should().NotBeNull();
                result.Value.Should().Be(expectedResult);
            }
Example #21
0
 /// <summary>
 /// See <see cref="NmeaSentence"/> for constructor usage
 /// </summary>
 public RecommendedMinimumNavigationInformation(
     DateTimeOffset dateTime,
     NavigationStatus?status,
     GeographicPosition position,
     Speed speedOverGround,
     Angle trackMadeGoodInDegreesTrue,
     Angle?magneticVariationInDegrees)
     : base(OwnTalkerId, Id, dateTime)
 {
     Status                     = status;
     Position                   = position;
     SpeedOverGround            = speedOverGround;
     TrackMadeGoodInDegreesTrue = trackMadeGoodInDegreesTrue;
     MagneticVariationInDegrees = magneticVariationInDegrees;
     Valid = true;
 }
Example #22
0
        public void Prototype(IGeometry iprototype)
        {
            var prototype = (iprototype as Arc);

            if (prototype == null)
            {
                throw new InvalidOperationException();
            }

            _angle  = prototype.Angle;
            _radius = prototype.Radius;
            _bowlen = prototype.BowLen;
            _base   = prototype.BaseVector;

            Location  = prototype.Location;
            Direction = prototype.Direction;
        }
Example #23
0
    public Box2Rotated GetWorldBounds(TileRef tileRef, Matrix3?worldMatrix = null, Angle?angle = null)
    {
        var grid = _mapManager.GetGrid(tileRef.GridIndex);

        if (worldMatrix == null || angle == null)
        {
            var gridXform = EntityManager.GetComponent <TransformComponent>(grid.GridEntityId);
            var(_, wAng, wMat) = gridXform.GetWorldPositionRotationMatrix();
            worldMatrix        = wMat;
            angle = wAng;
        }

        var center        = worldMatrix.Value.Transform((Vector2)tileRef.GridIndices + 0.5f) * grid.TileSize;
        var translatedBox = Box2.CenteredAround(center, (grid.TileSize, grid.TileSize));

        return(new Box2Rotated(translatedBox, -angle.Value, center));
    }
Example #24
0
        /// <summary>
        /// Returns the range with the maximum value in a sequence of nullable Angle values.
        /// </summary>
        /// <param name="source">A sequence of Angle values to determine the maximum value of.</param>
        /// <returns>The maximum value in the sequence.</returns>
        /// <remarks>If the source sequence is empty or contains only values that are null, this function returns null.</remarks>
        public static (Angle Min, Angle Max)? Range(this IEnumerable <Angle?> source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            using (var enumerator = source.GetEnumerator())
            {
                Angle?current = null;
                do
                {
                    if (!enumerator.MoveNext())
                    {
                        return(null); // sequence is empty
                    }
                    current = enumerator.Current;
                }while (!current.HasValue);

                var min = current.GetValueOrDefault();
                var max = min;
                while (enumerator.MoveNext())
                {
                    current = enumerator.Current;

                    // Do not replace & with &&. The branch prediction cost outweighs the extra operation
                    // unless nulls either never happen or always happen.
                    if (current.HasValue)
                    {
                        var currentValue = current.GetValueOrDefault();
                        if (currentValue < min)
                        {
                            min = currentValue;
                        }
                        if (currentValue > max)
                        {
                            max = currentValue;
                        }
                    }
                }

                return(min, max);
            }
        }
            public void NullAndAngle_ShouldTreatNullAsDefault()
            {
                // arrange
                Angle?nullAngle = null;
                var   angle     = CreateAngleInUnitOtherThan(AngleUnit.Turn);

                // act
                var result1 = angle - nullAngle;
                var result2 = nullAngle - angle;

                // assert
                result1.Should().NotBeNull();
                result1.Value.Turns.Should().Be(angle.Turns);
                result1.Value.Unit.Should().Be(angle.Unit);

                result2.Should().NotBeNull();
                result2.Value.Turns.Should().Be(-angle.Turns);
                result2.Value.Unit.Should().Be(angle.Unit);
            }
            public void MultipleSerialConversion_ShouldHaveSameValueAtTheEnd(number value)
            {
                // arrange
                var units = new List <AngleUnit>
                {
                    AngleUnit.Turn,
                    AngleUnit.Radian,
                    AngleUnit.Degree,
                    AngleUnit.Gradian,
                    AngleUnit.Turn
                };
                var   initialAngle = new Angle(value, units.First());
                Angle?finalAngle   = null;

                // act
                units.ForEach(u => finalAngle = (finalAngle ?? initialAngle).Convert(u));

                // assert
                finalAngle.Should().Be(initialAngle);
            }
Example #27
0
        public void Prototype(IGeometry iprototype)
        {

            var prototype = (iprototype as Arc);
            if (prototype == null)
                throw new InvalidOperationException();

            _angle = prototype.Angle;
            _radius = prototype.Radius;
            _bowlen = prototype.BowLen;
            _base = prototype.BaseVector;

            Location = prototype.Location;
            Direction = prototype.Direction;
        }
 /// <summary>
 /// Creates a new Rectangle
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="rotation"></param>
 public Rectangle2(double x, double y, double width, double height, Angle?rotation = null)
     : this(BuildEdges(x, y, width, height, rotation))
 {
 }
        /// <summary>
        /// Builds the edges of a rectangle from a location and width/height.
        /// Optionally, you can specify the rotation angle to the X-Axsis
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="rotation"></param>
        /// <returns></returns>
        public static Vector2[] BuildEdges(double x, double y, double width, double height, Angle?rotation = null)
        {
            var topLeft     = new Vector2(x, y);
            var topRight    = new Vector2(x + width, y);
            var bottomRight = new Vector2(x + width, y + height);
            var bottomLeft  = new Vector2(x, y + height);

            var vertices = new Vertices(new[] { topLeft, topRight, bottomRight, bottomLeft });

            // Rotate if necessary
            if (rotation.HasValue && rotation.Value != Angle.Zero)
            {
                vertices = vertices.RotateVertices(topLeft, rotation.Value);
            }
            return(vertices.ToArray());
        }
 public Rectangle2(Vector2 location, SizeD size, Angle?rotation = null)
     : this(location.X, location.Y, size.Width, size.Height, rotation ?? Angle.Zero)
 {
 }
    public override void FrameUpdate(float frameTime)
    {
        if (!_gameTiming.IsFirstTimePredicted)
            return;

        var currentEye = _eyeManager.CurrentEye;

        if (_playerManager.LocalPlayer?.ControlledEntity is not {} mob || Deleted(mob))
            return;

        // We can't lerp if the mob can't move!
        if (!TryComp(mob, out IMoverComponent? mover))
            return;

        var moverLastGridAngle = mover.LastGridAngle;

        // Let's not turn the camera into a washing machine when the game starts.
        if (_lastGridAngle == null)
        {
            _lastGridAngle = moverLastGridAngle;
            currentEye.Rotation = -moverLastGridAngle;
            return;
        }

        // Check if the last lerp grid angle we have is not the same as the last mover grid angle...
        if (!_lastGridAngle.Value.EqualsApprox(moverLastGridAngle))
        {
            // And now, we start lerping.
            _lerpTo = moverLastGridAngle;
            _lastGridAngle = moverLastGridAngle;
            _lerpStartRotation = currentEye.Rotation;
            _accumulator = 0f;
        }

        if (_lerpTo != null)
        {
            _accumulator += frameTime;

            var lerpRot = -_lerpTo.Value.FlipPositive().Reduced();
            var startRot = _lerpStartRotation.FlipPositive().Reduced();

            var changeNeeded = Angle.ShortestDistance(startRot, lerpRot);

            if (changeNeeded.EqualsApprox(Angle.Zero))
            {
                // Nothing to do here!
                CleanupLerp();
                return;
            }

            // Get how much the camera should have moved by now. Make it faster depending on the change needed.
            var changeRot = (CameraRotateSpeed * Math.Max(1f, Math.Abs(changeNeeded) * 0.75f)) * _accumulator * Math.Sign(changeNeeded);

            // How close is this from reaching the end?
            var percentage = (float)Math.Abs(changeRot / changeNeeded);

            currentEye.Rotation = Angle.Lerp(startRot, lerpRot, percentage);

            // Either we have overshot, or we have taken way too long on this, emergency reset time
            if (percentage >= 1.0f || _accumulator >= LerpTimeMax)
            {
                CleanupLerp();
            }

            void CleanupLerp()
            {
                currentEye.Rotation = -_lerpTo.Value;
                _lerpStartRotation = currentEye.Rotation;
                _lerpTo = null;
                _accumulator = 0f;
            }
        }
        else
        {
            // This makes it so rotating the camera manually is impossible...
            // However, it is needed. Why? Because of a funny (hilarious, even) race condition involving
            // ghosting, this system listening for attached mob changes, and the eye rotation being reset after our
            // changes back to zero because of an EyeComponent state coming from the server being applied.
            // At some point we'll need to come up with a solution for that. But for now, I just want to fix this.
            currentEye.Rotation = -moverLastGridAngle;
        }
    }
 public Rectangle2(AARectangle rect, Angle?rotation = null)
     : this(rect.Location, rect.Size, rotation ?? Angle.Zero)
 {
 }
Example #33
0
 public Box2 GetWorldAABB(Vector2?worldPos = null, Angle?worldRot = null)
 {
     return(Icon.GetWorldAABB(worldPos));
 }