public EnemyShip(IGridSquare seedSquare, EnemyBoard enemyBoard) { maxSize = enemyBoard.GetActiveShipMaxSize(); sizeDetected = 1; seed = Utils.ConvertGridSquareToPoint(seedSquare); bool addDown = true; bool addRight = true; bool addUp = true; bool addLeft = true; possibleTilesAroundSeed = new List <Point>(); for (int dist = 1; dist <= 4; dist++) { Point down = seed.Plus(new Point(0, dist)); if (IsPointOnGrid(down) && enemyBoard.IsTestedSquare(down)) { addDown = false; } if (addDown && IsPointOnGrid(down)) { possibleTilesAroundSeed.Add(down); } Point right = seed.Plus(new Point(dist, 0)); if (IsPointOnGrid(right) && enemyBoard.IsTestedSquare(right)) { addRight = false; } if (addRight && IsPointOnGrid(right)) { possibleTilesAroundSeed.Add(right); } Point up = seed.Plus(new Point(0, -dist)); if (IsPointOnGrid(up) && enemyBoard.IsTestedSquare(up)) { addUp = false; } if (addUp && IsPointOnGrid(up)) { possibleTilesAroundSeed.Add(up); } Point left = seed.Plus(new Point(-dist, 0)); if (IsPointOnGrid(left) && enemyBoard.IsTestedSquare(left)) { addLeft = false; } if (addLeft && IsPointOnGrid(left)) { possibleTilesAroundSeed.Add(left); } } }
public List <Point> GetRotatedPoints() { List <Point> points = new List <Point> (); foreach (Point rotatedPosition in rotatedPositions) { points.Add(origin.Plus(rotatedPosition)); } return(points); }
static FrameworkElement SetCurrentShift(object sender, MouseEventArgs e) { FrameworkElement draggedElement = (FrameworkElement)sender; FrameworkElement attachedToElement = GetAttachedToElement(draggedElement); FrameworkElement dragContainerElement = GetDragContainerElement(attachedToElement); Point currentPosition = e.GetPosition(dragContainerElement); Point startPosition = GetStartDragPoint(attachedToElement); Point shift = currentPosition.Minus(startPosition); Point initialElementPoint = GetStartElementPoint(attachedToElement); Point totalShift = shift.Plus(initialElementPoint); Point startBoundaryPoint = GetStartBoundaryPoint(attachedToElement); Point endBoundaryPoint = GetEndBoundaryPoint(attachedToElement); Point initialElementPointWithRespectToContainer = GetStartLocationWithinContainerElement(attachedToElement); Point totalShiftWithRespectToContainer = shift.Plus(initialElementPointWithRespectToContainer); if ((!startBoundaryPoint.Equals(DefaultStartBoundary)) || (!endBoundaryPoint.Equals(DefaultEndBoundary))) { Rect boundary = new Rect ( startBoundaryPoint.X, startBoundaryPoint.Y, endBoundaryPoint.X - startBoundaryPoint.X, endBoundaryPoint.Y - startBoundaryPoint.Y); Point updateVector = totalShiftWithRespectToContainer.BoundaryUpdate(boundary); totalShiftWithRespectToContainer = totalShiftWithRespectToContainer.Plus(updateVector); totalShift = totalShift.Plus(updateVector); } SetTotalShiftWithRespectToContainer(attachedToElement, totalShiftWithRespectToContainer); SetShift(attachedToElement, totalShift); SetIsDragOn(attachedToElement, true); return(draggedElement); }
/// <summary> /// vytvori oblouk zadany pocatecnim bodem, vektorem ve kterm je koncovy bod a zdvihem v poloine usecky /// </summary> /// <param name="pt1">pocatecni bod oblouku</param> /// <param name="v">vektor udavajici koncovy bod oblouky</param> /// <param name="elevation">zdvih oblouku v polovine usecky [pt1,v]</param> /// <returns></returns> public static Arc2D Arc2DElevation(Point pt1, Vector v, double elevation) { Point pt2, pt3 = pt1.Plus(v); pt2 = Funcs2D.PointOnLineLen(Funcs2D.PointOnLine(pt1, v, 0.5), Funcs2D.VectorNormal(v), elevation); return(new Arc2D(pt1, pt2, pt3)); }
public static ParallelResult ParallelCheck( Point pta, Vector da, //bod a vektor prvni primky Point ptb, Vector db, //bod a vektor druhe primky out Point retRel, // vraci relativni souradnice ( x = begin, y = end) na prvni primce out bool direct) // smer vektoru primek, true stejny smer, false opacny smer { retRel = new Point(); direct = false; var rr = Funcs2D.IsParallel(da, db); if (rr == 0) { return(ParallelResult.Nothing); } direct = rr > 0; retRel.X = Funcs2D.PointToLine(pta, da, ptb); retRel.Y = Funcs2D.PointToLine(pta, da, ptb.Plus(db)); if (Funcs2D.IsThreePointsOnLine(pta, pta.Plus(da), ptb)) { return(ParallelResult.ParallelOn); } else { return(ParallelResult.ParallelOut); } }
public void Displace(Point displacement) { foreach (Block block in blocks) { block.Position = displacement.Plus(block.Position); } origin = Point.Sum(origin, displacement); }
private void StepsOnVektor(Point pStart, Point pEnd, int stepsHorizontal, int i, out Point pOrig, out Point pResult) { Point vektor = pStart.Minus(pEnd); var temp = vektor.Multiply(i); int distance = (int)pStart.Distance(pEnd); pResult = temp.Divided(stepsHorizontal); pOrig = pStart.Plus(pResult); }
public static void SumUp(DependencyObject sender, DependencyPropertyChangedEventArgs e) { Point initShift = GetInitialShift(sender); Point initUpdateShift = GetInitUpdateShift(sender); Point shift = GetShift(sender); Point totalShift = initShift.Plus(shift).Plus(initUpdateShift); SetTotalShift(sender, totalShift); }
public void plus_method_correct(int x1, int y1, int x2, int y2) { Point p1 = new Point(x1, y1); Point p2 = new Point(x2, y2); Point p3 = p1.Plus(p2); Assert.AreNotSame(p3, p1); Assert.AreNotSame(p3, p2); Assert.AreEqual(p3.X, x1 + x2); Assert.AreEqual(p3.Y, y1 + y2); }
public List <Point> GetDisplacedPoints(Point displacement) { List <Point> points = new List <Point> (); foreach (Block block in Blocks) { points.Add(displacement.Plus(block.Position)); } return(points); }
private Point getCardLocation(int i, int j, Point alignmentShift) { var cardInterval = LayoutOptions.CardInterval; var result = new Point( cardInterval.Width / 2 + i * (CardSize.Width + cardInterval.Width), cardInterval.Height / 2 + j * (CardSize.Height + cardInterval.Height)); result = result.Plus(alignmentShift); return(result); }
public List <Block> CreateBlocksWithOrigin(Point origin) { List <Block> blocks = new List <Block> (); foreach (Point relativePosition in blockPositions) { Point absolutePosition = origin.Plus(relativePosition); Block block = Block.CreateFromPrototype(spritePrototype, absolutePosition); blocks.Add(block); } return(blocks); }
public static Point Midpoint(this IEnumerable <Point> points) { Point[] array = points.ToArray(); if (array == null || array.Length == 0) { return(new Point()); } Point sum = new Point(); foreach (var point in array) { sum = sum.Plus(point); } return(sum.Scale(1.0 / array.Length)); }
public object Convert ( object[] values, Type targetType, object parameter, CultureInfo culture) { Point result = new Point(); if (values == null) { return(result); } foreach (object obj in values) { if (obj is Point p) { result = result.Plus(p); } } return(result); }
public static Point Minus(this Point p1, Point p2) { return(p1.Plus(p2.Negative())); }
private void RenderHex(DrawingContext dc, Point c, bool firstLine) { dc.DrawLine(hexPen, c.Plus(-a / 2.0, r), c.Plus(a / 2.0, r)); dc.DrawLine(hexPen, c.Plus(a / 2.0, r), c.Plus(a, 0)); dc.DrawLine(hexPen, c.Plus(a, 0), c.Plus(a / 2.0, -r)); if (firstLine) dc.DrawLine(hexPen, c.Plus(a / 2.0, -r), c.Plus(-a / 2.0, -r)); dc.DrawLine(hexPen, c.Plus(-a / 2.0, -r), c.Plus(-a, 0)); dc.DrawLine(hexPen, c.Plus(-a, 0), c.Plus(-a / 2.0, r)); }
//Update It! private Point GetHexInWorldFromScreen(Point pointOnScreen) { var worldPoint = ToWorldPoint(pointOnScreen); var x = Math.Ceiling(worldPoint.X / (3.0 * real_a)) * 3 * real_a; var y = Math.Ceiling(worldPoint.Y / (2.0 * real_r)) * 2 * real_r; if (Math.Abs(x - worldPoint.X) > real_a) x -= 3 * real_a; if (Math.Abs(y - worldPoint.Y) > real_r) y -= 2 * real_r; var hexCenter = new Point(x, y); double minR = worldPoint.Minus(hexCenter).Abs(); if (minR > real_r * 1.025) { double minAlfa = 0; for (double alfa = 0; alfa <= Math.PI * 2; alfa += Math.PI / 3.0) { double tryR = hexCenter.Plus(2 * real_r * Math.Sin(alfa), 2 * real_r * Math.Cos(alfa)).Minus(worldPoint).Abs(); if (tryR < minR) { minR = tryR; minAlfa = alfa; } } hexCenter = hexCenter.Plus(2 * real_r * Math.Sin(minAlfa), 2 * real_r * Math.Cos(minAlfa)); } return hexCenter; }
void m_traiterBoutonVisu(object sender, EventArgs e) { Button v_button = new Button(); try { v_button = (Button)sender; switch (v_button.Name) { case "bVisuGauche": v_decalageVisu = v_decalageVisu.Plus(-50, 0); break; case "bVisuDroite": v_decalageVisu = v_decalageVisu.Plus(50, 0); break; case "bVisuHaut": v_decalageVisu = v_decalageVisu.Plus(0, 50); break; case "bVisuBas": v_decalageVisu = v_decalageVisu.Plus(0, -50); break; case "bVisuLoupePlus": v_echelleVisu++; break; case "bVisuLoupeMoins": if (v_echelleVisu > 1) { v_echelleVisu--; } break; } lEchelle.Text = v_echelleVisu.ToString(); m_dessinerVisu(); } catch { } }
public Rectangle MoveTo(Point absolute) { return new Rectangle(absolute, absolute.Plus(_max.Minus(_min))); }
public static void ArcToBezier(double xStart, double yStart, double xRadius, double yRadius, double rRotation, bool fLargeArc, bool fSweepUp, double xEnd, double yEnd, out Point[] pPt, out int cPieces) { var num = 1E-06; pPt = new Point[12]; var num12 = num * num; var flag = false; cPieces = -1; var num2 = 0.5 * (xEnd - xStart); var num3 = 0.5 * (yEnd - yStart); var num4 = num2 * num2 + num3 * num3; if (num4 >= num12) { if (!AcceptRadius(num4, num12, ref xRadius) || !AcceptRadius(num4, num12, ref yRadius)) { cPieces = 0; } else { double num5; double num6; // ReSharper disable once InlineOutVariableDeclaration double num7; // ReSharper disable once InlineOutVariableDeclaration double num8; double num9; double num10; Point point4; if (Math.Abs(rRotation) < num) { num5 = 1.0; num6 = 0.0; } else { rRotation = -rRotation * 3.1415926535897931 / 180.0; num5 = Math.Cos(rRotation); num6 = Math.Sin(rRotation); var num15 = num2 * num5 - num3 * num6; num3 = num2 * num6 + num3 * num5; num2 = num15; } num2 /= xRadius; num3 /= yRadius; num4 = num2 * num2 + num3 * num3; if (num4 > 1.0) { var num16 = Math.Sqrt(num4); xRadius *= num16; yRadius *= num16; num9 = num10 = 0.0; flag = true; num2 /= num16; num3 /= num16; } else { var num17 = Math.Sqrt((1.0 - num4) / num4); if (fLargeArc != fSweepUp) { num9 = -num17 * num3; num10 = num17 * num2; } else { num9 = num17 * num3; num10 = -num17 * num2; } } var ptStart = new Point(-num2 - num9, -num3 - num10); var ptEnd = new Point(num2 - num9, num3 - num10); var matrix = new Matrix(num5 * xRadius, -num6 * xRadius, num6 * yRadius, num5 * yRadius, 0.5 * (xEnd + xStart), 0.5 * (yEnd + yStart)); if (!flag) { matrix.OffsetX += matrix.M11 * num9 + matrix.M21 * num10; matrix.OffsetY += matrix.M12 * num9 + matrix.M22 * num10; } GetArcAngle(ptStart, ptEnd, fLargeArc, fSweepUp, out num7, out num8, out cPieces); var bezierDistance = GetBezierDistance(num7); if (!fSweepUp) { bezierDistance = -bezierDistance; } var rhs = new Point(-bezierDistance * ptStart.Y, bezierDistance * ptStart.X); var index = 0; pPt = new Point[cPieces * 3]; for (var i = 1; i < cPieces; i++) { var lhs = new Point(ptStart.X * num7 - ptStart.Y * num8, ptStart.X * num8 + ptStart.Y * num7); point4 = new Point(-bezierDistance * lhs.Y, bezierDistance * lhs.X); pPt[index++] = matrix.Transform(ptStart.Plus(rhs)); pPt[index++] = matrix.Transform(lhs.Minus(point4)); pPt[index++] = matrix.Transform(lhs); ptStart = lhs; rhs = point4; } point4 = new Point(-bezierDistance * ptEnd.Y, bezierDistance * ptEnd.X); pPt[index++] = matrix.Transform(ptStart.Plus(rhs)); pPt[index++] = matrix.Transform(ptEnd.Minus(point4)); pPt[index] = new Point(xEnd, yEnd); } } }
public Rectangle MoveTo(Point absolute) { return(new Rectangle(absolute, absolute.Plus(_max.Minus(_min)))); }
private void paintValueHint(PaintEventArgs e) { if (Properties == null) { return; } var command = getCommand(_mouseLocation.X, _mouseLocation.Y, MouseButtons.None); if (!command.HasValue) { return; } var property = Properties[command.Value.ButtonIndex]; if (string.IsNullOrEmpty(property)) { return; } var font = Font; var border = Border; var location = getPaintingRectangle(command.Value.ButtonIndex, command.Value.ClickedState) .Location; var textSize = e.Graphics.MeasureText(property, font); bool rotateText = IsVertical && textSize.Width > Width; int x; int y; if (IsVertical) { if (rotateText) { x = HintTextShift.Height + location.Y + ImageSize.Height + border; y = -(HintTextShift.Width + location.X + ImageSize.Width - (ImageSize.Width - font.Height) / 2); } else { x = HintTextShift.Width + location.X; y = HintTextShift.Height + location.Y + ImageSize.Height + border; } } else { x = HintTextShift.Width + location.X + ImageSize.Width + border; y = HintTextShift.Height + location.Y + (ImageSize.Height - font.Height) / 2; } if (rotateText) { if (x < 0) { x = 0; } else if (x + textSize.Width > Height) { x = Height - textSize.Width; } if (-y < 0) { y = 0; } else if (-(y + textSize.Height) > Width) { y = -(Width - textSize.Height); } } else { if (x < 0) { x = 0; } else if (x + textSize.Width > Width) { x = Width - textSize.Width; } if (y < 0) { y = 0; } else if (y + textSize.Height > Height) { y = Height - textSize.Height; } } if (rotateText) { e.Graphics.RotateTransform(90f); } var textLocation = new Point(x, y); if (HintIcon != null) { e.Graphics.DrawImage(HintIcon, textLocation.Plus(HintIconShift).Minus(HintTextShift)); } e.Graphics.DrawText(property, font, Color.Black, Color.White, 1f, 3f, new Rectangle(textLocation, textSize)); if (rotateText) { e.Graphics.RotateTransform(-90f); } }
public override void MoveToCore(Point newPosition) { base.MoveToCore(newPosition.Plus(0.2)); }
public static double AngleTo(this Point center, Point point) { return(Math.OAngle(center.Plus(new Point(10, 0)), center, point)); }