本文整理汇总了C#中Point.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Point.GetLength方法的具体用法?C# Point.GetLength怎么用?C# Point.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point
的用法示例。
在下文中一共展示了Point.GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadTileMap
public void LoadTileMap(SpriteLoader loader, Point[,] mapIndices, int depth)
{
for (int i = 0; i < mapIndices.GetLength(0); ++i)
{
for (int j = 0; i < mapIndices.GetLength(1); ++j)
{
Point tileCoord = mapIndices[i, j];
loader.AddSprite(
Texture,
new Vector2(i * TileWidth, j * TileHeight),
new Rectangle(tileCoord.X * TileWidth, tileCoord.Y * TileHeight, TileWidth, TileHeight),
depth);
}
}
}
示例2: BestFit
public static Line BestFit(Point[] p)
{
int n = p.GetLength(0);
double m = 0.0;
double yi = 0.0;
double sigxy = 0.0;
double sigx = 0.0;
double sigy = 0.0;
double sigxx = 0.0;
foreach (Point q in p)
{
if (q.IsEmpty) { n--; continue; }
sigxy += q.X*q.Y;
sigx += q.X;
sigy += q.Y;
sigxx += q.X*q.X;
}
m = (n*sigxy - sigx*sigy)/(n*sigxx-sigx*sigx);
yi = (sigy-m*sigx)/n;
Line l = new Line(m,yi);
return l;
}
示例3: drawDiagramm
/// <summary>
/// Рисует столбиковую диаграмму
/// </summary>
/// <param name="pbCanvas">Ccылка на объект PictoreBox для рисования</param>
/// <param name="IC">Объект InitialCondition, задающий начальные условия</param>
public static void drawDiagramm(ref PictureBox pbCanvas, utils.InitialConditions IC)
{
Color GlaphColor = Color.FromArgb(Globals.glob_colorRed, Globals.glob_colorGreen, Globals.glob_colorBlue);
Point[] arr = new Point[IC.ctx.Xarr.GetLength(0)];
Point[] zeroVertexes = new Point[IC.ctx.Xarr.GetLength(0)];
Point pCenter = new Point();
pCenter.X = (int)((pbCanvas.Width / (Math.Abs(IC.Xmin) + Math.Abs(IC.Xmax))) * Math.Abs(IC.Xmin));
pCenter.Y = (int)((pbCanvas.Height / (Math.Abs(IC.Ymin) + Math.Abs(IC.Ymax))) * Math.Abs(IC.Ymax));
for (int i = 0; i < IC.ctx.Xarr.GetLength(0); i++)
{
arr[i].X = (int)(pCenter.X + 2 * (IC.ctx.Xarr[i] * IC.scaleX));
zeroVertexes[i].X = arr[i].X;
}
for (int j = 0; j < IC.ctx.Yarr.GetLength(0); j++)
{
arr[j].Y = (int)(pCenter.Y - 2 * (IC.ctx.Yarr[j] * IC.scaleY));
zeroVertexes[j].Y = pCenter.Y;
}
using (Graphics G = pbCanvas.CreateGraphics())
{
using (Pen p = new Pen(GlaphColor))
{
p.Width = 3;
for (int i = 0; i < zeroVertexes.GetLength(0); i++)
{
G.DrawLine(p, arr[i], zeroVertexes[i]);
}
}
}
}
示例4: GetLines
protected Curve GetLines(Point[,] vertexes)
{
var curve = new Curve();
var rows = vertexes.GetLength(0);
var columns = vertexes.GetLength(1);
for (var i = 0; i < rows - 1; i++)
{
for (var j = 0; j < columns - 1; j++)
{
if (i == 0) { SetCurve(curve, i, j, i, j + 1); }
else { SetCurve(curve, i, j, i, j + 1, vertexes); }
if (j == 0) { SetCurve(curve, i, j, i + 1, j); }
else { SetCurve(curve, i, j, i + 1, j, vertexes); }
}
}
for (var i = 0; i < rows - 1; i++) { SetCurve(curve, i, columns - 1, i + 1, columns - 1); }
for (var j = 0; j < columns - 1; j++) { SetCurve(curve, rows - 1, j, rows - 1, j + 1); }
return curve;
}
示例5: plotX
internal void plotX(float[] data, float firstY, float incrementY, Pen p)
{
Point[] pts = new Point[data.GetLength(0)];
for (int i = 0; i < pts.GetLength(0); ++i)
{
pts[i].X = Convert.ToInt32(xScale * (data[i] - minX));
pts[i].Y = Convert.ToInt32(yScale * (firstY + incrementY * i - maxY));
}
lock (this)
{
offScreenG.DrawLines(p, pts);
}
}
示例6: calcPossibleMoves
public List<Point> calcPossibleMoves(Rectangle selectedObject, Canvas gameCanvas, int[] rollResults, Point[,] gridCoordinatesArray, int gridCirclesCount)
{
for (int i = 0; i < rollResults.Length; i++)
{
if (rollResults[i] == 5 || rollResults[i] == 6)
{
playerMovesCount++;
}
}
Point currentPositionCoord = new Point();
currentPositionCoord.X = Canvas.GetLeft(selectedObject) + selectedObject.Width / 2;
currentPositionCoord.Y = Canvas.GetTop(selectedObject) + selectedObject.Height / 2;
Point currentPositionIndex = new Point();
for (int i = 0; i < gridCoordinatesArray.GetLength(0); i++)
{
for (int j = 0; j < gridCoordinatesArray.GetLength(1); j++)
{
if (Math.Abs(currentPositionCoord.X - gridCoordinatesArray[i, j].X) < 1 && Math.Abs(currentPositionCoord.Y - gridCoordinatesArray[i, j].Y) < 1)
{
currentPositionIndex.X = i;
currentPositionIndex.Y = j;
if (j == 0)
{
currentPositionIndex.X = 0;
}
}
}
}
((MainWindow)System.Windows.Application.Current.MainWindow).labelIJ.Content = string.Format("I,J: {0},{1}", currentPositionIndex.X, currentPositionIndex.Y);
for (int i = 0; i < gridCoordinatesArray.GetLength(0); i++)
{
for (int j = 0; j < gridCoordinatesArray.GetLength(1); j++)
{
if ((Math.Abs(j - currentPositionIndex.Y) == 1 && (i - currentPositionIndex.X) == 0) ||
(((Math.Abs(i - currentPositionIndex.X) == 1) || (Math.Abs(i - currentPositionIndex.X) == 15)) && (j - currentPositionIndex.Y) == 0))
{
if (currentPositionIndex.Y % 2 == 0 && currentPositionIndex.X <= i)
{
movePositionsArray.Add(gridCoordinatesArray[i, j]);
}
if (currentPositionIndex.Y % 2 != 0 && currentPositionIndex.X >= i)
{
movePositionsArray.Add(gridCoordinatesArray[i, j]);
}
if (currentPositionIndex.Y == gridCirclesCount)
{
movePositionsArray.Add(gridCoordinatesArray[i, j]);
}
}
}
if (currentPositionIndex == new Point(0, 0))
{
movePositionsArray.Add(gridCoordinatesArray[i, 1]);
}
}
return movePositionsArray;
}
示例7: DrawConnectors
internal static void DrawConnectors(Graphics graphics, Pen pen, Point[] points, Size connectorCapSize, Size maxCapSize, LineAnchor startConnectorCap, LineAnchor endConnectorCap)
{
if (points.GetLength(0) >= 2)
{
GraphicsPath path = null;
float capinset = 0f;
if (startConnectorCap != LineAnchor.None)
{
Point[] pointArray = new Point[] { points[0], points[1] };
int num2 = (pointArray[0].Y == pointArray[1].Y) ? connectorCapSize.Width : connectorCapSize.Height;
num2 += num2 % 2;
num2 = Math.Min(Math.Min(num2, maxCapSize.Width), maxCapSize.Height);
path = GetLineCap(startConnectorCap, num2, out capinset);
if (((path != null) && ((startConnectorCap % LineAnchor.ArrowAnchor) == LineAnchor.None)) && ((pointArray[0].X == pointArray[1].X) || (pointArray[0].Y == pointArray[1].Y)))
{
Matrix transform = graphics.Transform;
graphics.TranslateTransform((float) pointArray[0].X, (float) pointArray[0].Y);
if (pointArray[0].Y == pointArray[1].Y)
{
graphics.RotateTransform((pointArray[0].X < pointArray[1].X) ? 90f : 270f);
}
else
{
graphics.RotateTransform((pointArray[0].Y < pointArray[1].Y) ? 180f : 0f);
}
using (Brush brush = new SolidBrush(pen.Color))
{
graphics.FillPath(brush, path);
graphics.DrawPath(pen, path);
}
graphics.Transform = (transform != null) ? transform : new Matrix();
}
}
GraphicsPath path2 = null;
float num3 = 0f;
if (endConnectorCap != LineAnchor.None)
{
Point[] pointArray2 = new Point[] { points[points.GetLength(0) - 2], points[points.GetLength(0) - 1] };
int num4 = (pointArray2[0].Y == pointArray2[1].Y) ? connectorCapSize.Width : connectorCapSize.Height;
num4 += num4 % 2;
num4 = Math.Min(Math.Min(num4, maxCapSize.Width), maxCapSize.Height);
path2 = GetLineCap(endConnectorCap, num4, out num3);
if (((path2 != null) && ((endConnectorCap % LineAnchor.ArrowAnchor) == LineAnchor.None)) && ((pointArray2[0].X == pointArray2[1].X) || (pointArray2[0].Y == pointArray2[1].Y)))
{
Matrix matrix2 = graphics.Transform;
graphics.TranslateTransform((float) pointArray2[1].X, (float) pointArray2[1].Y);
if (pointArray2[0].Y == pointArray2[1].Y)
{
graphics.RotateTransform((pointArray2[0].X < pointArray2[1].X) ? 270f : 90f);
}
else
{
graphics.RotateTransform((pointArray2[0].Y < pointArray2[1].Y) ? 0f : 180f);
}
using (Brush brush2 = new SolidBrush(pen.Color))
{
graphics.FillPath(brush2, path2);
graphics.DrawPath(pen, path2);
}
graphics.Transform = (matrix2 != null) ? matrix2 : new Matrix();
}
}
if (path != null)
{
CustomLineCap cap = new CustomLineCap(null, path) {
WidthScale = 1f / pen.Width,
BaseInset = capinset
};
pen.CustomStartCap = cap;
}
if (path2 != null)
{
CustomLineCap cap2 = new CustomLineCap(null, path2) {
WidthScale = 1f / pen.Width,
BaseInset = num3
};
pen.CustomEndCap = cap2;
}
graphics.DrawLines(pen, points);
if (path != null)
{
CustomLineCap customStartCap = pen.CustomStartCap;
pen.StartCap = LineCap.Flat;
customStartCap.Dispose();
}
if (path2 != null)
{
CustomLineCap customEndCap = pen.CustomEndCap;
pen.EndCap = LineCap.Flat;
customEndCap.Dispose();
}
}
}
示例8: DrawPolyBezier
public static PathGeometry DrawPolyBezier(Point[] input)
{
PathGeometry pg = new PathGeometry();
PathFigure pf = new PathFigure();
pf.StartPoint = input[0];
PolyBezierSegment pbs = new PolyBezierSegment();
for (int i = 1; i < input.GetLength(0); i++)
pbs.Points.Add(input[i]);
pf.Segments.Add(pbs);
pg.Figures.Add(pf);
return pg;
}
示例9: CatmullRom
public static Point[] CatmullRom(Point[] input)
{
if (input.GetLength(0) < 3)
{
throw new InvalidOperationException();
}
int inputLength = input.GetLength(0);
Point[] ans = new Point[3 * (inputLength - 2) + 4];
ans[0] = input[0];
ans[1] = input[0];
for (int i = 0; i < input.GetLength(0) - 2; i++)
{
Point p1 = input[i];
Point p2 = input[i + 1];
Point p3 = input[i + 2];
Vector v1 = p2 - p3;
Vector v2 = p1 - p3;
double theta = Math.Abs(Vector.AngleBetween(v1, v2));
double h = v1.Length * Math.Sin(theta * Math.PI / 180.0);
double deltai = Math.Sqrt(Math.Pow(v1.Length, 2) - h * h);
Vector v3 = p2 - p1;
double deltai_1 = Math.Sqrt(Math.Pow(v3.Length, 2) - h * h);
Point b3i_1 = p2 - (deltai_1 / (3 * (deltai + deltai_1))) * (p3 - p1);
Point b3i_2 = p2 + (deltai / (3 * (deltai + deltai_1))) * (p3 - p1);
ans[2 + 3 * i] = b3i_1;
ans[2 + 3 * i + 1] = input[i + 1];
ans[2 + 3 * i + 2] = b3i_2;
}
ans[ans.GetLength(0) - 2] = input[inputLength - 1];
ans[ans.GetLength(0) - 1] = input[inputLength - 1];
return ans;
}
示例10: renderSkeleton
/**
* Method for painting the canvas. Leave all the paint stuff to me!
* */
private void renderSkeleton(int frame, Point[,] animData, Boolean scale)
{
// Define parameters for painting:
int scaling = scale ? 200 : 1; // Scale skeleton points
int x = scale ? -(int)RenderWidth / 2 : 0;
int y = scale ? -(int)RenderHeight / 2 : 0;
int inverse = scale ? -1 : 1;
// Do the actual painting:
using (DrawingContext dc = this.drawingGroup.Open())
{
dc.DrawRectangle(Brushes.Black, null, new Rect(x, y, RenderWidth, RenderHeight));
for (int i = 0; i < animData.GetLength(1); i++)
{
Point p = new Point(animData[frame, i].X * scaling, animData[frame, i].Y * scaling * inverse);
// Check for occlusion
if (p.X < x || p.X > RenderWidth || p.Y < y || p.Y > RenderHeight)
continue;
dc.DrawEllipse(Brushes.Green, null, p, JointThickness, JointThickness);
}
}
}
示例11: DrawStructure2
/// <summary>
/// Отрисовка сетки по форме функции
/// </summary>
/// <param name="xMin">Минимальная координата функции по оси X</param>
/// <param name="yMin">Минимальная координата функции по оси Y</param>
/// <param name="xMax">Максимальная координата функции по оси X</param>
/// <param name="yMax">Максимальная координата функции по оси Y</param>
/// <param name="x0">Положение начала координат относительно контейнера по оси X</param>
/// <param name="y0">Положение начала координат относительно контейнера по оси Y</param>
/// <param name="structStep">Шаг сетки</param>
/// <param name="g">Графический контейнер, в котором будет производиться отрисовка</param>
void DrawStructure2(double xMin, double yMin, double xMax, double yMax, int x0, int y0, int structStep, Graphics g)
{
Point[,] structPoints = new Point[(int)(xMax - xMin) / structStep + 1, (int)(yMax - yMin) / structStep + 1]; //точки, по которым производятся вычисления
int pcnt = 0, qcnt = 0; //счетчики
for (double p = xMin; p <= xMax; p += structStep) //в цикле проходим по всем точкам на оси Х
{
qcnt = 0;
for (double q = yMin; q <= yMax; q += structStep) //в цикле проходим по всем точкам на оси Y
{
Point newPoint = GetPoint(p, q); //Вычисляем значение функции в точке (спроецированное на текущую плоскость)
// if (!(newPoint.X <= -x0 || newPoint.Y <= -y0 || newPoint.X > pictureBox1.Width || newPoint.Y > pictureBox1.Height)) //Если функция не вернула ошибку, то:
{
structPoints[pcnt, qcnt] = new Point(x0 + newPoint.X, y0 - newPoint.Y); //добавляем точку в массив для отрисовки
}
qcnt++;
}
pcnt++;
}
List<Point> pointArr = new List<Point>(); //Список точек для отрисовкки
for (int i = 0; i < structPoints.GetLength(0) - 1; i++) //проходим по всем точкам в массиве по оси Х
{
pointArr.Clear(); //Очищаем список точек для отрисовки
for (int j = 0; j < structPoints.GetLength(1) - 1; j++)//проходим по всем точкам в массиве по оси Y
{
if (!(structPoints[i, j].X == 0 && structPoints[i, j].Y == 0))//Если в точке нет ошибки, то
{
pointArr.Add(structPoints[i, j]); //Добавляем точку в список отрисовки
}
}
if (pointArr.Count > 1) //Если список отрисовки создан, то
{
g.DrawCurve(new Pen(netColor, 1), pointArr.ToArray()); //Рисуем кривую по точкам из списка отрисовки
}
}
for (int i = 0; i < structPoints.GetLength(1) - 1; i++)//проходим по всем точкам в массиве по оси Y
{
pointArr.Clear(); //Очищаем список точек для отрисовки
for (int j = 0; j < structPoints.GetLength(0) - 1; j++)//проходим по всем точкам в массиве по оси X
{
if (!(structPoints[j, i].X == 0 && structPoints[j, i].Y == 0))//Если в точке нет ошибки, то
{
pointArr.Add(structPoints[j, i]);//Добавляем точку в список отрисовки
if (pointsCB.Checked) g.DrawString("[" + (structPoints[j, i].X).ToString() + ";" + (structPoints[j, i].Y).ToString() + "]", new Font("Arial", 8f, FontStyle.Regular), new SolidBrush(coordColor), structPoints[j, i]);//Если отмечен соответствующий чекбокс, то рисуем надпись над точкой
}
}
if (pointArr.Count > 1)//Если список отрисовки создан, то
{
g.DrawCurve(new Pen(netColor, 1), pointArr.ToArray());//Рисуем кривую по точкам из списка отрисовки
}
}
}
示例12: IsInsidePolygon
/// <summary>
/// IsInsidePolygon takes a pollygon as an array of points as type Point and determines
/// if a testpoint as type Point is within the polygon
/// </summary>
/// <param name="polygon">array of type Point that defines a polygon</param>
/// <param name="testPoint">a point of type Point to test</param>
/// <returns>True if the point is within the polygon, else false</returns>
public static bool IsInsidePolygon(Point[] polygon, Point testPoint)
{
bool ret = true;
Point p1;
Point p2;
Int32 indx;
double xcross;
Int32 counter = 0;
if (polygon.GetLength(0) < 3)
ret = false; // polygon isn't even a triangle
else
foreach (Point corner in polygon)
if (corner.X == testPoint.X && corner.Y == testPoint.Y)
ret = false; // testPoint is one of the corners
if (!ret) return ret;
p1 = polygon[polygon.GetLength(0) - 1]; // start with last point hence the closing line segment
for (indx = 0; indx < polygon.GetLength(0); indx++)
{
// This algorithm creates a ray from the test point to the right. It counts the
// number of line segments of the polygon that the ray crosses. An even number
// means the test point is outside of the polygon, an odd number means the test
// point is inside the polygon
p2 = polygon[indx];
if (testPoint.Y > System.Math.Min(p1.Y, p2.Y))
if (testPoint.Y <= System.Math.Max(p1.Y, p2.Y))
if (testPoint.X <= System.Math.Max(p1.X, p2.X))
if (p1.Y != p2.Y) // horizontal segments are invalid
{
xcross = (testPoint.Y - p1.Y) * (p2.X - p1.X) / (p2.Y - p1.Y) + p1.X;
if (p1.X == p2.X || testPoint.X <= xcross)
counter++;
}
p1 = p2;
}
ret = (counter % 2 != 0);
return ret;
}
示例13: DrawStructure2
//int howmuchisdone = 0;
void DrawStructure2(int xMin, int yMin, int xMax, int yMax, int x0, int y0, int structStep, Graphics g)
{
Point[,] structPoints = new Point[(xMax - xMin) / structStep + 1, (yMax - yMin) / structStep + 1];
int pcnt = 0, qcnt = 0;
for (double p = xMin; p <= xMax; p += structStep)
{
qcnt = 0;
for (double q = yMin; q <= yMax; q += structStep)
{
// howmuchisdone++;
Point newPoint = GetPoint(p, q);
if (!(newPoint.X < -10000 || newPoint.Y < -10000))
{
structPoints[pcnt, qcnt] = new Point(x0 + newPoint.X, y0 - newPoint.Y);
}
qcnt++;
}
pcnt++;
}
List<Point> pointArr = new List<Point>();
for (int i = 0; i < structPoints.GetLength(0) - 1; i++)
{
pointArr.Clear();
for (int j = 0; j < structPoints.GetLength(1) - 1; j++)
{
if (!structPoints[i, j].IsEmpty)
{
pointArr.Add(structPoints[i, j]);
}
}
if (pointArr.Count > 1)
{
g.DrawCurve(new Pen(netColor, 1), pointArr.ToArray());
}
}
for (int i = 0; i < structPoints.GetLength(1) - 1; i++)
{
pointArr.Clear();
for (int j = 0; j < structPoints.GetLength(0) - 1; j++)
{
if (!structPoints[i, j].IsEmpty)
{
pointArr.Add(structPoints[j, i]);
}
}
if (pointArr.Count > 1)
{
g.DrawCurve(new Pen(netColor, 1), pointArr.ToArray());
}
}
//howmuchisdone = 0;
}
示例14: CheckPointsArray
private Boolean CheckPointsArray(Point[] expected, Point[] actual)
{
Boolean equal = false;
int matches = 0;
int lenght = expected.GetLength(0);
for (int i = 0; i < lenght; i++)
{
if ((expected[i].X == actual[i].X) && (expected[i].Y == actual[i].Y))
{
matches++;
}
}
if (matches == lenght)
{
equal = true;
}
return equal;
}
示例15: DrawPolyBezier
public static PathGeometry DrawPolyBezier(Point[] input)
{
if (input == null)
{
throw new ArgumentNullException("input");
}
if (input.Length == 0)
{
throw new InvalidOperationException();
}
PathGeometry pg = new PathGeometry();
PathFigure pf = new PathFigure();
pf.StartPoint = input[0];
PolyBezierSegment pbs = new PolyBezierSegment();
for (int i = 1; i < input.GetLength(0); i++)
pbs.Points.Add(input[i]);
pf.Segments.Add(pbs);
pg.Figures.Add(pf);
return pg;
}