本文整理汇总了C#中IEnumerable.Min方法的典型用法代码示例。如果您正苦于以下问题:C# IEnumerable.Min方法的具体用法?C# IEnumerable.Min怎么用?C# IEnumerable.Min使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEnumerable
的用法示例。
在下文中一共展示了IEnumerable.Min方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChunkIsStable
protected bool ChunkIsStable(IEnumerable<Point> points)
{
const int maxVariance = 50;
var xVariance = points.Max(p => p.X) - points.Min(p => p.Y);
var yVariance = points.Max(p => p.X) - points.Min(p => p.Y);
return xVariance < maxVariance && yVariance < maxVariance;
}
示例2: ChunkIsStable
protected bool ChunkIsStable(IEnumerable<Zipping.Pair<int, int>> points)
{
const int maxVariance = 50;
var xVariance = points.Max(p => p.First) - points.Min(p => p.First);
var yVariance = points.Max(p => p.Second) - points.Min(p => p.Second);
return xVariance < maxVariance && yVariance < maxVariance;
}
示例3: MinimumOf
public static BoundingBox MinimumOf(IEnumerable<BoundingBox> boxes)
{
decimal northmost = boxes.Max(b => b.North);
decimal southmost = boxes.Min(b => b.South);
decimal eastmost = boxes.Max(b => b.East);
decimal westmost = boxes.Min(b => b.West);
return new BoundingBox { North = northmost, South = southmost, East = eastmost, West = westmost };
}
示例4: OctreeLookup
public OctreeLookup(IEnumerable<float[]> points)
{
tree = new Octree(
points.Max(p => p[0]),
points.Min(p => p[0]),
points.Max(p => p[1]),
points.Min(p => p[1]),
points.Max(p => p[2]),
points.Min(p => p[2]),
points.Count());
foreach (var p in points)
tree.AddNode(p[0], p[1], p[2], p);
}
示例5: SetPlotModelAxes
public void SetPlotModelAxes(
IEnumerable<DataPoint> seriesPoints,
string xAxisTitle, string yAxisTitle)
{
double minXVal = seriesPoints.Min<DataPoint>(dp => dp.X);
double maxXVal = seriesPoints.Max<DataPoint>(dp => dp.X);
double minYVal = seriesPoints.Min<DataPoint>(dp => dp.Y);
double maxYVal = seriesPoints.Max<DataPoint>(dp => dp.Y);
PlotType = PlotType.XY;
SetXAxisForPlotModel(minXVal, maxXVal, xAxisTitle);
SetYAxisForPlotModel(minYVal, maxYVal, yAxisTitle);
}
示例6: MinDate
public static DateTime MinDate(this IEnumerable<DateTime> left, IEnumerable<DateTime> right)
{
var minLeft = left.Any() ? left.Min() : DateTime.MaxValue;
var minRight = right.Any() ? right.Min() : DateTime.MaxValue;
return minLeft.Ticks < minRight.Ticks ? minLeft : minRight;
}
示例7: Normalize
public static IEnumerable<double> Normalize(IEnumerable<double> collection)
{
double min = collection.Min();
double max = collection.Max();
return collection.Select(f => Normalize(f, min, max));
}
示例8: Calculate
public static VehicleStatisticsModel Calculate(IEnumerable<Model.FillupEntry> fillUps, bool includeFirst = true)
{
if (!fillUps.Any()) return new VehicleStatisticsModel();
var firstFillUp = fillUps.OrderBy(x => x.Date).FirstOrDefault();
double totalFuelCost = 0.0;
double totalUnits = 0.0;
double totalCost = 0.0;
int totalDistance = 0;
foreach (var fillUp in fillUps)
{
if (includeFirst || fillUp != firstFillUp)
{
totalFuelCost += fillUp.PricePerUnit*fillUp.TotalUnits;
totalUnits += fillUp.TotalUnits;
totalCost += fillUp.TotalCost;
totalDistance += fillUp.Distance ?? 0;
}
}
var odometer = fillUps.Max(x => x.Odometer);
var earliestEntryDate = fillUps.Min(x => x.Date).ToUniversalTime();
var today = DateTime.UtcNow.Date;
var totalMonths = CalculateDifferenceInMonths(earliestEntryDate.Date, today.Date);
return new VehicleStatisticsModel(totalFuelCost, totalUnits, totalCost, totalDistance, odometer, totalMonths);
}
示例9: GetArea
/// <summary>
/// Gets area that's occupied by user selected points
/// </summary>
/// <param name="selector">Selected points container</param>
/// <param name="maxWorkingArea">Minimum allowed area size</param>
/// <returns></returns>
public static System.Drawing.Rectangle GetArea(IEnumerable<PointSelector.SelectedPoint> selector, int workingAreaSize)
{
var minX = selector.Min(p => p.Location.X);
var maxX = selector.Max(p => p.Location.X);
var minY = selector.Min(p => p.Location.Y);
var maxY = selector.Max(p => p.Location.Y);
int areaWidth = maxX - minX;
int areaHeight = maxY - minY;
areaWidth = areaWidth > workingAreaSize ? workingAreaSize : areaWidth;
areaWidth = areaHeight > workingAreaSize ? workingAreaSize : areaHeight;
if (areaWidth < workingAreaSize)
{
minX = minX - (workingAreaSize - areaWidth) / 2;
minX = minX < 0 ? 0 : minX;
areaWidth = workingAreaSize;
}
if (areaHeight < workingAreaSize)
{
minY = minY - (workingAreaSize - areaHeight) / 2;
minY = minY < 0 ? 0 : minY;
areaHeight = workingAreaSize;
}
return new System.Drawing.Rectangle(minX, minY, areaWidth, areaHeight);
}
示例10: Play
public IEnumerable<Card> Play(IEnumerable<Card> hand, IEnumerable<Card> table, int rank, Suit suit, Mode mode, bool revolution, History history)
{
if (revolution && rank != Card.RankOfJoker)
{
rank = 14 - rank;
}
if (hand == null || hand.Count() == 0)
return null;
int count = table.Count();
// 初手はとりあえず一番弱いのを出しとく。
if (mode.Match(Mode.First))
{
var min = hand.Min(x => Game.Rank(x, revolution));
return hand.Where(x => Game.Rank(x, revolution) == min);
}
if (mode.Match(Mode.Normal))
{
if(mode.Match(Mode.SuitBound))
{
return hand.MinCard(x => Game.Rank(x, revolution) > rank && x.Suit == suit, revolution);
}
else
{
return hand.MinCard(x => Game.Rank(x, revolution) > rank, revolution);
}
}
if(mode.Match(Mode.Multiple))
{
for (int i = rank + 1; i <= 13; i++)
{
// 出せる
var c = hand.Where(x => Game.Rank(x, revolution) == i);
if (c.Count() >= count)
return c.Take(count);
// Joker含めれば出せる
if (c.Count() + 1 == count && hand.FirstOrDefault(x => x.Suit == Suit.Joker) != null)
return c.Concat(hand.Where(x => x.Suit == Suit.Joker).Take(count));
}
}
if (mode.Match(Mode.SequenceBound))
return null; //todo また未対応
if (mode.Match(Mode.Sequence))
{
if (mode.Match(Mode.SuitBound))
return hand.Sequence(rank, revolution, count, suit);
else
return hand.Sequence(rank, revolution, count);
}
return null;
}
示例11: ConvertToAst
public List<ILNode> ConvertToAst(List<Instruction> body, IEnumerable<ExceptionHandler> ehs)
{
List<ILNode> ast = new List<ILNode>();
while (ehs.Any()) {
ILTryCatchBlock tryCatchBlock = new ILTryCatchBlock();
// Find the first and widest scope
int tryStart = ehs.Min(eh => eh.TryStart.Offset);
int tryEnd = ehs.Where(eh => eh.TryStart.Offset == tryStart).Max(eh => eh.TryEnd.Offset);
var handlers = ehs.Where(eh => eh.TryStart.Offset == tryStart && eh.TryEnd.Offset == tryEnd).ToList();
// Cut all instructions up to the try block
{
int tryStartIdx;
for (tryStartIdx = 0; body[tryStartIdx].Offset != tryStart; tryStartIdx++);
ast.AddRange(ConvertToAst(body.CutRange(0, tryStartIdx)));
}
// Cut the try block
{
List<ExceptionHandler> nestedEHs = ehs.Where(eh => (tryStart <= eh.TryStart.Offset && eh.TryEnd.Offset < tryEnd) || (tryStart < eh.TryStart.Offset && eh.TryEnd.Offset <= tryEnd)).ToList();
int tryEndIdx;
for (tryEndIdx = 0; tryEndIdx < body.Count && body[tryEndIdx].Offset != tryEnd; tryEndIdx++);
tryCatchBlock.TryBlock = ConvertToAst(body.CutRange(0, tryEndIdx), nestedEHs);
}
// Cut all handlers
tryCatchBlock.CatchBlocks = new List<ILTryCatchBlock.CatchBlock>();
foreach(ExceptionHandler eh in handlers) {
int start;
for (start = 0; body[start] != eh.HandlerStart; start++);
int end;
for (end = 0; body[end] != eh.HandlerEnd; end++);
int count = end - start;
List<ExceptionHandler> nestedEHs = ehs.Where(e => (start <= e.TryStart.Offset && e.TryEnd.Offset < end) || (start < e.TryStart.Offset && e.TryEnd.Offset <= end)).ToList();
List<ILNode> handlerAst = ConvertToAst(body.CutRange(start, count), nestedEHs);
if (eh.HandlerType == ExceptionHandlerType.Catch) {
tryCatchBlock.CatchBlocks.Add(new ILTryCatchBlock.CatchBlock() {
ExceptionType = eh.CatchType,
Body = handlerAst
});
} else if (eh.HandlerType == ExceptionHandlerType.Finally) {
tryCatchBlock.FinallyBlock = handlerAst;
} else {
// TODO
}
}
ehs = ehs.Where(eh => eh.TryStart.Offset > tryEnd).ToList();
ast.Add(tryCatchBlock);
}
// Add whatever is left
ast.AddRange(ConvertToAst(body));
return ast;
}
示例12: GetTarget
public override Character GetTarget(IEnumerable<Character> targetsList)
{
Character target = targetsList
.Where(t => t.Team == this.Team && t.IsAlive == true && t.Id != this.Id)
.FirstOrDefault(t => t.HealthPoints == targetsList.Min(h => h.HealthPoints));
return target;
}
示例13: PerfIteratorResult
public PerfIteratorResult(IEnumerable<PerfRoundResult> resultsList)
{
this.ResultsList = resultsList;
this.RepeatCount = resultsList.Count();
this.OverallAverageTicks = resultsList.Average(r => r.AverageTicks);
this.OverallMaxTicks = resultsList.Max(r => r.MaxTicks);
this.OverallMinTicks = resultsList.Min(r => r.MinTicks);
}
示例14: ConfigureParameters
protected void ConfigureParameters(IEnumerable<double> data) {
double originalRangeStart = data.Min();
double originalRangeEnd = data.Max();
double originalRangeWidth = originalRangeEnd - originalRangeStart;
double targetRangeWidth = Range.End - Range.Start;
Multiplier = targetRangeWidth / originalRangeWidth;
Addend = Range.Start - originalRangeStart * Multiplier;
}
示例15: FromPoints
/// <summary>
/// Creates a Polyline from a list of points and calculates the lines and bounds of the result
/// </summary>
/// <param name="points">The list of points that define the polyline</param>
/// <returns>a Polyline object</returns>
public static Polyline FromPoints(IEnumerable<Point> points)
{
Polyline poly = new Polyline();
poly.Points = points.ToArray();
if (poly.Points.Length > 1) {
poly.Lines = new Line[poly.Points.Length - 1];
for (int i = 0; i < poly.Lines.Length; i++) {
poly.Lines[i] = Line.FromPoints(
new Vector2(poly.Points[i].X, poly.Points[i].Y),
new Vector2(poly.Points[i + 1].X, poly.Points[i + 1].Y));
}
}
poly.Bounds.X = points.Min(x => x.X);
poly.Bounds.Y = points.Min(x => x.Y);
poly.Bounds.Width = points.Max(x => x.X) - points.Min(x => x.X);
poly.Bounds.Height = points.Max(x => x.Y) - points.Min(x => x.Y);
return poly;
}