本文整理汇总了C#中Point.Select方法的典型用法代码示例。如果您正苦于以下问题:C# Point.Select方法的具体用法?C# Point.Select怎么用?C# Point.Select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point
的用法示例。
在下文中一共展示了Point.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMethod1
public void TestMethod1()
{
int nBuildings = 3;
Point[] buildings = new Point[nBuildings];
//buildings[0] = new Point(-5,-3);
//buildings[1] = new Point(-9, 2);
//buildings[2] = new Point(3, -4);
buildings[0] = new Point(1, 2);
buildings[1] = new Point(0, 0);
buildings[2] = new Point(2, 2);
int widthDistance = buildings.Max(_ => _.X) - buildings.Min(_ => _.X);
var average = buildings.Average(_ => _.Y);
var yPos = (long) buildings.Select(p => new Tuple<int, double>(p.Y, Math.Abs(p.Y - average))).OrderBy(_ => _.Item2).First().Item1;
var dist = buildings.Select(p => Math.Abs((p.Y - yPos))).Sum();
var totalDistance = (long)widthDistance + dist;
Assert.AreEqual(4,totalDistance);
}
示例2: OnSpellEffect
protected override void OnSpellEffect(Spell spell)
{
var targetPos = (TilePosition)((TerrainEntity)spell.Targets[0][0]).Position;
Point[] area = new Point[]
{
new Point(1,1),
new Point(-1,-1),
new Point(-1,1),
new Point(1,-1),
new Point(0,0),
new Point(0,1),
new Point(0,-1),
new Point(1,0),
new Point(-1,0)
};
TilePosition[] tileArea = area.Select(pos => new TilePosition(targetPos.Point + pos)).ToArray();
foreach (TilePosition tile in tileArea)
{
var targets = this.World.GetEntities(tile).OfType<UnitEntity>();
foreach (UnitEntity target in targets)
if (target.Module<HealthModule>().IsDead())
{
if (targets.Count() == 1)
{
var unit = new ZombieUnit(this.Owner);
spell.RunAction(new AddEntityAction(unit, tile.GenerateSpawn()));
}
spell.RunAction(new RemoveEntityAction(target));
}
}
}
示例3: Compute
public static Tuple<Point, Vector> Compute(Point[] points)
{
var avgX = points.Select(p => p.X).Average();
var avgY = points.Select(p => p.Y).Average();
var shifted = points.Select(p => p - new Vector(avgX, avgY));
var mvSample = new MultivariateSample(2);
foreach (var p in shifted)
mvSample.Add(p.X, p.Y);
var pca = mvSample.PrincipalComponentAnalysis();
var firstComponentVector = pca.Component(0).NormalizedVector();
return Tuple.Create(
new Point(avgX, avgY),
new Vector(firstComponentVector[0], firstComponentVector[1]));
}
示例4: calculateMedianYCoordinate
private static int calculateMedianYCoordinate(Point[] locations)
{
int[] orderedYCoordinatesOfLocations = locations.Select(location => location.Y).OrderBy(yCoordinate => yCoordinate).ToArray();
int medianIndex = locations.Count() / 2;
int medianY = orderedYCoordinatesOfLocations[medianIndex];
return medianY;
}
示例5: Log
private void Log(Point[] points)
{
var template =
@"Shortest Path Request
Points:
{0}
";
var data = string.Format(template, string.Join("\n", points.Select(p => p.ToString()).ToArray()));
logService.Write(ShortestPath.Core.Domain.Persisted.Log.LogType.SEARCH, data);
}
示例6: SmoothPoints
public static Point[] SmoothPoints(Point[] points, Func<double[], double[]> scalarSmooth)
{
Contract.Requires(points != null);
Contract.Requires(scalarSmooth != null);
Contract.Ensures(Contract.Result<Point[]>() != null);
Contract.Ensures(Contract.Result<Point[]>().Length != points.Length);
var x = points.Select(p => p.X).ToArray();
var y = points.Select(p => p.Y).ToArray();
x = scalarSmooth(x);
y = scalarSmooth(y);
var n = points.Length;
var result =
Enumerable.Range(0, n)
.Select(i => new Point(x[i], y[i]))
.ToArray();
return result;
}
示例7: Send
public void Send(Point[] points)
{
using (var client = new Producer(_router))
{
var messages = points.Select(x =>
{
var pointToString = _formatter.PointToString(x);
return new Message(pointToString);
}).ToArray();
client.SendMessageAsync("InfluxCapacitor", messages).Wait();
}
}
示例8: DrawPolyline
public void DrawPolyline(Point[] points)
{
_canvas.DrawLines(Pens.Black, points.Select(p => GetTranslatedPoint(p))
.Select(p => new PointF((p.X / 200.0f) * zoom, (p.Y / 200.0f) * zoom))
.ToArray());
//var pointsString = new StringBuilder();
//var firstPoint = GetTranslatedPoint(points[0]);
//pointsString.AppendLine("ctx.beginPath();");
//pointsString.AppendLine(string.Format("ctx.moveTo({0}, {1});", firstPoint.X / 1000, -firstPoint.Y / 1000));
//for (int i = 1; i < points.Length; i++)
//{
// var currentPoint = GetTranslatedPoint(points[i]);
// pointsString.AppendLine(string.Format("ctx.lineTo({0}, {1});", currentPoint.X / 1000, -currentPoint.Y / 1000));
//}
//pointsString.AppendLine("ctx.stroke();");
//AppendTextToOutput(pointsString.ToString());
}
示例9: OnSpellEffect
protected override void OnSpellEffect(Spell spell)
{
var targetPos = spell.Controller.Hero.PositionAs<TilePosition>();
Point[] area = new Point[]
{
new Point(1,1),
new Point(-1,-1),
new Point(-1,1),
new Point(1,-1),
new Point(0,1),
new Point(0,-1),
new Point(1,0),
new Point(-1,0)
};
TilePosition[] tileArea = area.Select(pos => new TilePosition(targetPos.Point + pos)).ToArray();
foreach (TilePosition tile in tileArea)
{
var targets = this.World.GetEntities(tile).OfType<UnitEntity>();
foreach (UnitEntity target in targets)
target.Module<AttackModule>().Damage += 2;
}
}
示例10: GetDiamondGeometry
private static Geometry GetDiamondGeometry()
{
Point[] points = new Point[]{
new Point(0, s_itemSize.Height / 2),
new Point(s_itemSize.Width / 2, s_itemSize.Height),
new Point(s_itemSize.Width, s_itemSize.Height / 2),
new Point(s_itemSize.Width / 2, 0)};
PathSegmentCollection psc = new PathSegmentCollection(
points.Select(point => new LineSegment(point, true)).OfType<PathSegment>());
PathFigure pf = new PathFigure(points[0], psc, true);
PathGeometry geometry = new PathGeometry(new PathFigure[] { pf }, FillRule.EvenOdd, null);
return geometry;
}
示例11: PathWithRotation
private string[] PathWithRotation(Point nextRoom, int rotation, Point to, int distance, List<Direction> testedDirections, Point[] rocks)
{
string[] path;
Rotate(nextRoom, rotation);
var direction = nextStepOf(RoomTypeAt(nextRoom), nextRoom.Position);
if (testedDirections.Contains(direction))
{
Console.Error.WriteLine("Exiting room " + nextRoom + " at " + nextRoom.Position + " has already been tested.");
path = null; //Already tested, so short circuit
}
else
{
testedDirections.Add(direction);
//Console.Error.WriteLine("Testing " + nextRoom + " from " + nextRoom.Position + " as tile #" + RoomTypeAt(nextRoom));
if (!IsValidEntry(nextRoom))
{
path = null;
}
else
{
var newRocks = rocks.Select(rock =>
{
var newRock = rock + nextStepOf(RoomTypeAt(rock), rock.Position);
Console.Error.WriteLine("Rock moved from " + rock + " to " + newRock);
return newRock;
}).ToArray();
path = TestPaths(nextRoom, to, distance, newRocks);
}
}
Rotate(nextRoom, 4 - rotation);
return path;
}
示例12: Log
private void Log(Point[] points, bool cacheHit)
{
var template =
@"Road Time Request
Cache:
{0}
Points:
{1}
";
var data = string.Format(template, cacheHit ? "hit" : "miss", string.Join("\n", points.Select(p => p.ToString()).ToArray()));
logService.Write(ShortestPath.Core.Domain.Persisted.Log.LogType.ROAD_TIME_QUERY, data);
}
示例13: foreach
/*public static Point[] Interpolate(Point[] points, float[] xi)
{
var interpolatedvalues = new List<Point>();
points = points.OrderBy(x => x.X).ToArray();
//Assumes inorder enumerables
var i = 0;
foreach (var xValue in xi)
{
while (points[i].X < xValue)
{
i++;
if (i >= points.Length)
break;
}
if (i >= points.Length)
break;
if (Math.Abs(points[i].X - xValue) < Double.Epsilon)
{
interpolatedvalues.Add(points[i]);
}
else
{
var x0 = 0d;
var y0 = 0d;
if (i > 0)
{
x0 = points[i - 1].X;
y0 = points[i - 1].Y;
}
var x1 = points[i].X;
var y1 = points[i].Y;
var yValue = y0 * (xValue - x1) / (x0 - x1) + y1 * (xValue - x0) / (x1 - x0);
interpolatedvalues.Add(new Point(xValue, yValue));
}
}
return interpolatedvalues.OrderBy(x => x.X).ToArray();
}*/
public static Point[] Interpolate(Point[] points, float[] xi)
{
var interpolatedPoints = new Point[xi.Length];
for (var i = 0; i < xi.Length; i++)
{
interpolatedPoints[i] = new Point(xi[i], Interp1(points.Select(x => x.X).ToList(), points.Select(x => x.Y).ToList(), xi[i]));
}
return interpolatedPoints;
}
示例14: FillPolygon
public IDrawingGraphics FillPolygon(Point[] points)
{
this.Graphics.FillPolygon(this.state.CurrentBrush, points.Select((p) => new Point(CalculateX(p.X), CalculateY(p.Y))).ToArray());
return this;
}
示例15: GetPolygon
private static Point[] GetPolygon(Point center, Point[] polygon, double percent)
{
return polygon.
Select(o =>
{
Vector displace = o - center;
displace *= percent;
return center + displace;
}).
ToArray();
}