private static int GetExtremePoint(Bitmap image, PointPosition position) { int?result = null; switch (position) { case PointPosition.Top: result = GetTopExtremePoint(image); break; case PointPosition.Bottom: result = GetBottomExtremePoint(image); break; case PointPosition.Left: result = GetLeftExtremePoint(image); break; case PointPosition.Right: result = GetRightExtremePoint(image); break; } return(result ?? throw new ArgumentException(nameof(position))); }
private Operation GetOperation(PointPosition position) { switch (position) { case PointPosition.Inside: return(Operation.Move); case PointPosition.Left: return(Operation.ResizeLeft); case PointPosition.Top: return(Operation.ResizeTop); case PointPosition.Right: return(Operation.ResizeRight); case PointPosition.Bottom: return(Operation.ResizeBottom); case PointPosition.TopLeft: return(Operation.ResizeTopLeft); case PointPosition.TopRight: return(Operation.ResizeTopRight); case PointPosition.BottomRight: return(Operation.ResizeBottomRight); case PointPosition.BottomLeft: return(Operation.ResizeBottomLeft); default: return(Operation.None); } }
private void BeginOperation(int x, int y) { PointPosition position = GetMousePosition(this.selectedSprite.Rectangle, x, y); operation = GetOperation(position); switch (operation) { case Operation.Move: case Operation.ResizeLeft: case Operation.ResizeTop: case Operation.ResizeTopLeft: offsetPoint = new Point(x - selectedSprite.X, y - selectedSprite.Y); break; case Operation.ResizeRight: case Operation.ResizeBottom: case Operation.ResizeBottomRight: offsetPoint = new Point(x - selectedSprite.Right, selectedSprite.Bottom - y); break; case Operation.ResizeTopRight: offsetPoint = new Point(x - selectedSprite.Right, y - selectedSprite.Y); break; case Operation.ResizeBottomLeft: offsetPoint = new Point(x - selectedSprite.X, selectedSprite.Bottom - y); break; } }
private Cursor GetMouseCursor(PointPosition position) { switch (position) { case PointPosition.Top: case PointPosition.Bottom: return(Cursors.SizeNS); case PointPosition.Left: case PointPosition.Right: return(Cursors.SizeWE); case PointPosition.BottomLeft: case PointPosition.TopRight: return(Cursors.SizeNESW); case PointPosition.BottomRight: case PointPosition.TopLeft: return(Cursors.SizeNWSE); case PointPosition.Inside: return(Cursors.SizeAll); default: return(Cursors.Default); } }
protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) { if (sheet != null) { if (operation == Operation.None) { SpriteDefinition sprite = GetSpriteFromMousePoint(e.X, e.Y); if (sprite != null) { PointPosition position = GetMousePosition(sprite.Rectangle, e.X, e.Y); this.Cursor = GetMouseCursor(position); } else { this.Cursor = Cursors.Default; } } else { if (e.Button == MouseButtons.Left) { DoOperation(e.X, e.Y); } } } base.OnMouseMove(e); }
internal PointPosition GetPointPosition(Point point) { PointPosition result = PointPosition.Inside; for (int i = 0; i < _edges.Count && result == PointPosition.Inside; i++) { var testVector = point.VectorTo(_edges[i].Start); var normalInsideVector = GetNormalInsideVectorForEdge(i); double scalarMultiplication = testVector.ScalarMultiplicationWith(normalInsideVector); if (scalarMultiplication > 0) { result = PointPosition.Outside; } else if (Math.Abs(scalarMultiplication) <= _precision) { if (point.IsPointBelongToLine((_edges[i].Start, _edges[i].End))) { result = PointPosition.OnEdge; } else { result = PointPosition.Outside; } } }
public void ReturnsAwaitedResult(double x, double y, PointPosition awaitedResult) { (x, y) = CoordinatesProcessing.UnFlattenCoordinates(x, y, Offset, ScaleValue); var(p, _, _) = CoordinatesProcessing.GetPointPosition(x, y, Offset, ScaleValue); Assert.Equal(awaitedResult, p); }
private void Awake() { _pointPosition = PointPosition.point; check = _pointPosition.position; vector3Enemy = transform.position + Vector3.forward; }
private bool SetLine(List <RaycastResult> result, PointPosition position) { GameObject targetLinePosition = IsOnExecutePoint(result, position); if (targetLinePosition && graphLine) { SetLineData(targetLinePosition.GetComponent <ExecutePoint>()); return(true); } return(false); }
protected GameObject IsOnExecutePoint(List <RaycastResult> rayResults, PointPosition point) { for (int ix = 0; ix < rayResults.Count; ++ix) { if (Util.CompareTwoStrings(rayResults[ix].gameObject.tag, point.ToString())) { return(rayResults[ix].gameObject); } } return(null); }
private bool SetLine(List <RaycastResult> result, PointPosition position) { GameObject targetLinePosition = IsOnExecutePoint(result, position); if (targetLinePosition && graphLine) { linePoint.start = SelfPosition; linePoint.end = targetLinePosition.transform.position; graphLine.SetLinePoint(linePoint); graphLine.SetExecutePoints(this, targetLinePosition.GetComponent <ExecutePoint>()); SetHasLine(true); targetLinePosition.GetComponent <ExecutePoint>().SetHasLine(true); return(true); } return(false); }
protected override void OnMouseDown(MouseEventArgs e) { if (sheet != null) { SpriteDefinition sprite = GetSpriteFromMousePoint(e.X, e.Y); if (sprite != null) { PointPosition position = GetMousePosition(sprite.Rectangle, e.X, e.Y); if (position != PointPosition.Outside) { this.SelectedSprite = sprite; BeginOperation(e.X, e.Y); } } } base.OnMouseDown(e); }
public static bool IsPointInShape(GeoPoint point, List <GeoPoint> shape) { int count = 0; for (int i = 0; i < shape.Count; i++) { PointPosition position = GetPointPosition(point, shape[i], shape[(i + 1) % shape.Count]); switch (position) { case PointPosition.INTERSECT: count++; break; case PointPosition.ON_LINE: case PointPosition.NO_INTERSECT: default: break; } } return(count % 2 == 1); }
private static PointPosition determinePosition(Point beginVector, Point endVector, Point toDetermine, bool isLeftHalf) { // we change answer for right hull to make it esier to analize in other methods // PointPosition.Right -> PointPosition.Left and vise versa if (toDetermine == null) { return(PointPosition.Right); } else { PointPosition answer = Utils.DeterminePosition(beginVector, endVector, toDetermine); if (answer != PointPosition.On) { if (!isLeftHalf) { if (answer == PointPosition.Left) { return(PointPosition.Right); } else { return(PointPosition.Left); } } else { return(answer); } } else { return(PointPosition.Right); } } }
public static RouteDTO PathToRoute(List <RouteFeature> path, PointPosition startPosition, PointPosition endPosition) { var sortedFeatures = SortFeatures(path, startPosition, endPosition); var routeDto = new RouteDTO { Data = new RouteDataDTO { Type = "LineString", Coordinates = sortedFeatures.SelectMany(x => x.Data.Coordinates.Select(y => new[] { y.Longitude, y.Latitude }) .ToArray()).ToArray() }, Info = new RouteInfoDTO { Length = 0 //Length = Math.Round(path.Sum(x => (double) x.Data.Properties["lenght"]), 2) //TODO fix } }; var routeJson = routeDto.ToGeoJson(); var firstFeature = sortedFeatures.First(); var lastFeature = sortedFeatures.Last(); var firstFeatureJson = FeaturesToGeojsonHelper.ToGeojson(new [] { firstFeature.Data.Coordinates.Select(x => x.ToDoubleArray()).ToArray() }); var lastFeatureJson = FeaturesToGeojsonHelper.ToGeojson(new [] { lastFeature.Data.Coordinates.Select(x => x.ToDoubleArray()).ToArray() }); //var distanceToStartFeature = DistanceHelpers.CalcualteDistanceToFeature( // firstFeature.Data.Coordinates.Select(x => x.ToDoubleArray()).ToArray(), startPosition.ToDoubleArray()); var projectionOnStartFeature = DistanceHelpers.GetProjectionOnFeature( firstFeature.Data.Coordinates.Select(x => x.ToDoubleArray()).ToArray(), startPosition.ToDoubleArray()); var distanceToStartProjection = DistanceHelpers.DistanceBetweenCoordinates(projectionOnStartFeature.Item2, startPosition.ToDoubleArray()); if (( distanceToStartProjection != DistanceHelpers.DistanceBetweenCoordinates(startPosition.ToDoubleArray(), firstFeature.Data.Coordinates.First().ToDoubleArray()) && distanceToStartProjection != DistanceHelpers.DistanceBetweenCoordinates(startPosition.ToDoubleArray(), firstFeature.Data.Coordinates.Last().ToDoubleArray()) ) || (distanceToStartProjection == DistanceHelpers.DistanceBetweenCoordinates( startPosition.ToDoubleArray(), firstFeature.Data.Coordinates.Last().ToDoubleArray())) ) { //var projectionResult = DistanceHelpers.GetProjectionOnFeature( // firstFeature.Data.Coordinates.Select(x => x.ToDoubleArray()).ToArray(), // startPosition.ToDoubleArray()); var result = new List <double[]> { projectionOnStartFeature.Item2 }; var index = Array.FindIndex(routeDto.Data.Coordinates, x => x.SequenceEqual(projectionOnStartFeature.Item1.Item1)); result.AddRange(routeDto.Data.Coordinates.Skip(index + 1)); routeDto.Data.Coordinates = result.ToArray(); } var projectionOnEndFeature = DistanceHelpers.GetProjectionOnFeature( lastFeature.Data.Coordinates.Select(x => x.ToDoubleArray()).ToArray(), endPosition.ToDoubleArray()); var distanceToEndProjection = DistanceHelpers.DistanceBetweenCoordinates(projectionOnEndFeature.Item2, endPosition.ToDoubleArray()); if ((distanceToEndProjection != DistanceHelpers.DistanceBetweenCoordinates(endPosition.ToDoubleArray(), lastFeature.Data.Coordinates.First().ToDoubleArray()) && distanceToEndProjection != DistanceHelpers.DistanceBetweenCoordinates(endPosition.ToDoubleArray(), lastFeature.Data.Coordinates.Last().ToDoubleArray())) || (distanceToEndProjection == DistanceHelpers.DistanceBetweenCoordinates( endPosition.ToDoubleArray(), lastFeature.Data.Coordinates.First().ToDoubleArray())) ) { //var projectionResult = DistanceHelpers.GetProjectionOnFeature( // lastFeature.Data.Coordinates.Select(x => x.ToDoubleArray()).ToArray(), endPosition.ToDoubleArray()); var index = Array.FindIndex(routeDto.Data.Coordinates, x => x.SequenceEqual(projectionOnEndFeature.Item1.Item2)); var result = routeDto.Data.Coordinates.Take(index).ToList(); result.Add(projectionOnEndFeature.Item2); routeDto.Data.Coordinates = result.ToArray(); } return(routeDto); }
private static bool makeDecisionAboutRotation(ref Treap <Point> lowerCurrent, ref Point lowerCurrentPoint, Point lowerPrevPoint, Point lowerNextPoint, ref int toCutFromLowerHull, ref Treap <Point> upperCurrent, ref Point upperCurrentPoint, Point upperPrevPoint, Point upperNextPoint, ref int toLeaveInUpperHull, double mediumY, bool isLeftHalf) { PointPosition lowerPrevPos = determinePosition(lowerCurrentPoint, upperCurrentPoint, lowerPrevPoint, isLeftHalf); PointPosition lowerNextPos = determinePosition(lowerCurrentPoint, upperCurrentPoint, lowerNextPoint, isLeftHalf); PointPosition upperPrevPos = determinePosition(lowerCurrentPoint, upperCurrentPoint, upperPrevPoint, isLeftHalf); PointPosition upperNextPos = determinePosition(lowerCurrentPoint, upperCurrentPoint, upperNextPoint, isLeftHalf); if (lowerPrevPos == PointPosition.Right && lowerNextPos == PointPosition.Right && upperPrevPos == PointPosition.Right && upperNextPos == PointPosition.Right) // A - found { return(true); // answer found } else if (lowerPrevPos == PointPosition.Left && lowerNextPos == PointPosition.Right && upperPrevPos == PointPosition.Right && upperNextPos == PointPosition.Right) // B { goLeft(ref lowerCurrent, ref lowerCurrentPoint, ref toCutFromLowerHull); //goRight(ref rightTop, ref rightTopPoint, ref rightMinPoint, ref rightMaxPoint, // ref toLeaveInRightHull, ref minPointLeaveInRight, ref maxPointLeaveInRight); } else if (lowerPrevPos == PointPosition.Right && lowerNextPos == PointPosition.Left && upperPrevPos == PointPosition.Right && upperNextPos == PointPosition.Right) // C { goRight(ref lowerCurrent, ref lowerCurrentPoint, ref toCutFromLowerHull); //goRight(ref rightTop, ref rightTopPoint, ref rightMinPoint, ref rightMaxPoint, // ref toLeaveInRightHull, ref minPointLeaveInRight, ref maxPointLeaveInRight); } else if (lowerPrevPos == PointPosition.Right && lowerNextPos == PointPosition.Right && upperPrevPos == PointPosition.Right && upperNextPos == PointPosition.Left) // D { //goLeft(ref leftTop, ref leftTopPoint, ref leftMinPoint, ref leftMaxPoint, // ref toCutFromLeftHull, ref minPointCutFromLeft, ref maxPointCutFromLeft); goRight(ref upperCurrent, ref upperCurrentPoint, ref toLeaveInUpperHull); } else if (lowerPrevPos == PointPosition.Right && lowerNextPos == PointPosition.Right && upperPrevPos == PointPosition.Left && upperNextPos == PointPosition.Right) // E { //goLeft(ref leftTop, ref leftTopPoint, ref leftMinPoint, ref leftMaxPoint, // ref toCutFromLeftHull, ref minPointCutFromLeft, ref maxPointCutFromLeft); goLeft(ref upperCurrent, ref upperCurrentPoint, ref toLeaveInUpperHull); } else if (lowerPrevPos == PointPosition.Left && lowerNextPos == PointPosition.Right && upperPrevPos == PointPosition.Right && upperNextPos == PointPosition.Left) // F { goLeft(ref lowerCurrent, ref lowerCurrentPoint, ref toCutFromLowerHull); goRight(ref upperCurrent, ref upperCurrentPoint, ref toLeaveInUpperHull); } else if (lowerPrevPos == PointPosition.Left && lowerNextPos == PointPosition.Right && upperPrevPos == PointPosition.Left && upperNextPos == PointPosition.Right) // G { goLeft(ref lowerCurrent, ref lowerCurrentPoint, ref toCutFromLowerHull); } else if (lowerPrevPos == PointPosition.Right && lowerNextPos == PointPosition.Left && upperPrevPos == PointPosition.Right && upperNextPos == PointPosition.Left) // H { goRight(ref upperCurrent, ref upperCurrentPoint, ref toLeaveInUpperHull); } else if (lowerPrevPos == PointPosition.Right && lowerNextPos == PointPosition.Left && upperPrevPos == PointPosition.Left && upperNextPos == PointPosition.Right) // I - the hardest { if (isIntersectLoverY(lowerCurrentPoint, lowerNextPoint, upperCurrentPoint, upperPrevPoint, mediumY, isLeftHalf)) { goRight(ref lowerCurrent, ref lowerCurrentPoint, ref toCutFromLowerHull); } else { goLeft(ref upperCurrent, ref upperCurrentPoint, ref toLeaveInUpperHull); } } else { throw new Exception("something wrong"); } return(false); // answer not found }
private void Start() { point = this; }
private Point GetPoint(PointPosition position, Point first, Point second) { if (position == PointPosition.LeftTop) { return new Point(Math.Min(first.X, second.X), Math.Min(first.Y, second.Y)); } return new Point(Math.Max(first.X, second.X), Math.Max(first.Y, second.Y)); }
//private double[][] SorthPath(IList<double[][]> path) //{ // var tempPat = new List<double[][]>(path); // var lastSubPath = tempPat.First(); // tempPat.Remove(lastSubPath); // IEnumerable<double[]> coordinates = lastSubPath; // while (tempPat.Any()) // { // var newLastSubPath = // tempPat.FirstOrDefault(x => DistanceHelpers.AreClose(x.First(), coordinates.First())); // if (newLastSubPath != null) // { // tempPat.Remove(newLastSubPath); // coordinates = newLastSubPath.Reverse().Concat(coordinates); // continue; // } // newLastSubPath = tempPat.FirstOrDefault(x => DistanceHelpers.AreClose(x.First(), coordinates.Last())); // if (newLastSubPath != null) // { // tempPat.Remove(newLastSubPath); // coordinates = coordinates.Concat(newLastSubPath); // continue; // } // newLastSubPath = tempPat.FirstOrDefault(x => DistanceHelpers.AreClose(x.Last(), coordinates.First())); // if (newLastSubPath != null) // { // tempPat.Remove(newLastSubPath); // coordinates = newLastSubPath.Concat(coordinates); // continue; // } // newLastSubPath = tempPat.FirstOrDefault(x => DistanceHelpers.AreClose(x.Last(), coordinates.Last())); // if (newLastSubPath != null) // { // tempPat.Remove(newLastSubPath); // coordinates = coordinates.Concat(newLastSubPath.Reverse()); // continue; // } // throw new Exception("Something went wrong at path sorting"); // } // if (!coordinates.First().SequenceEqual(path.First().First())) coordinates = coordinates.Reverse(); // return coordinates.ToArray(); //} public static IList <RouteFeature> SortFeatures(List <RouteFeature> path, PointPosition startPosition, PointPosition endPosition) { var tempPat = new List <RouteFeature>(path); var lastSubPath = tempPat.First(); tempPat.Remove(lastSubPath); IEnumerable <RouteFeature> routeFeatures = new List <RouteFeature> { lastSubPath }; while (tempPat.Any()) { var newLastSubPath = tempPat.FirstOrDefault(x => DistanceHelpers.AreClose(x.Data.Coordinates.First().ToDoubleArray(), routeFeatures.First().Data.Coordinates.First().ToDoubleArray())); if (newLastSubPath != null) { tempPat.Remove(newLastSubPath); var result = new List <RouteFeature> { newLastSubPath }; result.AddRange(routeFeatures); newLastSubPath.Data.Coordinates = newLastSubPath.Data.Coordinates.Reverse().ToArray(); routeFeatures = result; continue; } newLastSubPath = tempPat.FirstOrDefault(x => DistanceHelpers.AreClose(x.Data.Coordinates.First().ToDoubleArray(), routeFeatures.Last().Data.Coordinates.Last().ToDoubleArray())); if (newLastSubPath != null) { tempPat.Remove(newLastSubPath); var result = new List <RouteFeature>(); result.AddRange(routeFeatures); result.Add(newLastSubPath); routeFeatures = result; continue; } newLastSubPath = tempPat.FirstOrDefault(x => DistanceHelpers.AreClose(x.Data.Coordinates.Last().ToDoubleArray(), routeFeatures.First().Data.Coordinates.First().ToDoubleArray())); if (newLastSubPath != null) { tempPat.Remove(newLastSubPath); var result = new List <RouteFeature> { newLastSubPath }; result.AddRange(routeFeatures); routeFeatures = result; continue; } newLastSubPath = tempPat.FirstOrDefault(x => DistanceHelpers.AreClose(x.Data.Coordinates.Last().ToDoubleArray(), routeFeatures.Last().Data.Coordinates.Last().ToDoubleArray())); if (newLastSubPath != null) { tempPat.Remove(newLastSubPath); var result = new List <RouteFeature>(); result.AddRange(routeFeatures); result.Add(newLastSubPath); newLastSubPath.Data.Coordinates = newLastSubPath.Data.Coordinates.Reverse().ToArray(); routeFeatures = result; continue; } throw new Exception("Something went wrong at feature sorting"); } if (!routeFeatures.First().Data.Coordinates.First().ToDoubleArray() .SequenceEqual(path.First().Data.Coordinates.First().ToDoubleArray())) { routeFeatures = routeFeatures.Reverse(); foreach (var f in routeFeatures) { f.Data.Coordinates = f.Data.Coordinates.Reverse().ToArray(); } } else if (routeFeatures.Count() == 1) { var projectionStart = DistanceHelpers.GetProjectionOnFeature( routeFeatures.First().Data.Coordinates.Select(x => x.ToDoubleArray()).ToArray(), startPosition.ToDoubleArray()); var projectionEnd = DistanceHelpers.GetProjectionOnFeature( routeFeatures.First().Data.Coordinates.Select(x => x.ToDoubleArray()).ToArray(), endPosition.ToDoubleArray()); var featureSegments = DistanceHelpers.SplitFeatureIntoLineSegments(routeFeatures.First().Data .Coordinates.Select(x => x.ToDoubleArray()).ToArray()); var indexStart = FindIndex(projectionStart.Item1, featureSegments); var indexEnd = FindIndex(projectionEnd.Item1, featureSegments); if (indexEnd < indexStart) { routeFeatures.First().Data.Coordinates = routeFeatures.First().Data.Coordinates.Reverse().ToArray(); } } return(routeFeatures.ToArray()); }
public Poped(Point point, PointPosition branch) { this.Point = point; this.Branch = branch; }