public void HashCodeNotEqualsTest() { var coordinates = new Coordinates2(1, 2); var coordinates2 = new Coordinates2(2, 3); Assert.NotEqual(coordinates.GetHashCode(), coordinates2.GetHashCode()); }
public void OperatorNotEqualsTest() { var coordinates = new Coordinates2(1, 2); var coordinates2 = new Coordinates2(2, 3); Assert.True(coordinates != coordinates2); }
public void EqualsTest() { var coordinates = new Coordinates2(1, 2); var coordinates2 = new Coordinates2(1, 2); Assert.True(coordinates.Equals((object)coordinates2)); }
/// <summary> /// Reads and converts the JSON to type <see cref="Rectangle"/>. /// </summary> /// <param name="reader">The reader.</param> /// <param name="options">An object that specifies serialization options to use.</param> /// <param name="directionType">The rectangle direction type.</param> /// <returns>The converted value.</returns> protected static Rectangle Read(ref Utf8JsonReader reader, JsonSerializerOptions options, RectangleDirectionType directionType) { if (reader.TokenType != JsonTokenType.StartArray) { throw new JsonException("Expected start of array"); } var values = new Coordinates2[2]; for (int i = 0; i < 2; i++) { if (!reader.Read()) { throw new JsonException("Unexpected end of array"); } values[i] = JsonSerializer.Deserialize <Coordinates2>(ref reader, options); } if (!reader.Read() || reader.TokenType != JsonTokenType.EndArray) { throw new JsonException("Expected end of array"); } return(new Rectangle(values[0], values[1], directionType)); }
public void ConstructorTest() { var coordinates = new Coordinates2(4, 2); Assert.Equal(4, coordinates.X); Assert.Equal(2, coordinates.Y); Assert.Equal(new[] { 4d, 2d }, coordinates); }
public void NotEqualsTest() { var coordinates = new Coordinates2(1, 2); var coordinates2 = new Coordinates2(2, 3); Assert.False(coordinates.Equals(coordinates2)); Assert.False(coordinates.Equals(null)); }
/// <summary> /// Initializes a new instance of the <see cref="Rectangle"/> struct. /// </summary> /// <param name="coords1">The first coordinates.</param> /// <param name="coords2">The second coordinates.</param> /// <param name="directionType">The rectangle direction type.</param> public Rectangle(Coordinates2 coords1, Coordinates2 coords2, RectangleDirectionType directionType) { this.Direction = directionType; if (directionType == RectangleDirectionType.BottomUp) { this.TopLeft = new Coordinates2(coords1.X, coords2.Y); this.TopRight = coords2; this.BottomLeft = coords1; this.BottomRight = new Coordinates2(coords2.X, coords1.Y); } else // TopDown { this.TopLeft = coords1; this.TopRight = new Coordinates2(coords2.X, coords1.Y); this.BottomLeft = new Coordinates2(coords1.X, coords2.Y); this.BottomRight = coords2; } }
private void MumbleLoop() { do { bool shouldRun = true; this.client.Mumble.Update(); if (!this.client.Mumble.IsAvailable) { shouldRun = false; } int mapId = this.client.Mumble.MapId; if (mapId == 0) { shouldRun = false; } if (shouldRun) { if (!this.maps.ContainsKey(mapId) && !this.apiMapDownloadBusy.Contains(mapId)) { this.apiMapDownloadBusy.Add(mapId); this.apiMapDownloadQueue.Enqueue(mapId); this.apiMapDownloadEvent.Set(); } try { this.Invoke(new Action <IGw2MumbleClient>(m => { this.textBoxVersion.Text = m.Version.ToString(); this.textBoxTick.Text = m.Tick.ToString(); this.textBoxAvatarPosition1.Text = m.AvatarPosition.X.ToString(); this.textBoxAvatarPosition2.Text = m.AvatarPosition.Y.ToString(); this.textBoxAvatarPosition3.Text = m.AvatarPosition.Z.ToString(); this.textBoxAvatarFront1.Text = m.AvatarFront.X.ToString(); this.textBoxAvatarFront2.Text = m.AvatarFront.Y.ToString(); this.textBoxAvatarFront3.Text = m.AvatarFront.Z.ToString(); this.textBoxName.Text = m.Name; this.textBoxCameraPosition1.Text = m.CameraPosition.X.ToString(); this.textBoxCameraPosition2.Text = m.CameraPosition.Y.ToString(); this.textBoxCameraPosition3.Text = m.CameraPosition.Z.ToString(); this.textBoxCameraFront1.Text = m.CameraFront.X.ToString(); this.textBoxCameraFront2.Text = m.CameraFront.Y.ToString(); this.textBoxCameraFront3.Text = m.CameraFront.Z.ToString(); this.textBoxRawIdentity.Text = m.RawIdentity; this.textBoxCharacterName.Text = m.CharacterName; this.textBoxRace.Text = m.Race.ToString(); this.textBoxSpecialization.Text = m.Specialization.ToString(); this.textBoxTeamColorId.Text = m.TeamColorId.ToString(); this.checkBoxCommander.Checked = m.IsCommander; this.textBoxFieldOfView.Text = m.FieldOfView.ToString(); this.textBoxUiSize.Text = m.UiSize.ToString(); this.textBoxServerAddress.Text = $"{m.ServerAddress}:{m.ServerPort}"; this.textBoxMapId.Text = m.MapId.ToString(); this.textBoxMapType.Text = m.MapType.ToString(); this.textBoxShardId.Text = m.ShardId.ToString(); this.textBoxInstance.Text = m.Instance.ToString(); this.textBoxBuildId.Text = m.BuildId.ToString(); this.checkBoxUiStateMapOpen.Checked = m.IsMapOpen; this.checkBoxUiStateCompassTopRight.Checked = m.IsCompassTopRight; this.checkBoxUiStateCompassRotationEnabled.Checked = m.IsCompassRotationEnabled; this.checkBoxUiStateGameFocus.Checked = m.DoesGameHaveFocus; this.checkBoxUiStateCompetitive.Checked = m.IsCompetitiveMode; this.checkBoxUiStateInputFocus.Checked = m.DoesAnyInputHaveFocus; this.checkBoxUiStateInCombat.Checked = m.IsInCombat; this.textBoxCompassWidth.Text = m.Compass.Width.ToString(); this.textBoxCompassHeight.Text = m.Compass.Height.ToString(); this.textBoxCompassRotation.Text = m.CompassRotation.ToString(); this.textBoxPlayerCoordsX.Text = m.PlayerLocationMap.X.ToString(); this.textBoxPlayerCoordsY.Text = m.PlayerLocationMap.Y.ToString(); this.textBoxMapCenterX.Text = m.MapCenter.X.ToString(); this.textBoxMapCenterY.Text = m.MapCenter.Y.ToString(); this.textBoxMapScale.Text = m.MapScale.ToString(); this.textBoxProcessId.Text = m.ProcessId.ToString(); this.textBoxMount.Text = m.Mount.ToString(); if (this.maps.TryGetValue(m.MapId, out var map)) { this.textBoxMapName.Text = map.Name; var mapPosition = m.AvatarPosition.ToMapCoords(CoordsUnit.Mumble); this.textBoxMapPosition1.Text = mapPosition.X.ToString(); this.textBoxMapPosition2.Text = mapPosition.Y.ToString(); this.textBoxMapPosition3.Text = mapPosition.Z.ToString(); var continentPosition = m.AvatarPosition.ToContinentCoords(CoordsUnit.Mumble, map.MapRect, map.ContinentRect); this.textBoxContinentPosition1.Text = continentPosition.X.ToString(); this.textBoxContinentPosition2.Text = continentPosition.Y.ToString(); this.textBoxContinentPosition3.Text = continentPosition.Z.ToString(); ContinentFloorRegionMapPoi?closestWaypoint = null; Coordinates2 closestWaypointPosition = default; double closestWaypointDistance = double.MaxValue; ContinentFloorRegionMapPoi?closestPoi = null; Coordinates2 closestPoiPosition = default; double closestPoiDistance = double.MaxValue; foreach (int floorId in map.Floors) { if (this.floors.TryGetValue(floorId, out var floor)) { if (floor.Regions.TryGetValue(map.RegionId, out var floorRegion)) { if (floorRegion.Maps.TryGetValue(map.Id, out var floorMap)) { foreach (var poi in floorMap.PointsOfInterest) { double distanceX = Math.Abs(continentPosition.X - poi.Value.Coord.X); double distanceZ = Math.Abs(continentPosition.Z - poi.Value.Coord.Y); double distance = Math.Sqrt(Math.Pow(distanceX, 2) + Math.Pow(distanceZ, 2)); if (poi.Value.Type.Value == PoiType.Waypoint && distance < closestWaypointDistance) { closestWaypointPosition = poi.Value.Coord; closestWaypointDistance = distance; closestWaypoint = poi.Value; } else if (poi.Value.Type.Value == PoiType.Landmark && distance < closestPoiDistance) { closestPoiPosition = poi.Value.Coord; closestPoiDistance = distance; closestPoi = poi.Value; } } } } } } if (closestWaypoint != null) { this.textBoxWaypoint.Text = closestWaypoint.Name; int poiId = closestWaypoint.Id; this.textBoxWaypointLink.Text = closestWaypoint.ChatLink; this.textBoxWaypointContinentDistance.Text = closestWaypointDistance.ToString(); this.textBoxWaypointContinentPosition1.Text = closestWaypoint.Coord.X.ToString(); this.textBoxWaypointContinentPosition2.Text = closestWaypoint.Coord.Y.ToString(); double angle = Math.Atan2(continentPosition.Z - closestWaypointPosition.Y, continentPosition.X - closestWaypointPosition.X) * 180 / Math.PI; this.textBoxWaypointDirection1.Text = this.GetDirectionFromAngle(angle).ToString(); this.textBoxWaypointDirection2.Text = angle.ToString(); } else { this.textBoxWaypoint.Text = string.Empty; this.textBoxWaypointLink.Text = string.Empty; this.textBoxWaypointContinentDistance.Text = string.Empty; this.textBoxWaypointContinentPosition1.Text = string.Empty; this.textBoxWaypointContinentPosition2.Text = string.Empty; this.textBoxWaypointDirection1.Text = string.Empty; this.textBoxWaypointDirection2.Text = string.Empty; } if (closestPoi != null) { this.textBoxPoi.Text = closestPoi.Name; int poiId = closestPoi.Id; this.textBoxPoiLink.Text = closestPoi.ChatLink; this.textBoxPoiContinentDistance.Text = closestPoiDistance.ToString(); this.textBoxPoiContinentPosition1.Text = closestPoi.Coord.X.ToString(); this.textBoxPoiContinentPosition2.Text = closestPoi.Coord.Y.ToString(); double angle = Math.Atan2(continentPosition.Z - closestPoiPosition.Y, continentPosition.X - closestPoiPosition.X) * 180 / Math.PI; this.textBoxPoiDirection1.Text = this.GetDirectionFromAngle(angle).ToString(); this.textBoxPoiDirection2.Text = angle.ToString(); } else { this.textBoxPoi.Text = string.Empty; this.textBoxPoiLink.Text = string.Empty; this.textBoxPoiContinentDistance.Text = string.Empty; this.textBoxPoiContinentPosition1.Text = string.Empty; this.textBoxPoiContinentPosition2.Text = string.Empty; this.textBoxPoiDirection1.Text = string.Empty; this.textBoxPoiDirection2.Text = string.Empty; } } }), this.client.Mumble); } catch (ObjectDisposedException) { // The application is likely closing break; } } Thread.Sleep(1000 / 60); } while (!this.stopRequested); }
public void ToStringTest() { var coordinates = new Coordinates2(5, 10); Assert.Equal("(5,10)", coordinates.ToString()); }