public void VectorXEqualsVactorX() { var vectorX = new Vector2(1.0, 1.0); Assert.IsTrue(vectorX == vectorX); Assert.IsTrue(vectorX.Equals(vectorX)); Assert.IsTrue(vectorX.Equals((object)vectorX)); }
public void Vector2_EqualsTestsCorrectly() { var vector1 = new Vector2(123.4f, 567.8f); var vector2 = new Vector2(123.4f, 567.8f); var vector3 = new Vector2(567.8f, 123.4f); TheResultingValue(vector1.Equals(vector2)).ShouldBe(true); TheResultingValue(vector1.Equals(vector3)).ShouldBe(false); }
public void VectorXNotEqualsVectorY() { var vectorX = new Vector2(1.0, 1.0); var vectorY = new Vector2(2.0, 2.0); Assert.IsFalse(vectorX == vectorY); Assert.IsTrue(vectorX != vectorY); Assert.IsFalse(vectorX.Equals(vectorY)); Assert.IsFalse(vectorX.Equals((object)vectorY)); }
public void VectorXEqualsVectorYEqualsVectorZTransitiveEquality() { var vectorX = new Vector2(1.0, 1.0); var vectorY = new Vector2(1.0, 1.0); var vectorZ = new Vector2(1.0, 1.0); Assert.IsTrue(vectorX.Equals(vectorY)); Assert.IsTrue(vectorY.Equals(vectorZ)); Assert.IsTrue(vectorX.Equals(vectorZ)); Assert.IsTrue(vectorX.Equals((object)vectorY)); Assert.IsTrue(vectorY.Equals((object)vectorZ)); Assert.IsTrue(vectorX.Equals((object)vectorZ)); }
public void NaNEquality() { Vector2 nanVec = new Vector2(float.NaN, float.NaN); Assert.IsFalse(nanVec == nanVec); Assert.IsTrue(nanVec != nanVec); Assert.IsTrue(nanVec.Equals(nanVec)); }
public void Test_Equals() { var a = new Vector2 (1, 2.00001f); var b = new Vector2 (1, 2.00002f); Assert.IsTrue (a.Equals (b)); // 誤差を許容する比較 Assert.IsFalse (a == b); // 厳密な比較 Assert.AreNotEqual (a.GetHashCode (), b.GetHashCode ()); // ハッシュは厳密な比較を基準 }
public UInt16 FindUV(Vector2 v) { UInt16 index = (UInt16)Geometry.UVs.FindIndex(delegate(Vector2 p) { return v.Equals(p); }); if (index >= 0) return index; Geometry.UVs.Add(v); return (UInt16)(Geometry.UVs.Count - 1); }
private static void OnDraw(EventArgs args) { if (_notifications.Count != 0) { var lastNotifPos = new Vector2(); var auxNotifications = new List<NotificationModel>(); foreach (var notificationModel in _notifications) { var diffTime = (notificationModel.StartTimer + notificationModel.AnimationTimer + notificationModel.ShowTimer) - Game.Time; var animationEnd = notificationModel.StartTimer + notificationModel.AnimationTimer - Game.Time; var diffPos = 0f; if (animationEnd > 0) { diffPos = 200 * animationEnd; } if (diffTime > 0) { if (lastNotifPos.Equals(new Vector2())) { var pos = new Vector2(Drawing.Width - 220, y: Drawing.Height / 13.5f - diffPos); MainBar.Draw(pos); lastNotifPos = pos; Text.TextValue = notificationModel.ShowText; var vector1 = new Vector2(Text.Bounding.Width, Text.Bounding.Height); var vector2 = new Vector2(Resources.notification.Size.Width, Resources.notification.Size.Height); pos += (vector2 - vector1) / 2; Text.Position = pos; Text.Color = notificationModel.Color; Text.Draw(); } else { var pos = new Vector2(lastNotifPos.X, y: lastNotifPos.Y + 70); MainBar.Draw(pos); lastNotifPos = pos; Text.TextValue = notificationModel.ShowText; var vector1 = new Vector2(Text.Bounding.Width, Text.Bounding.Height); var vector2 = new Vector2(Resources.notification.Size.Width, Resources.notification.Size.Height); pos += (vector2 - vector1) / 2; Text.Position = pos; Text.Color = notificationModel.Color; Text.Draw(); } } else { auxNotifications.Add(notificationModel); } } if (auxNotifications.Count > 0) { _notifications = _notifications.Except(auxNotifications).ToList(); } } else { Drawing.OnDraw -= OnDraw; } }
// Test Operator: Equality //-----------------------------------------// /// <summary> /// Helper method for testing equality. /// </summary> void TestEquality (Vector2 a, Vector2 b, Boolean expected ) { // This test asserts the following: // (a == b) == expected // (b == a) == expected // (a != b) == !expected // (b != a) == !expected Boolean result_1a = (a == b); Boolean result_1b = (a.Equals(b)); Boolean result_1c = (a.Equals((Object)b)); Boolean result_2a = (b == a); Boolean result_2b = (b.Equals(a)); Boolean result_2c = (b.Equals((Object)a)); Boolean result_3a = (a != b); Boolean result_4a = (b != a); Assert.That(result_1a, Is.EqualTo(expected)); Assert.That(result_1b, Is.EqualTo(expected)); Assert.That(result_1c, Is.EqualTo(expected)); Assert.That(result_2a, Is.EqualTo(expected)); Assert.That(result_2b, Is.EqualTo(expected)); Assert.That(result_2c, Is.EqualTo(expected)); Assert.That(result_3a, Is.EqualTo(!expected)); Assert.That(result_4a, Is.EqualTo(!expected)); }
private static bool HandlePlayerUpdate(GetDataHandlerArgs args) { var plr = args.Data.ReadInt8(); var control = args.Data.ReadInt8(); var item = args.Data.ReadInt8(); var pos = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); var vel = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); if (item < 0 || item >= args.TPlayer.inventory.Length) { return true; } if (!pos.Equals(args.Player.LastNetPosition)) { float distance = Vector2.Distance(new Vector2(pos.X / 16f, pos.Y / 16f), new Vector2(args.Player.LastNetPosition.X / 16f, args.Player.LastNetPosition.Y / 16f)); if (TShock.CheckIgnores(args.Player) && distance > TShock.Config.MaxRangeForDisabled) { if(args.Player.IgnoreActionsForCheating != "none") { args.Player.SendMessage("Disabled for cheating: " + args.Player.IgnoreActionsForCheating, Color.Red); } else if (args.Player.IgnoreActionsForDisabledArmor != "none") { args.Player.SendMessage("Disabled for banned armor: " + args.Player.IgnoreActionsForDisabledArmor, Color.Red); } else if (args.Player.IgnoreActionsForInventory != "none") { args.Player.SendMessage("Disabled for Server Side Inventory: " + args.Player.IgnoreActionsForInventory, Color.Red); } else if (TShock.Config.RequireLogin && !args.Player.IsLoggedIn) { args.Player.SendMessage("Please /register or /login to play!", Color.Red); } else if (args.Player.IgnoreActionsForClearingTrashCan) { args.Player.SendMessage("You need to rejoin to ensure your trash can is cleared!", Color.Red); } else if (args.Player.IgnoreActionsForPvP) { args.Player.SendMessage("PvP is forced! Enable PvP else you can't move or do anything!", Color.Red); } int lastTileX = (int)(args.Player.LastNetPosition.X / 16f); int lastTileY = (int)(args.Player.LastNetPosition.Y / 16f); if (!args.Player.Teleport(lastTileX, lastTileY + 3)) { args.Player.Spawn(); } return true; } if (args.Player.Dead) { return true; } if (!args.Player.Group.HasPermission(Permissions.ignorenoclipdetection) && Collision.SolidCollision(pos, args.TPlayer.width, args.TPlayer.height)) { int lastTileX = (int)(args.Player.LastNetPosition.X / 16f); int lastTileY = (int)(args.Player.LastNetPosition.Y / 16f); if (!args.Player.Teleport(lastTileX, lastTileY + 3)) { args.Player.SendMessage("You got stuck in a solid object, Sent to spawn point."); args.Player.Spawn(); } return true; } } args.Player.LastNetPosition = pos; if ((control & 32) == 32) { if (!args.Player.Group.HasPermission(Permissions.usebanneditem) && TShock.Itembans.ItemIsBanned(args.TPlayer.inventory[item].name, args.Player)) { control -= 32; args.Player.LastThreat = DateTime.UtcNow; args.Player.SendMessage(string.Format("You cannot use {0} on this server. Your actions are being ignored.", args.TPlayer.inventory[item].name), Color.Red); } } args.TPlayer.selectedItem = item; args.TPlayer.position = pos; args.TPlayer.velocity = vel; args.TPlayer.oldVelocity = args.TPlayer.velocity; args.TPlayer.fallStart = (int)(pos.Y / 16f); args.TPlayer.controlUp = false; args.TPlayer.controlDown = false; args.TPlayer.controlLeft = false; args.TPlayer.controlRight = false; args.TPlayer.controlJump = false; args.TPlayer.controlUseItem = false; args.TPlayer.direction = -1; if ((control & 1) == 1) { args.TPlayer.controlUp = true; } if ((control & 2) == 2) { args.TPlayer.controlDown = true; } if ((control & 4) == 4) { args.TPlayer.controlLeft = true; } if ((control & 8) == 8) { args.TPlayer.controlRight = true; } if ((control & 16) == 16) { args.TPlayer.controlJump = true; } if ((control & 32) == 32) { args.TPlayer.controlUseItem = true; } if ((control & 64) == 64) { args.TPlayer.direction = 1; } NetMessage.SendData((int)PacketTypes.PlayerUpdate, -1, args.Player.Index, "", args.Player.Index); return true; }
public void EqualsTest1() { Vector2 target = new Vector2(5f, 8.5f); object value = new Vector2(6f, 15.1f); bool expected = false; bool actual; actual = target.Equals(value); Utilities.AreEqual(expected, actual); target = new Vector2(7f, 3f); value = new Vector2(7f, 3f); expected = true; actual = target.Equals(value); Utilities.AreEqual(expected, actual); }
public void VectorXEqualsNull() { var vectorX = new Vector2(1.0, 1.0); Assert.IsFalse(vectorX.Equals(null)); }
/// <summary> /// Obtains a list of vertexes that represent the polyline approximating the curve segments as necessary. /// </summary> /// <param name="bulgePrecision">Curve segments precision (a value of zero means that no approximation will be made).</param> /// <param name="weldThreshold">Tolerance to consider if two new generated vertexes are equal.</param> /// <param name="bulgeThreshold">Minimum distance from which approximate curved segments of the polyline.</param> /// <returns>A list of vertexes expressed in object coordinate system.</returns> public IList<Vector2> PoligonalVertexes(int bulgePrecision, double weldThreshold, double bulgeThreshold) { List<Vector2> ocsVertexes = new List<Vector2>(); int index = 0; foreach (LwPolylineVertex vertex in this.Vertexes) { double bulge = vertex.Bulge; Vector2 p1; Vector2 p2; if (index == this.Vertexes.Count - 1) { p1 = new Vector2(vertex.Position.X, vertex.Position.Y); p2 = new Vector2(this.vertexes[0].Position.X, this.vertexes[0].Position.Y); } else { p1 = new Vector2(vertex.Position.X, vertex.Position.Y); p2 = new Vector2(this.vertexes[index + 1].Position.X, this.vertexes[index + 1].Position.Y); } if (!p1.Equals(p2, weldThreshold)) { if (MathHelper.IsZero(bulge) || bulgePrecision == 0) { ocsVertexes.Add(p1); } else { double c = Vector2.Distance(p1, p2); if (c >= bulgeThreshold) { double s = (c / 2) * Math.Abs(bulge); double r = ((c / 2) * (c / 2) + s * s) / (2 * s); double theta = 4 * Math.Atan(Math.Abs(bulge)); double gamma = (Math.PI - theta) / 2; double phi = Vector2.Angle(p1, p2) + Math.Sign(bulge) * gamma; Vector2 center = new Vector2(p1.X + r * Math.Cos(phi), p1.Y + r * Math.Sin(phi)); Vector2 a1 = p1 - center; double angle = Math.Sign(bulge) * theta / (bulgePrecision + 1); ocsVertexes.Add(p1); for (int i = 1; i <= bulgePrecision; i++) { Vector2 curvePoint = new Vector2(); Vector2 prevCurvePoint = new Vector2(this.vertexes[this.vertexes.Count - 1].Position.X, this.vertexes[this.vertexes.Count - 1].Position.Y); curvePoint.X = center.X + Math.Cos(i*angle)*a1.X - Math.Sin(i*angle)*a1.Y; curvePoint.Y = center.Y + Math.Sin(i*angle)*a1.X + Math.Cos(i*angle)*a1.Y; if (!curvePoint.Equals(prevCurvePoint, weldThreshold) && !curvePoint.Equals(p2, weldThreshold)) { ocsVertexes.Add(curvePoint); } } } else { ocsVertexes.Add(p1); } } } index++; } return ocsVertexes; }
private static void CheckOne(LensDistortionMapping correction, Vector2 distorted) { Vector2 corrected = correction.GetCorrected(distorted); Vector2 redistorted = correction.GetDistorted(corrected); Assert.IsTrue(distorted.Equals(redistorted, .05)); }
private void SetEllipseParameters(Ellipse ellipse, double[] param) { double a = ellipse.MajorAxis*0.5; double b = ellipse.MinorAxis*0.5; Vector2 startPoint = new Vector2(a * Math.Cos(param[0]), b * Math.Sin(param[0])); Vector2 endPoint = new Vector2(a * Math.Cos(param[1]), b * Math.Sin(param[1])); // trigonometry functions are very prone to round off errors if (startPoint.Equals(endPoint)) { ellipse.StartAngle = 0.0; ellipse.EndAngle = 360.0; } else { ellipse.StartAngle = Vector2.Angle(startPoint) * MathHelper.RadToDeg; ellipse.EndAngle = Vector2.Angle(endPoint) * MathHelper.RadToDeg; } }
private void ChangeCurrentSprite(Vector2 direction) { if (this.facingDirection.Equals(direction)) { return; } if (direction.Equals(new Vector2(-1, -1))) { this.CurrentSprite = this.LeftUpAnimation; } else if (direction.Equals(new Vector2(0, -1))) { this.CurrentSprite = this.CenterUpAnimation; } else if (direction.Equals(new Vector2(1, -1))) { this.CurrentSprite = this.RightUpAnimation; } else if (direction.Equals(new Vector2(-1, 0))) { this.CurrentSprite = this.LeftCenterAnimation; } else if (direction.Equals(new Vector2(1, 0))) { this.CurrentSprite = this.RightCenterAnimation; } else if (direction.Equals(new Vector2(-1, 1))) { this.CurrentSprite = this.LeftDownAnimation; } else if (direction.Equals(new Vector2(0, 1))) { this.CurrentSprite = this.CenterDownAnimation; } else if (direction.Equals(new Vector2(1, 1))) { this.CurrentSprite = this.RightDownAnimation; } }