private Point2D?circumcenter; // cached #region Constructors public Triangle2D(Point2D a, Point2D b, Point2D c) { this.a = a; this.b = b; this.c = c; this.circumcenter = null; }
public bool FindValidPoint(float x, float z, out Point2D point) { Vector2 pos = new Vector2(x - terrainOffset.x, z - terrainOffset.z); float minDist = float.MaxValue; Point2D?chosen = null; for (int i = 0; i < neighbours.Length; i++) { Vector2 next = pos + neighbours[i]; Point2D p = ClampToPoint(next.x, next.y, false); if (ValidPoint(p)) { next.x = p.x * tileSize + tileSize / 2; next.y = p.y * tileSize + tileSize / 2; float dist = Vector2.Distance(pos, next); if (dist < minDist) { minDist = dist; chosen = p; } } } if (chosen.HasValue) { point = chosen.Value; return(true); } point = new Point2D(0, 0); return(false); }
/// <summary> /// Moves the thing in the direction of the specified vector /// </summary> public bool Move(Point2D vector) { var newPos = Positions.Select(p => p.Translate(vector)).ToList(); var ev = BeforeMoved; var eva = new Point2DEventArgs(newPos); if (ev != null) { ev.Invoke(this, eva); } if (eva.Abort) { return(false); } Positions = newPos; var ev2 = Moved; if (ev2 != null) { ev2.Invoke(this, new Point2DEventArgs(newPos)); } if (_rotationalCentre.HasValue) { _rotationalCentre = _rotationalCentre.Value.Translate(vector); } return(true); }
private bool IsRealIntersect(Point2D?p, Line2D line1, Line2D line2) { bool check1 = p.Value.X >= line1.StartPoint.X && p.Value.X <= line1.EndPoint.X; bool check2 = p.Value.X >= line2.StartPoint.X && p.Value.X <= line2.EndPoint.X; return(check1 && check2); }
public bool Rotate(Point2D?origin = null, int angle = 90) { var o = origin.GetValueOrDefault(RotationalCentre); var newPos = Positions.Select(p => p.Rotate(o, angle)).ToList(); var ev = BeforeMoved; var eva = new Point2DEventArgs(newPos); if (ev != null) { ev.Invoke(this, eva); } if (eva.Abort) { return(false); } Positions = newPos; var ev2 = Moved; if (ev2 != null) { ev2.Invoke(this, eva); } return(true); }
public IEnumerable <Line2D> GetLines() { if (MiddleLine2D == null) { yield break; } var vertexes = GetVertexes(); if (vertexes == null) { yield break; } Point2D?firstVertex = null; Point2D?lastVertex = null; foreach (var vertex in vertexes) { if (firstVertex == null) { firstVertex = vertex; } if (lastVertex != null) { yield return(new Line2D(lastVertex.Value, vertex)); } lastVertex = vertex; if (lastVertex != firstVertex) { yield return(new Line2D(lastVertex.Value, firstVertex.Value)); } } }
private bool IsRealPoint(Point2D?p) { if (p.Value.X == 0 && p.Value.Y == 0) { return(false); } return(true); }
public override bool ProcessMouseButtonUp(CanonicalMouseEventArgs e, InteractionContext context) { if (this.IsActive) { this.Deactivate(); this.nullable_0 = new Point2D?(); } return(this.IsActive); }
public StorageLocation CreateStorageLocation(Point2D?locationOffset = null, Point2D?markerPointOffset = null, int?storageLocationId = null, int?markerPointId = null) { storageLocationId ??= GetNextId(StorageLocations); return(new StorageLocation { Id = storageLocationId.Value, StorageRowOffset = locationOffset ?? default, Diameter = 1.5 }
public void IntersectWithTest(string s1, string e1, string s2, string e2, string expected) { var line1 = Line2D.Parse(s1, e1); var line2 = Line2D.Parse(s2, e2); Point2D?e = string.IsNullOrEmpty(expected) ? (Point2D?)null : Point2D.Parse(expected); Point2D?intersection = line1.IntersectWith(line2); Assert.AreEqual(e, intersection); }
private static List <Tuple <Point, string> > Adapter(Point2D?value, Envelope env) { var list = new List <Tuple <Point, string> >(); if (value.HasValue) { list.Add(Tuple.Create(new Point(value.Value.X, value.Value.Y), default(string))); } return(list); }
/// <inheritdoc/> public override List <Tuple <Point, string, string> > GetAdaptedValue(Point2D?source, Envelope envelope) { var list = new List <Tuple <Point, string, string> >(); if (source.HasValue) { list.Add(Tuple.Create(new Point(source.Value.X, source.Value.Y), default(string), default(string))); } return(list); }
/// <summary> /// Returns Box-Muller normally distributed 2D point /// </summary> /// <param name="muX">Mean X</param> /// <param name="muY">Mean Y</param> /// <param name="sigma">Sigma</param> public Point2D GenerateNormalPoint(double muX, double muY, double sigma) { Point2D?sample = null; while (!sample.HasValue) { var p = GenerateUniformPoint(); sample = p.ToBoxMuller(); } return(new Point2D(sample.Value.X * sigma + muX, sample.Value.Y * sigma + muY)); }
public ItemWidget(Widget parent, Point2D?dragOffset) : base(parent) { lblAmount = new TextLine(Fonts.Text); lblAmount.TextColor = Color.White; this.dragOffset = dragOffset; if (dragOffset.HasValue) { Host.GrabMouse(this); Position = Host.MousePosition.Sub(dragOffset.Value); } }
public async Task MoveAsync(Point2D start, Point2D end, Point2D?captured = null) { var moveSteps = planner.PlanMove(start, end, captured); foreach (var setOfSteps in moveSteps) { await performer.MovePieceAsync(setOfSteps); //TODO: remove: previousMoves[previousMoves.Count - 1].Add(setOfSteps); } previousMoves.Add(moveSteps); await performer.GoHomeAsync(); }
public virtual Point2D?Snap(Point2D wcsValue, double wcsToDcsScaleFactor) { double gridDistanceWcs = this.GetGridDistanceWcs(wcsToDcsScaleFactor); double proximityLimitWcs = this.double_1 / wcsToDcsScaleFactor; Point2D point2D = new Point2D(wcsValue.X % gridDistanceWcs, wcsValue.Y % gridDistanceWcs); Point2D?nullable = new Point2D?(); if (this.method_0(point2D.X, gridDistanceWcs, proximityLimitWcs) && this.method_0(point2D.Y, gridDistanceWcs, proximityLimitWcs)) { nullable = new Point2D?(new Point2D(System.Math.Round(wcsValue.X / gridDistanceWcs) * gridDistanceWcs, System.Math.Round(wcsValue.Y / gridDistanceWcs) * gridDistanceWcs)); } return(nullable); }
/// <summary> /// Function getting a CS:GO Position fetched from a replay file which returns a coordinate for our UI /// </summary> /// <param name="p"></param> /// <returns></returns> public Point2D GameToUIPosition(Canvas TargetUi, Point2D?p, Point2D coordinateorigin, Vector2D dimension) { if (TargetUi == null) { throw new Exception("Unkown UI to map game position to. Please define Ui Variable"); } // Calculate a given demo point into a point suitable for our gui minimap: therefore we need a rotation factor, the origin of the coordinate and other data about the map. var scaler = GetScaleFactor(TargetUi, dimension); var x = Math.Abs(coordinateorigin.X - p.Value.X) * scaler.X; var y = Math.Abs(coordinateorigin.Y - p.Value.Y) * scaler.Y; return(new Point2D(x, y)); }
private Point2D GetShotTargetPosition( ChickenUnitState unitState, ChickenViewData enemyUnit) { if (!_features.IsAnySet(Features.PredictiveShot)) { return(enemyUnit.Position); } Point2D?predictiveShotTargetPosition = null; var enemyUnitBeakTip = GameHelper.GetBeakTipPosition(enemyUnit.Position, enemyUnit.BeakAngle); var enemyUnitVector = enemyUnitBeakTip - enemyUnit.Position; var enemyToMeVector = unitState.Position - enemyUnit.Position; var cosAlpha = enemyUnitVector.GetAngleCosine(enemyToMeVector); var distanceToEnemySqr = enemyToMeVector.GetLengthSquared(); var distanceToEnemy = distanceToEnemySqr.Sqrt(); if (!(cosAlpha.Abs() - 1f).IsZero()) { var equation = new QuadraticEquation( GameConstants.ShotToChickenRectilinearSpeedRatio.Sqr() - 1f, 2f * distanceToEnemy * cosAlpha, -distanceToEnemySqr); float d1, d2; if (equation.GetRoots(out d1, out d2) > 0) { var d = new[] { d1, d2 } .Where(item => item > 0f) .OrderBy(item => item) .FirstOrDefault(); if (d.IsPositive()) { predictiveShotTargetPosition = GameHelper.GetNewPosition( enemyUnit.Position, enemyUnit.BeakAngle, d); } } } var result = predictiveShotTargetPosition ?? GameHelper.GetNewPosition( enemyUnit.Position, enemyUnit.BeakAngle, GameConstants.ChickenUnit.DefaultRectilinearSpeed); return(result); }
public void IntersectingBug1() { Segment2D[] red = { new Segment2D(new Point2D(384450, 7171260), new Point2D(384450, 7171380)) }; var one = new Segment2D(new Point2D(393160.294372512, 7169290.29437251), new Point2D(393103.309524418, 7169266.69047558)); var two = new Segment2D(new Point2D(392970, 7169820), new Point2D(392970, 7169240.58874503)); var three = new Segment2D(new Point2D(392899.705627487, 7169220), new Point2D(393967.645019878, 7169662.35498012)); Segment2D[] blue = { one, two, three }; Point2D?result = Intersector.Intersect(two, three); var rbi = new RedBlueIntersector(red, blue); }
bool IsNextTo(GameEntityInstance other) { Point2D?currentLocation = Location; while (currentLocation != other.Location) { currentLocation = NextStep((Point2D)currentLocation, other); if (currentLocation == null) { return(false); } } return(true); }
public List <IList <Point2D> > PlanMove(Point2D start, Point2D end, Point2D?captured = null) //inputs (0-7, 0-7) { List <IList <Point2D> > paths = new List <IList <Point2D> >(); if (captured.HasValue) { paths.Add(getCapturedPath(end)); } if (captured != end && board.PieceAt(end) != null) { paths.Add(getCapturedPath(end)); } paths.Add(getMovePath(start, end)); return(paths); }
/// <summary> /// Compute the intersections of the bisector of the supplied node with the bisectors starting /// from the neightbour vertices in the LAV. Store the nearest intersection (if it exists) in the /// priority queue. /// </summary> /// <param name="lav">The List of Active Vertices</param> /// <param name="node">The node at the origin of the bisector to be intersected.</param> private void EnqueueNearestBisectorIntersection(CircularLinkedList <Vertex> lav, CircularLinkedListNode <Vertex> node) { // TODO: Retrieve the the lav using node.List // Find intersection with previous bisector // TODO: For some unknown reason the ternary operator does not work for the following expression Point2D?previousIntersection = null; if (node.Previous != null) { previousIntersection = Intersector.Intersect(node.Value.Bisector, node.Previous.Value.Bisector); } // Find intersection with next bisector // TODO: For some unknown reason the ternary operator does not work for the following expression Point2D?nextIntersection = null; if (node.Next != null) { nextIntersection = Intersector.Intersect(node.Value.Bisector, node.Next.Value.Bisector); } // Find intersection with "opposite" bisector at point B Point2D?oppositeIntersection = null; if (IsReflex(node.Value)) { oppositeIntersection = OppositeIntersection(lav, node.Value); } double?previousDistance2 = previousIntersection.HasValue ? (previousIntersection.Value - node.Value.Bisector.Source).Magnitude2 : (double?)null; double?nextDistance2 = nextIntersection.HasValue ? (nextIntersection.Value - node.Value.Bisector.Source).Magnitude2 : (double?)null; double?oppDistance2 = oppositeIntersection.HasValue ? (oppositeIntersection.Value - node.Value.Bisector.Source).Magnitude2 : (double?)null; if (IsMinimum(previousDistance2, nextDistance2, oppDistance2)) { EnqueuePreviousIntersection(node, previousIntersection.Value); } else if (IsMinimum(nextDistance2, previousDistance2, oppDistance2)) { EnqueueNextIntersection(node, nextIntersection.Value); } else if (IsMinimum(oppDistance2, previousDistance2, nextDistance2)) { EnqueueOppIntersection(node, oppositeIntersection.Value); } }
void AddEdgeEndpointVertices(IEdge edge, Point2D?edgeStart, Point2D?edgeEnd) { if (edgeStart == null || edgeEnd == null) { // should not happen throw new System.Exception("The line between box centers does not intersect the boxes!"); } var startPoint = new RouteVertex(edgeStart.Value.X, edgeStart.Value.Y); startPoint.IsEdgeEndpoint = true; var endPoint = new RouteVertex(edgeEnd.Value.X, edgeEnd.Value.Y); endPoint.IsEdgeEndpoint = true; this.vertices.Add(startPoint); this.vertices.Add(endPoint); // remember what RouteVertices we created for this user edge this.setStartVertex(edge, startPoint); this.setEndVertex(edge, endPoint); }
void AddEdgeEndpointVertices(IEdge edge, Point2D?edgeStart, Point2D?edgeEnd) { if (edgeStart == null || edgeEnd == null) { // should not happen return; } var startPoint = new RouteVertex(edgeStart.Value.X, edgeStart.Value.Y); startPoint.IsEdgeEndpoint = true; var endPoint = new RouteVertex(edgeEnd.Value.X, edgeEnd.Value.Y); endPoint.IsEdgeEndpoint = true; this.vertices.Add(startPoint); this.vertices.Add(endPoint); // remember what RouteVertices we created for this user edge this.setStartVertex(edge, startPoint); this.setEndVertex(edge, endPoint); }
internal void SetControlPoints(string positions) { var splinesBuilder = ImmutableArray.CreateBuilder <ImmutableArray <Point2D> >(); var pointsBuilder = ImmutableArray.CreateBuilder <Point2D>(); var splinesStr = positions.Trim().Split(';'); foreach (var splineStr in splinesStr) { var pointsStr = splineStr.Trim().Split(' '); int index = 0; Point2D?startPoint = null; Point2D?endPoint = null; pointsBuilder.Clear(); foreach (var pointStr in pointsStr) { if (index == 0 && pointStr.StartsWith("s,")) { startPoint = new Point2D(pointStr.Substring(2), GraphLayout.DefaultDpi); } else if (index == 0 && pointStr.StartsWith("e,")) { endPoint = new Point2D(pointStr.Substring(2), GraphLayout.DefaultDpi); } else { pointsBuilder.Add(new Point2D(pointStr, GraphLayout.DefaultDpi)); ++index; } } Debug.Assert(pointsBuilder.Count % 3 == 1); if (startPoint != null) { pointsBuilder[0] = startPoint.Value; } if (endPoint != null) { pointsBuilder[pointsBuilder.Count - 1] = endPoint.Value; } splinesBuilder.Add(pointsBuilder.ToImmutable()); } this.Splines = splinesBuilder.ToImmutable(); }
public Link(Player actor, Player reciever, LinkType type, Direction dir, Point2D?coll) { if (actor == null || reciever == null) { throw new Exception("Players cannot be null"); } if (actor.Team != reciever.Team && type == LinkType.SUPPORTLINK) { Console.WriteLine("Cannot create Supportlink between different teams"); // Occurs if a kill occurs where an enemy hit his teammate so hard that he is registered as assister } if (actor.Team == reciever.Team && type == LinkType.COMBATLINK) { Console.WriteLine("Cannot create Combatlink in the same team"); //Can occur if teamdamage happens. Dman antimates } players = new Player[2]; players[0] = actor; players[1] = reciever; this.type = type; this.dir = dir; this.Collision = coll; }
/// <summary> /// Substitutes consecutive same points with just one instance of that point and filters out undefined points. /// </summary> /// <param name="routePoints">A collection of points.</param> /// <returns>Normalized collection of points.</returns> private static IEnumerable <Point2D> Normalize(IEnumerable <Point2D> routePoints) { if (routePoints == null) { yield break; } Point2D?previousPoint = null; foreach (var routePoint in routePoints.Where(i => i.IsDefined)) { if (routePoint == previousPoint) { continue; } yield return(routePoint); previousPoint = routePoint; } }
public static void IntersectWithIn(this Line2D line, Line2D target, out Point2D?pt) { var ff = line.IntersectWith(target); if (ff.HasValue) { Point2D aa = (Point2D)ff; if (aa.IsLayIn(line) && (aa.IsLayIn(target))) { pt = aa; } else { pt = null; } } else { pt = null; } }
/// <summary> /// Constructs a triangle from the first three points yielded /// by the supplied enumerable. /// </summary> /// <param name="points">A sequence of three points</param> public Triangle2D(IEnumerable <Point2D> points) { using (IEnumerator <Point2D> enumerator = points.GetEnumerator()) { if (!enumerator.MoveNext()) { throw new ArgumentException("points enumerable must contain at least three points"); } a = enumerator.Current; if (!enumerator.MoveNext()) { throw new ArgumentException("points enumerable must contain at least three points"); } b = enumerator.Current; if (!enumerator.MoveNext()) { throw new ArgumentException("points enumerable must contain at least three points"); } c = enumerator.Current; } this.circumcenter = null; }
private void method_0(CanonicalMouseEventArgs e, InteractionContext context) { Point2D point2D = new Point2D(0.5 * context.CanvasRectangle.Size.X, 0.5 * context.CanvasRectangle.Size.Y); Point2D position = e.Position; Vector2D vector2D1 = position - point2D; if (!(vector2D1 != Vector2D.Zero)) { return; } double num1 = System.Math.Atan2(-vector2D1.Y, vector2D1.X); if (this.nullable_0.HasValue) { Vector2D vector2D2 = this.nullable_0.Value - point2D; double num2 = System.Math.Atan2(-vector2D2.Y, vector2D2.X); if (num1 != num2) { this.TransformationProvider.ModelOrientation *= QuaternionD.FromAxisAngle(Vector3D.ZAxis, num1 - num2); } } this.nullable_0 = new Point2D?(position); }