} // BuyTile() private bool IsValidPurchase(Coordinate2 tileBeingPurchased, int playerId) { bool isValid = false; List <Coordinate2> validCards = new List <Coordinate2>(); if (this.round > graceRounds) { // Find each unowned neighbor tiles for this player validCards = GetValidCards(playerId); } else { int x = tileBeingPurchased.x; int y = tileBeingPurchased.y; // This is where the tile is checked against purchasing rules if (GridManager.grid[x, y].ownerId == 0 && // Is the tile unowned? !GridManager.grid[x, y].bankrupt) { // Is the tile not bankrupt? isValid = true; } } if (validCards.Contains(tileBeingPurchased)) { isValid = true; } return(isValid); } // GetValidTiles()
//Distance from the start point of the great circle to the point on the path closest to the external point /// <summary> /// Computes the distance of the point on the great circle between the two path points that is closest to the external point. /// This is the distance from the fromPath point along the great circle, that minimizes the distance to the external point. /// </summary> /// <param name="fromPath">First point on the great circle</param> /// <param name="toPath">Second point on the great circle</param> /// <param name="external">Point to compute the distance along the great circle from the start point to</param> /// <returns>The distance in meters from the fromPath point, to the point on the great circle closest to the external point</returns> public double NearestDistance(Coordinate2 <double> fromPath, Coordinate2 <double> toPath, Coordinate2 <double> external) { double d13 = this.Distance(fromPath.X, fromPath.Y, toPath.X, toPath.Y); double dt = this.DistanceTo(fromPath, toPath, external); return(Math.Acos(Math.Cos(d13 / meanRadius) / Math.Cos(dt / meanRadius)) * meanRadius); }
/// <summary> /// /// </summary> /// <param name="tokens"></param> /// <param name="skipExtraParenthesis"></param> /// <returns></returns> private Coordinate2 <double> GetPreciseCoordinate(IEnumerator <Token> tokens, Boolean skipExtraParenthesis) { var coord = new Coordinate2 <double>(); var extraParenthesisFound = false; if (skipExtraParenthesis) { extraParenthesisFound = IsStringValueNext(tokens, "("); if (extraParenthesisFound) { tokens.MoveNext(); //_index++; } } coord.X = GetNextNumber(tokens); coord.Y = GetNextNumber(tokens); if (IsNumberNext(tokens)) { GetNextNumber(tokens); //skip over Z } if (skipExtraParenthesis && extraParenthesisFound && IsStringValueNext(tokens, ")")) { tokens.MoveNext(); //_index++; } return(coord); }
private static Coordinate2 <double> MeanNearest(Coordinate2 <double> p1, Coordinate2 <double> p2, Coordinate2 <double> q1, Coordinate2 <double> q2) { Coordinate2 <double> mean = new Coordinate2 <double>((p1.X + p2.X + q1.X + q2.X) * 0.25, (p1.Y + p2.Y + q1.Y + q2.Y) * 0.25); Coordinate2 <double> intPt = p1; double bestDist = SegmentUtils.Length(mean.X, mean.Y, intPt.X, intPt.Y); double curDist = SegmentUtils.Length(mean.X, mean.Y, p2.X, p2.Y); if (curDist < bestDist) { bestDist = curDist; intPt = p2; } curDist = SegmentUtils.Length(mean.X, mean.Y, q1.X, q1.Y); if (curDist < bestDist) { bestDist = curDist; intPt = q1; } curDist = SegmentUtils.Length(mean.X, mean.Y, q2.X, q2.Y); if (curDist < bestDist) { //bestDist = curDist; //intPt = q2; return(q2); } return(intPt); }
// Matching structure public GridCell(Grid grid, Coordinate2 gridLocation) { this.grid = grid; this.gridLocation = gridLocation; this.occupant = null; this.state = State.Empty; }
private bool IsValidPurchase(Coordinate2 tileBeingPurchased, int playerId) { int round = matchData.Round; bool isValid = false; List <Coordinate2> validCards = new List <Coordinate2>(); if (round > config.GraceRounds) { // Find each unowned neighbor tiles for this player validCards = GetValidCards(playerId); } else { Debug.Log(debugTag + "Tile being purchased: " + tileBeingPurchased); // This is where the tile is checked against purchasing rules if (!gridController.IsTileOwned(tileBeingPurchased.x, tileBeingPurchased.y) && !gridController.IsTileBankrupt(tileBeingPurchased.x, tileBeingPurchased.y)) { isValid = true; } } if (validCards.Contains(tileBeingPurchased)) { isValid = true; } return(isValid); }
public static bool PointsEqual(Coordinate2 <double> pt1, Point2 <double> pt2) { if (MathUtils.AlmostEqual(pt1.X, pt2.X) && MathUtils.AlmostEqual(pt1.Y, pt2.Y)) { return(true); } return(false); }
public override Point2 <double> ConstructPoint(Coordinate2 <double> coord) { if (coord != null && !(double.IsNaN(coord.X) || double.IsNaN(coord.Y))) { return(new Point2 <double>(coord.X, coord.Y)); } return(null); }
//Distance from the great circle path to the external point /// <summary> /// Compute the distance to the great circle passing through the path points from the external point. /// This is the distance in meters from the external point, to the great circle containing the two path points. /// </summary> /// <param name="fromPath">First point on the great circle</param> /// <param name="toPath">Second point on the great circle</param> /// <param name="external">Point to compute the distance from the great circle to</param> /// <returns>The distance in meters to the external point</returns> public double DistanceTo(Coordinate2 <double> fromPath, Coordinate2 <double> toPath, Coordinate2 <double> external) { double d13 = this.Distance(fromPath.X, fromPath.Y, toPath.X, toPath.Y); double o13 = this.Direction(fromPath.X, fromPath.Y, toPath.X, toPath.Y); double o12 = this.Direction(fromPath.X, fromPath.Y, external.X, external.Y); return(Math.Asin(Math.Sin(d13 / meanRadius) * Math.Sin(o13 - o12)) * meanRadius); }
public override int GetHashCode(SpatialEqualityOptions options) { unchecked { int hashCode = (Coordinate1 != null ? Coordinate1.GetHashCode(options) : 0); hashCode = (hashCode * 397) ^ (Coordinate2 != null ? Coordinate2.GetHashCode(options) : 0); hashCode = (hashCode * 397) ^ Distance.GetHashCode(); hashCode = (hashCode * 397) ^ Bearing12.GetHashCode(); hashCode = (hashCode * 397) ^ Bearing21.GetHashCode(); return(hashCode); } }
} // Constructor public override bool Equals(object obj) { if (obj == null || !this.GetType().Equals(obj.GetType())) { return(false); } else { Coordinate2 c = (Coordinate2)obj; return(x == c.x && y == c.y); } } // override Equals()
private void setCoordinate1Click(object sender, RoutedEventArgs e) { Joint LeftFoot = Calibration.mainSkeleton.Joints[JointType.FootLeft]; if (LeftFoot == null) { } else { Calibration.yaxis.max = MatrixMath.jointToPoint(LeftFoot); Coordinate2 coord2 = new Coordinate2(sensor, tracker); Debug.WriteLine("click"); coord2.Show(); this.Close(); } }
public bool BuyTile(Coordinate2 target) { int turn = matchData.Turn; // Don't want the turn changing while this is running int phase = matchData.Phase; bool purchaseSuccess = false; // Debug.Log(debug + "Player " + turn // + " (ID: " + GameManager.players[turn - 1].Id // + ") trying to buy tile " + target.ToString()); // Check against the rest of the purchasing rules before proceding if (IsValidPurchase(target, turn)) { players[turn - 1].ownedTiles.Add(target); // Server-side gridController.SetTileOwner(target.x, target.y, turn); TurnEvent turnEvent = new TurnEvent(phase, turn, "Buy", "Tile", target.x, target.y, matchDataBroadcaster.TopCardStr, JsonUtility.ToJson(new Card(gridController.GetServerTile("Tile", target.x, target.y)))); matchDataBroadcaster.TurnEventStr = JsonUtility.ToJson(turnEvent); // Debug.Log(debug + "JSON: " + turnEvent); // Debug.Log(debug + "Player " + turn // + " (ID: " + GameManager.players[turn - 1].Id // + ") bought tile " + target.ToString()); UpdatePlayersInfo(); IncrementTurn(); purchaseSuccess = true; } else { // Debug.Log(debug + "Can't purchase, tile " + target.ToString() // + " is not valid for you! \nAlready Owned?\nOut of Range?\nBankrupt Tile?"); } return(purchaseSuccess); }
} // OnTurnChange() public bool BuyTile(Coordinate2 target) { int turn = this.turn; // Don't want the turn changing while this is running bool purchaseSuccess = false; Debug.Log(debug + "Player " + turn + " (ID: " + GameManager.players[turn - 1].Id + ") trying to buy tile " + target.ToString()); // Check against the rest of the purchasing rules before proceding if (IsValidPurchase(target, turn)) { GameManager.players[turn - 1].ownedTiles.Add(target); // Server-side GridManager.grid[target.x, target.y].ownerId = turn; TurnEvent turnEvent = new TurnEvent(this.phase, turn, "Buy", "Tile", target.x, target.y); this.turnEventBroadcast = JsonUtility.ToJson(turnEvent); Debug.Log(debug + "JSON: " + turnEvent); // this.turnEventBroadcast = turn + "_x" + target.x + "_y" + target.y; Debug.Log(debug + "Player " + turn + " (ID: " + GameManager.players[turn - 1].Id + ") bought tile " + target.ToString()); // Debug.Log(debug + "Advancing Turn; This is a temporary mechanic!"); purchaseSuccess = true; this.IncrementTurn(); } else { Debug.Log(debug + "Can't purchase, tile " + target.ToString() + " is not valid for you! \nAlready Owned?\nOut of Range?\nBankrupt Tile?"); } return(purchaseSuccess); } // BuyTile()
public bool PlaceChild(Tower towerPrefab, Coordinate2 coord) { if (!nodes [coord.X, coord.Y].Available || !nodes [coord.X, coord.Y].Buildable) { Debug.Log("[" + coord.X + ", " + coord.Y + "]: Available(" + nodes [coord.X, coord.Y].Available + ") - Buildable(" + nodes [coord.X, coord.Y].Buildable + ")"); return(false); } if (towerPrefab.Price > GameManager.instance.Currency) { return(false); } Transform towerParent = transform.FindChild("Towers"); if (towerParent == null) { towerParent = new GameObject("Towers").transform; towerParent.transform.SetParent(transform); towerParent.transform.localPosition = Vector3.zero; } Tower obj = Instantiate(towerPrefab).GetComponent <Tower> (); obj.transform.SetParent(towerParent); Vector3 pos = new Vector3((Size.x * ((2.0f * coord.X) - Dimentions.x + 1.0f)) / (2.0f * Dimentions.x), 0, (Size.y * ((2.0f * coord.Y) - Dimentions.y + 1.0f)) / (2.0f * Dimentions.y)); obj.transform.localPosition = pos; GameManager.instance.Currency -= obj.Price; nodes [coord.X, coord.Y].Available = false; return(true); }
public static LineSegment2IntersectionResult <double> ComputeIntersection(Point2 <double> p1, Point2 <double> p2, Point2 <double> q1, Point2 <double> q2) { if (p1 == null || p2 == null || q1 == null || q2 == null) { return(null); } //quick rejection if (!Coordinate2Utils.EnvelopesIntersect(p1, p2, q1, q2)) { return(new LineSegment2IntersectionResult <double>()); } // for each endpoint, compute which side of the other segment it lies // if both endpoints lie on the same side of the other segment, the segments do not intersect int Pq1 = Coordinate2Utils.OrientationIndex(p1, p2, q1); int Pq2 = Coordinate2Utils.OrientationIndex(p1, p2, q2); if ((Pq1 > 0 && Pq2 > 0) || (Pq1 < 0 && Pq2 < 0)) { return(new LineSegment2IntersectionResult <double>()); } int Qp1 = Coordinate2Utils.OrientationIndex(q1, q2, p1); int Qp2 = Coordinate2Utils.OrientationIndex(q1, q2, p2); if ((Qp1 > 0 && Qp2 > 0) || (Qp1 < 0 && Qp2 < 0)) { return(new LineSegment2IntersectionResult <double>()); } //end quick rejection if (Pq1 == 0 && Pq2 == 0 && Qp1 == 0 && Qp2 == 0) //collinear intersection { bool p1q1p2 = Coordinate2Utils.PointInEnvelope(p1, p2, q1); bool p1q2p2 = Coordinate2Utils.PointInEnvelope(p1, p2, q2); bool q1p1q2 = Coordinate2Utils.PointInEnvelope(q1, q2, p1); bool q1p2q2 = Coordinate2Utils.PointInEnvelope(q1, q2, p2); if (p1q1p2 && p1q2p2) { return(new LineSegment2IntersectionResult <double>(LineIntersectionType.CollinearIntersection, q1, q2)); } if (q1p1q2 && q1p2q2) { return(new LineSegment2IntersectionResult <double>(LineIntersectionType.CollinearIntersection, p1, p2)); } if (p1q1p2 && q1p1q2) { if (q1.Equals(p1) && !p1q2p2 && !q1p2q2) { return(new LineSegment2IntersectionResult <double>(q1)); } return(new LineSegment2IntersectionResult <double>(LineIntersectionType.CollinearIntersection, q1, p1)); } if (p1q1p2 && q1p2q2) { if (q1.Equals(p2) && !p1q2p2 && !q1p1q2) { return(new LineSegment2IntersectionResult <double>(q1)); } return(new LineSegment2IntersectionResult <double>(LineIntersectionType.CollinearIntersection, q1, p2)); } if (p1q2p2 && q1p1q2) { if (q2.Equals(p1) && !p1q1p2 && !q1p2q2) { return(new LineSegment2IntersectionResult <double>(q2)); } return(new LineSegment2IntersectionResult <double>(LineIntersectionType.CollinearIntersection, q2, p1)); } if (p1q2p2 && q1p2q2) { if (q2.Equals(p2) && !p1q1p2 && !q1p1q2) { return(new LineSegment2IntersectionResult <double>(q2)); } return(new LineSegment2IntersectionResult <double>(LineIntersectionType.CollinearIntersection, q2, p2)); } return(new LineSegment2IntersectionResult <double>()); }//end collinear // At this point we know that there is a single intersection point (since the lines are not collinear). // Check if the intersection is an endpoint. If it is, copy the endpoint as the intersection point. Copying the point rather than computing it // ensures the point has the exact value, which is important for robustness. It is sufficient to simply check for an endpoint which is on // the other line, since at this point we know that the inputLines must intersect. if (Pq1 == 0 || Pq2 == 0 || Qp1 == 0 || Qp2 == 0) { // Check for two equal endpoints. This is done explicitly rather than by the orientation tests below in order to improve robustness. if (p1.Equals(q1) || p1.Equals(q2)) { return(new LineSegment2IntersectionResult <double>(p1)); } else if (p2.Equals(q1) || p2.Equals(q2)) { return(new LineSegment2IntersectionResult <double>(p2)); } // Now check to see if any endpoint lies on the interior of the other segment. else if (Pq1 == 0) { return(new LineSegment2IntersectionResult <double>(q1)); } else if (Pq2 == 0) { return(new LineSegment2IntersectionResult <double>(q2)); } else if (Qp1 == 0) { return(new LineSegment2IntersectionResult <double>(p1)); } else if (Qp2 == 0) { return(new LineSegment2IntersectionResult <double>(p2)); } } //end exact at endpoint //intersectWNormalization Coordinate2 <double> n1 = new Coordinate2 <double>(p1); Coordinate2 <double> n2 = new Coordinate2 <double>(p2); Coordinate2 <double> n3 = new Coordinate2 <double>(q1); Coordinate2 <double> n4 = new Coordinate2 <double>(q2); Coordinate2 <double> normPt = new Coordinate2 <double>(); Coordinate2Utils.NormalizeToEnvCentre(n1, n2, n3, n4, normPt); //safeHCoordinateIntersection Coordinate2 <double> intPt = null; // unrolled computation double px = n1.Y - n2.Y; double py = n2.X - n1.X; double pw = n1.X * n2.Y - n2.X * n1.Y; double qx = n3.Y - n4.Y; double qy = n4.X - n3.X; double qw = n3.X * n4.Y - n4.X * n3.Y; double x = py * qw - qy * pw; double y = qx * pw - px * qw; double w = px * qy - qx * py; double xInt = x / w; double yInt = y / w; if (double.IsNaN(xInt) || double.IsNaN(yInt) || double.IsInfinity(xInt) || double.IsInfinity(yInt)) { intPt = MeanNearest(n1, n2, n3, n4); xInt = intPt.X + normPt.X; yInt = intPt.Y + normPt.Y; return(new LineSegment2IntersectionResult <double>(p1.Factory.ConstructPoint(xInt, yInt))); } else { xInt += normPt.X; yInt += normPt.Y; intPt = new Coordinate2 <double>(xInt, yInt); } //End safeHCoordinateIntersection //End intersectWNormalization if (!(Coordinate2Utils.PointInEnvelope(p1, p2, intPt) || Coordinate2Utils.PointInEnvelope(q1, q2, intPt))) { intPt = MeanNearest(p1, p2, q1, q2); } return(new LineSegment2IntersectionResult <double>(p1.Factory.ConstructPoint(intPt.X, intPt.Y))); }
private void InitializeCamera() { CameraPosition = Coordinate2.X0Y0; CameraZoom = 1.0f; CameraRotation = 0.0f; }
private void CleanupCamera() { CameraPosition = Coordinate2.X0Y0; CameraZoom = 1.0f; CameraRotation = 0.0f; }
protected override void CleanupCenter() { _Center = default(Coordinate2); }
private void InitializeTextureCoordinates() { TextureCoordinates = new Single[4 * 2]; //TODO: these are temporary, for testing. TextureCoordinates_0_TopLeft = new Coordinate2(0.0f, 0.0f); TextureCoordinates_1_BottomLeft = new Coordinate2(0.0f, 1.0f); TextureCoordinates_2_TopRight = new Coordinate2(1.0f, 0.0f); TextureCoordinates_3_BottomRight = new Coordinate2(1.0f, 1.0f); }
public void SetPositionFromCenter(Coordinate2 position) { Single x = position.X - TileWidth / 2; Single y = position.Y - TileHeight / 2; Position = new Coordinate2(x, y); }
private void InitializeTextureCoordinates() { TextureCoordinates = new Single[4 * 2]; TextureCoordinates_0_TopLeft = new Coordinate2(0.0f, 0.0f); TextureCoordinates_1_BottomLeft = new Coordinate2(0.0f, 1.0f); TextureCoordinates_2_TopRight = new Coordinate2(1.0f, 0.0f); TextureCoordinates_3_BottomRight = new Coordinate2(1.0f, 1.0f); }
public void SetCenter(Coordinate2 center) { if (_Center == center) return; _Center = center; SetRecalcRequired(); }
public new void SetPosition(Coordinate2 position, RelativePosition relativeTo = RelativePosition.Center) { base.SetPosition(position, relativeTo); }
protected void AdjustPosition(Single horizontal, Single vertical) { Position = new Coordinate2(Position.X + horizontal, Position.Y + vertical); }
public void SetPositionFromCenter(Single x, Single y) { Single xx = x - TileWidth / 2; Single yy = y - TileHeight / 2; Position = new Coordinate2(xx, yy); }
public void AddDebugInfoLine(String name, Coordinate2 data) { DebugInfoBuilder.Append(name); DebugInfoBuilder.Append(DebugInfoSeparator); DebugInfoBuilder.Append(data.ToString()); DebugInfoBuilder.AppendLine(); }
protected override void InitializeCenter() { _Center = new Coordinate2(DrawEngine2d.FrameBufferWidth/2, DrawEngine2d.FrameBufferHeight/2); SetRecalcRequired(); }
protected void SetPosition(Coordinate2 position, RelativePosition relativeTo = RelativePosition.Center) { //TODO: Add support for CoordinateSystemMode if (DrawEngine2d.CoordinateSystemMode != CoordinateSystemMode.OriginAtUpperLeft) throw new NotImplementedException(); switch (relativeTo) { case RelativePosition.Center : Position = new Coordinate2(position.X - HalfWidth, position.Y - HalfHeight); break; case RelativePosition.TopLeft : Position = position; break; case RelativePosition.Top : Position = new Coordinate2(position.X - HalfWidth, position.Y); break; case RelativePosition.TopRight : Position = new Coordinate2(position.X - Width, position.Y); break; case RelativePosition.Left : Position = new Coordinate2(position.X, position.Y - HalfHeight); break; case RelativePosition.Right : Position = new Coordinate2(position.X - Width, position.Y - HalfHeight); break; case RelativePosition.BottomLeft : Position = new Coordinate2(position.X, position.Y - Height); break; case RelativePosition.Bottom : Position = new Coordinate2(position.X - HalfWidth, position.Y - Height); break; case RelativePosition.BottomRight : Position = new Coordinate2(position.X - Width, position.Y - Height); break; default : throw new NotImplementedException(); } }
} // CreateCardObjectName() // An overload of CreateCardObjectName that takes in a Coordinate2 public static string CreateCardObjectName(string type, Coordinate2 location) { return(CreateCardObjectName(type, location.x, location.y)); } // CreateCardObjectName()
private void InitializeVertices() { Vertices = new Single[VertexCount * 3]; VertexCoordinates_0_TopLeft = new Coordinate2(0.0f, 0.0f); VertexCoordinates_1_BottomLeft = new Coordinate2(0.0f, 1.0f); VertexCoordinates_2_TopRight = new Coordinate2(1.0f, 0.0f); VertexCoordinates_3_BottomRight = new Coordinate2(1.0f, 1.0f); }
public void SetCenterToPointWithinBounds(Coordinate2 point, RectangularArea2 bounds) { //TODO throw new NotImplementedException(); }