/// <summary> /// Determines the derivatives of a curve at a given parameter.<br/> /// <em>Corresponds to algorithm 3.2 from The NURBS Book by Piegl and Tiller.</em> /// </summary> /// <param name="curve">The curve object.</param> /// <param name="parameter">Parameter on the curve at which the point is to be evaluated.</param> /// <param name="numberDerivs">Integer number of basis functions - 1 = knots.length - degree - 2.</param> /// <returns>The derivatives.</returns> internal static List <Point4> CurveDerivatives(NurbsBase curve, double parameter, int numberDerivs) { List <Point4> curveHomogenizedPoints = curve.ControlPoints; int n = curve.Knots.Count - curve.Degree - 2; int derivateOrder = numberDerivs < curve.Degree ? numberDerivs : curve.Degree; Point4[] ck = new Point4[numberDerivs + 1]; int knotSpan = curve.Knots.Span(n, curve.Degree, parameter); List <Vector> derived2d = DerivativeBasisFunctionsGivenNI(knotSpan, parameter, curve.Degree, derivateOrder, curve.Knots); for (int k = 0; k < derivateOrder + 1; k++) { for (int j = 0; j < curve.Degree + 1; j++) { double valToMultiply = derived2d[k][j]; Point4 pt = curveHomogenizedPoints[knotSpan - curve.Degree + j]; for (int i = 0; i < pt.Size; i++) { ck[k][i] = ck[k][i] + (valToMultiply * pt[i]); } } } return(ck.ToList()); }
void OnPromotionRequired(Point4 location) { foreach (PromotionRequiredCallback callback in promotionRequiredCallbacks) { callback(location); } }
public static void Main() { var pt = new Point4(0, -22, 45, 100); Console.Write(pt.X); Console.Write(' '); Console.Write(pt.Y); Console.Write(' '); Console.Write(pt.Z); Console.Write(' '); Console.Write(pt.W); Console.Write(' '); var pt2 = pt as Point2; var pt3 = (Point4)pt2; Console.Write(pt3 is Point2); Console.Write(' '); Console.Write(pt3 is Point3); Console.Write(' '); Console.Write(pt3 is Point4); var pt4 = new Point2(0, 0); Console.Write(' '); Console.Write(pt4 is Point2); Console.Write(' '); Console.Write(pt4 is Point3); Console.Write(' '); Console.Write(pt4 is Point4); Console.WriteLine(); }
public override string ToString() { var sb = new StringBuilder(); var xMin = MinX; var xMax = MaxX; var yMin = MinY; var yMax = MaxY; sb.AppendLine("============================"); sb.AppendLine($"Cycle: {Cycle}"); sb.AppendLine($"X: {xMin}-{xMax}, Y: {yMin}-{yMax}"); sb.AppendLine(); foreach (var w in this.cubes.Keys.Select(p => p.W).Distinct().OrderBy(v => v)) { foreach (var z in this.cubes.Keys.Select(p => p.Z).Distinct().OrderBy(v => v)) { sb.AppendLine($"z={z}, w={w}"); for (var y = yMin; y <= yMax; y++) { for (var x = xMin; x <= xMax; x++) { var key = new Point4(x, y, z, w); sb.Append(this.cubes.ContainsKey(key) ? '#' : '.'); } sb.AppendLine(); } sb.AppendLine(); } } sb.AppendLine("============================"); return(sb.ToString()); }
void ExecuteMove(Tile3D startTile, Tile3D endTile) { if (endTile.currentPiece != null && endTile.currentPiece.type == ChessPiece.Type.KING) { if (board.currentMove == ChessPiece.Team.WHITE) { turnText.text = "White wins!!"; } else { turnText.text = "Black wins!!"; } StartCoroutine(LoadStartScene()); } Point4 startPosition = new Point4(startTile.x, startTile.y, startTile.z, startTile.w); Point4 newPosition = new Point4(endTile.x, endTile.y, endTile.z, endTile.w); board.MovePiece(board.GetMove(startPosition, newPosition)); if (board.currentMove == ChessPiece.Team.BLACK) { turnText.text = "Black's turn"; } else if (board.currentMove == ChessPiece.Team.WHITE) { turnText.text = "White's turn"; } attackers.ComputeAttackers(); }
public void MovePiece(Move move) { ChessPiece piece = move.pieceMoved; Point4 newPosition = move.endPosition; ChessPiece capturedPiece = pieces[piece.x, piece.y, piece.z, piece.w]; Point4 movedFrom = move.startPosition; SetPiece(newPosition, piece); SetPiece(movedFrom, null); /*if (moveHistory.Count > 0) * { * lastMove = moveHistory[moveHistory.Count - 1]; * } * * if (lastMove != null && lastMove.pieceMoved.type == ChessPiece.Type.PAWN && * piece.type == ChessPiece.Type.PAWN && lastMove.startPosition == lastMove.pieceMoved.startPosition && * (newPosition == lastMove.pieceMoved.currentPosition - lastMove.pieceMoved.forwardW || newPosition == lastMove.pieceMoved.currentPosition - lastMove.pieceMoved.forwardZ)) ||{ || SetPiece(lastMove.pieceMoved.currentPosition, null); ||}*/ if (piece.type == ChessPiece.Type.PAWN) { if ((piece.team == ChessPiece.Team.WHITE && piece.z == size.z - 1 && piece.w == size.w - 1) || (piece.team == ChessPiece.Team.BLACK && piece.z == 0 && piece.w == 0)) { ChessPiece promotedPiece = piece.DeepCopy(); promotedPiece.type = ChessPiece.Type.QUEEN; SetPiece(newPosition, promotedPiece); } } moveHistory.Add(move); /*if (capturedPiece.type == ChessPiece.Type.KING) * { * if(currentMove == ChessPiece.Team.WHITE) * { * turnText.text = "White wins!!"; * } * else * { * turnText.text = "Black wins!!"; * } * StartCoroutine(LoadStartScene()); * }*/ if (currentMove == ChessPiece.Team.WHITE) { currentMove = ChessPiece.Team.BLACK; } else { currentMove = ChessPiece.Team.WHITE; } OnBoardUpdate(); }
private void Evaluate(Point4 p) { var c = this[p]; var activeNeighbors = GetAdjacentActiveCubes(p).Count(); if (c.Current == State.Active) { // If a cube is *active* and *exactly `2` or `3`* of its // neighbors are also active, the cube remains *active*. // Otherwise, the cube becomes *inactive*. if (activeNeighbors == 2 || activeNeighbors == 3) { c.Next = State.Active; } } else { // If a cube is *inactive* but *exactly `3`* of its // neighbors are active, the cube becomes *active*. // Otherwise, the cube remains *inactive*. if (activeNeighbors == 3) { c.Next = State.Active; } } }
public void RemoveTileUpdateCallback(Point4 location, TileUpdateCallback callback) { if (tileUpdateCallbacks.ContainsKey(location)) { tileUpdateCallbacks[location].Remove(callback); } }
/// <summary> /// This method evaluate a B-spline span using the deBoor algorithm. /// https://github.com/mcneel/opennurbs/blob/2b96cf31429dab25bf8a1dbd171227c506b06f88/opennurbs_evaluate_nurbs.cpp#L1249 /// This method is not implemented for clamped knots. /// </summary> /// <param name="controlPts">The control points of the curve.</param> /// <param name="knots">The knot vector of the curve.</param> /// <param name="degree">The value degree of the curve.</param> /// <param name="parameter">The parameter value where the curve is evaluated.</param> internal static void DeBoor(ref List <Point4> controlPts, KnotVector knots, int degree, double parameter) { if (Math.Abs(knots[degree] - knots[degree - 1]) < GSharkMath.Epsilon) { throw new Exception($"DeBoor evaluation failed: {knots[degree]} == {knots[degree + 1]}"); } // deltaT = {knot[order-1] - t, knot[order] - t, .. knot[2*order-3] - t} List <double> deltaT = new List <double>(); for (int k = 0; k < degree; k++) { deltaT.Add(knots[degree + 1 + k] - parameter); } for (int i = degree; i > 0; --i) { for (int j = 0; j < i; j++) { double k0 = knots[degree + 1 - i + j]; double k1 = knots[degree + 1 + j]; double alpha0 = deltaT[j] / (k1 - k0); double alpha1 = 1.0 - alpha0; Point4 cv1 = controlPts[j + 1]; Point4 cv0 = controlPts[j]; controlPts[j] = (cv0 * alpha0) + (cv1 * alpha1); } } }
public static void Write(this BinaryWriter writer, Point4 value) { writer.Write(value.X); writer.Write(value.Y); writer.Write(value.Z); writer.Write(value.W); }
public ChessPiece(Type type, Team team, Point4 position, ChessBoard board) { this.type = type; this.team = team; currentPosition = position; startPosition = position; this.board = board; }
public void Initialize(Point4 position, ChessBoard board) { this.position = position; this.board = board; UpdatePiece(); board.RegisterTileUpdateCallback(position, UpdatePiece); }
public ChessBoard(Point4 size, ChessVariantOptions options) { this.size = size; pieces = new ChessPiece[size.x, size.y, size.z, size.w]; maxBoardDimension = Mathf.Max(size.x, size.y, size.z, size.w); this.options = options; }
public void RegisterTileUpdateCallback(Point4 location, TileUpdateCallback callback) { if (!tileUpdateCallbacks.ContainsKey(location)) { tileUpdateCallbacks[location] = new HashSet <TileUpdateCallback>(); } tileUpdateCallbacks[location].Add(callback); }
void UpdateTileHighlights() { foreach (ChessboardController2D chessboardController in chessboardControllers) { foreach (Tile2D boardTile in chessboardController.tiles) { boardTile.ClearSelection(); } if (attackedTile != Point4.NONE) { chessboardController.GetTile(attackedTile).Select(); foreach (ChessPiece attacker in attackers.attackers[attackedTile.x, attackedTile.y, attackedTile.z, attackedTile.w]) { chessboardController.GetTile(attacker.currentPosition).Attacked(); } } else if (selectedTile != Point4.NONE && destinationTile == Point4.NONE) { chessboardController.GetTile(selectedTile).Select(); if (board.GetPiece(selectedTile) != null) { foreach (Point4 move in board.GetPiece(selectedTile).GetValidMoves()) { chessboardController.GetTile(move).Highlight(); } } } else if (selectedTile != Point4.NONE && destinationTile != Point4.NONE) { chessboardController.GetTile(selectedTile).Select(); chessboardController.GetTile(destinationTile).Select(); } if (board.moveHistory.Count > 0) { Point4 startPoint = board.moveHistory[board.moveHistory.Count - 1].startPosition; chessboardController.GetTile(startPoint).Moved(); Point4 endPoint = board.moveHistory[board.moveHistory.Count - 1].endPosition; chessboardController.GetTile(endPoint).Moved(); } foreach (ChessPiece piece in board.pieces) { if (piece != null && piece.type == ChessPiece.Type.KING) { foreach (ChessPiece attackingPiece in attackers.GetAttackers(piece.currentPosition)) { if (piece.team != attackingPiece.team) { chessboardController.GetTile(attackingPiece.currentPosition).Check(); chessboardController.GetTile(piece.currentPosition).Check(); } } } } } }
public void SetPiece(Point4 position, ChessPiece piece) { pieces[position.x, position.y, position.z, position.w] = piece; if (piece != null) { piece.currentPosition = position; } OnTileUpdate(position); }
Vector3 GetTilePosition(Point4 position) { Vector3 xComponent = GetCardinalityVector(cardinalityX); Vector3 yComponent = GetCardinalityVector(cardinalityY); Vector3 zComponent = GetCardinalityVector(cardinalityZ); Vector3 wComponent = GetCardinalityVector(cardinalityW); return(xComponent * position.x + yComponent * position.y + zComponent * position.z + wComponent * position.w); }
public Point4 GetContainingPoints() { Point4 points = new Point4(); points.point0 = new Point(x, y); points.point1 = new Point(x + 1, y); points.point2 = new Point(x, y + 1); points.point3 = new Point(x + 1, y + 1); return(points); }
void OnTileUpdate(Point4 location) { if (tileUpdateCallbacks.ContainsKey(location)) { foreach (TileUpdateCallback callback in tileUpdateCallbacks[location]) { callback(); } } }
public Move GetMove(Point4 start, Point4 end) { Move move = new Move(); move.startPosition = start; move.endPosition = end; move.pieceMoved = GetPiece(start); move.pieceCaptured = GetPiece(end); return(move); }
public IEnumerable <Cube4> GetAdjacentActiveCubes(Point4 point) { foreach (var p in point.GetAdjacent()) { if (cubes.ContainsKey(p) && cubes[p].Current == State.Active) { yield return(cubes[p]); } } }
public static void Uniform4(int uniformLocation, ref Point4 coords) { unsafe { fixed(int *ptr = &coords.X) { Delegates.Uniform4ivARB(uniformLocation, 1, ptr); } } }
public bool IsLineOfSight(Node end) { bool inSight; if (x == end.x) { int dy = MyMathf.Sign(end.y - y); if (dy == 0) { return(!tile.isBlocked); } inSight = true; for (int sy = y; sy != end.y + dy; sy += dy) { if (nodes[x, sy].tile.isBlocked) { inSight = false; break; } } return(inSight); } else if (y == end.y) { int dx = MyMathf.Sign(end.x - x); //if (dx == 0) return !tile.isBlocked; inSight = true; for (int sx = x; sx != end.x + dx; sx += dx) { if (nodes[sx, y].tile.isBlocked) { inSight = false; break; } } return(inSight); } Point4 startPoints = GetContainingPoints(); Point4 endPoints = end.GetContainingPoints(); inSight = true; for (int i = 0; i < 4; i++) { if (!startPoints[i].IsLineOfSight(endPoints[i])) { inSight = false; break; } } return(inSight); }
public bool IsValidMove(Point4 position) { foreach (Point4 move in GetValidMoves()) { if (move == position) { return(true); } } return(false); }
/// <summary> /// Bezier degree reduction. /// <em>Refer to The NURBS Book by Piegl and Tiller at page 220.</em> /// </summary> private static double BezierDegreeReduce(Point4[] bpts, int degree, out Point4[] rbpts) { // Eq. 5.40 int r = (int)Math.Floor(((double)degree - 1) / 2); Point4[] P = new Point4[degree]; P[0] = bpts[0]; P[P.Length - 1] = bpts.Last(); bool isDegreeOdd = degree % 2 != 0; int r1 = (isDegreeOdd) ? r - 1 : r; // Eq. 5.41 for (int i = 1; i <= r1; i++) { double alphaI = (double)i / degree; P[i] = (bpts[i] - (P[i - 1] * alphaI)) / (1 - alphaI); } for (int i = degree - 2; i >= r + 1; i--) { double alphaI = (double)(i + 1) / degree; P[i] = (bpts[i + 1] - (P[i + 1] * (1 - alphaI))) / alphaI; } /* Equations (5.43) and (5.44) express the parametric error {distance between points at corresponding parameter values); * the maximums of geometric and parametric errors are not necessarily at the same u value. * For p even the maximum error occurs at u = 1/2; for p odd the error is zero at u = 1/2, and it has two peaks a bit to the left and * right of u = 1/2. */ // Eq. 5.43 p even. KnotVector knots = new KnotVector(degree - 1, P.Length); int span = knots.Span(degree - 1, 0.5); List <double> Br = Evaluate.Curve.BasisFunction(degree - 1, knots, span, 0.5); double parametricError = bpts[r + 1].DistanceTo((P[r] + P[r + 1]) * 0.5) * Br[r + 1]; // Eq. 5.42 if (isDegreeOdd) { double alphaR = (double)r / degree; Point4 PLeft = (bpts[r] - (P[r - 1] * alphaR)) / (1 - alphaR); double alphaR1 = (double)(r + 1) / degree; Point4 PRight = (bpts[r + 1] - (P[r + 1] * (1 - alphaR1))) / alphaR1; P[r] = (PLeft + PRight) * 0.5; // Eq. 5.44 p odd. parametricError = ((1 - alphaR) * 0.5) * ((Br[r] - Br[r + 1]) * PLeft.DistanceTo(PRight)); } rbpts = P; return(parametricError); }
public void Execute(int i) { Point4 p = default(S).GetPoint4(i, resolution, invResolution); positions[i] = transpose(TransformVectors(positionTRS, p.positions)); float3x4 n = transpose(TransformVectors(normalTRS, p.normals, 0f)); normals[i] = float3x4( normalize(n.c0), normalize(n.c1), normalize(n.c2), normalize(n.c3) ); }
private void ExecuteCycle(List <Point4> cubes) { Dictionary <Point4, int> neighborMap = new Dictionary <Point4, int>(); foreach (Point4 cube in cubes) { for (int w = -1; w <= 1; w++) { for (int z = -1; z <= 1; z++) { for (int y = -1; y <= 1; y++) { for (int x = -1; x <= 1; x++) { if (x == 0 && y == 0 && z == 0 && w == 0) { if (!neighborMap.ContainsKey(cube)) { neighborMap[cube] = 0; } continue; } Point4 neighbor = cube + new Point4(x, y, z, w); if (!neighborMap.ContainsKey(neighbor)) { neighborMap[neighbor] = 0; } neighborMap[neighbor]++; } } } } } foreach ((Point4 point, int neighborCount) in neighborMap) { if (cubes.Contains(point)) { if (neighborCount < 2 || neighborCount > 3) { cubes.Remove(point); } } else if (neighborCount == 3) { cubes.Add(point); } } }
void ClickOffTile() { if (selectedTile != Point4.NONE && destinationTile == Point4.NONE) { selectedTile = Point4.NONE; } else if (selectedTile != Point4.NONE && destinationTile != Point4.NONE) { destinationTile = Point4.NONE; } UpdateTileHighlights(); }
public override string ToString() { string res = ""; res += string.Format("Point1- {0}\n", Point1.ToString()); res += string.Format("Point2- {0}\n", Point2.ToString()); res += string.Format("Point3- {0}\n", Point3.ToString()); res += string.Format("Point4- {0}\n", Point4.ToString()); res += string.Format("Point5- {0}\n", Point5.ToString()); res += string.Format("Point6- {0}\n", Point6.ToString()); res += string.Format("Point7- {0}\n", Point7.ToString()); res += string.Format("Point8- {0}\n", Point8.ToString()); res += string.Format("Edge- {0}", EdgeLenght); return(res); }
public double getDistanceL1(Point4 other) { if (other is Point4d) { return(getDistanceL1((Point4d)other)); } else if (other is BuffPoint4d) { return(getDistanceL1((BuffPoint4d)other)); } else { return(getDistanceL1(new Point4d(other))); } }
public Segment4(Point4 a, Point4 b) { this.a = a; this.b = b; }
public Triangle4(Point4 a, Point4 b, Point4 c) { this.a = a; this.b = b; this.c = c; }