本文整理汇总了C#中Tuple.Any方法的典型用法代码示例。如果您正苦于以下问题:C# Tuple.Any方法的具体用法?C# Tuple.Any怎么用?C# Tuple.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tuple
的用法示例。
在下文中一共展示了Tuple.Any方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NNResultsVisual
public NNResultsVisual(double width, double height, Tuple<Point, double, bool>[] values, bool shouldOutlineNonMatches)
{
#region Min/Max Value, Colors
bool hasNegative = values.Any(o => o.Item2 < 0);
double maxValue = Math.Max(Math.Abs(values.Min(o => o.Item2)), Math.Abs(values.Max(o => o.Item2)));
if (maxValue < 1d) // should never be greater, but leave alone if it is
{
maxValue = 1d;
}
Color positiveColor = hasNegative ? Colors.Blue : Colors.Black;
Color negativeColor = Colors.Red;
#endregion
#region XY Scale
double radius = ((width + height) / 2) / 100;
bool hasNegativePosition = values.Any(o => o.Item1.X < 0 || o.Item1.Y < 0);
double maxX = Math.Max(Math.Abs(values.Min(o => o.Item1.X)), Math.Abs(values.Max(o => o.Item1.X)));
double maxY = Math.Max(Math.Abs(values.Min(o => o.Item1.Y)), Math.Abs(values.Max(o => o.Item1.Y)));
// If they are somewhat near 1, then cap at 1
if (maxX > .5 && maxX < 1) maxX = 1;
if (maxY > .5 && maxY < 1) maxY = 1;
double offsetX = hasNegativePosition ? (width / 2) : 0;
double offsetY = hasNegativePosition ? (height / 2) : 0;
double scaleX = maxX > 0d ? (width - offsetX) / maxX : 1;
double scaleY = maxY > 0d ? (height - offsetY) / maxY : 1;
#endregion
Pen matchPen = new Pen(Brushes.Lime, radius * .32);
Pen otherPen = shouldOutlineNonMatches ? new Pen(new SolidColorBrush(Color.FromArgb(192, 192, 192, 192)), radius * .18) : null;
_visual = new DrawingVisual();
using (DrawingContext dc = _visual.RenderOpen())
{
foreach (var value in values)
{
Color color = value.Item2 < 0 ? negativeColor : positiveColor;
double alpha = Math.Abs(value.Item2) / maxValue;
Color finalColor = Color.FromArgb(Convert.ToByte(alpha * 255), color.R, color.G, color.B);
Point point = new Point(offsetX + (value.Item1.X * scaleX), offsetY + (value.Item1.Y * scaleY));
Pen pen = value.Item3 ? matchPen : otherPen;
dc.DrawEllipse(new SolidColorBrush(finalColor), pen, point, radius, radius);
}
}
}
示例2: SetValues
public static void SetValues(Object instance, Tuple<string, object>[] properties)
{
if (instance == null) return;
if (properties == null || !properties.Any()) return;
foreach (var property in properties)
{
SetValue(instance, property);
}
}
示例3: IsAdditionalControllerAction
private static bool IsAdditionalControllerAction(HtmlHelper htmlHelper, string areaName,
Tuple<string, string>[] additionalActiveControllerActionNames)
{
if (additionalActiveControllerActionNames == null || additionalActiveControllerActionNames.Length == 0)
{
return false;
}
return additionalActiveControllerActionNames.Any(t =>
TokenMatches(htmlHelper, areaName, "area")
&& ValueMatches(htmlHelper, t.Item1, "controller")
&& ValueMatches(htmlHelper, t.Item2, "action"));
}
示例4: GetAccepHeaderTraceLog
private static void GetAccepHeaderTraceLog(
NancyContext context,
NegotiationContext negotiationContext,
Tuple<string, decimal>[] coercedAcceptHeaders,
StringBuilder sb)
{
var allowableFormats = negotiationContext.PermissableMediaRanges
.Select(mr => mr.ToString())
.Aggregate((t1, t2) => t1 + ", " + t2);
var originalAccept = context.Request.Headers["accept"].Any()
? string.Join(", ", context.Request.Headers["accept"])
: "None";
var coercedAccept = coercedAcceptHeaders.Any()
? coercedAcceptHeaders.Select(h => h.Item1).Aggregate((t1, t2) => t1 + ", " + t2)
: "None";
sb.AppendFormat("[DefaultResponseNegotiator] Original accept header: {0}\n", originalAccept);
sb.AppendFormat("[DefaultResponseNegotiator] Coerced accept header: {0}\n", coercedAccept);
sb.AppendFormat("[DefaultResponseNegotiator] Acceptable media ranges: {0}\n", allowableFormats);
}
示例5: TransferTypes
/// <summary>
/// This will move the types in transfer from the from array to the to array. The arrays passed in won't be affected,
/// but the return will be the new from and to
/// </summary>
private static Tuple<Type[], Tuple<Type, int>[]> TransferTypes(Type[] existingFrom, Tuple<Type, int>[] existingTo, Tuple<Type, int>[] transfer)
{
// Only keep the types that aren't in transfer
Type[] newFrom = existingFrom.Where(o => !transfer.Any(p => p.Item1.Equals(o))).ToArray();
if (newFrom.Length == 0)
{
newFrom = null;
}
// Add transfer to existing
Tuple<Type, int>[] newTo = UtilityCore.ArrayAdd(existingTo, transfer);
return Tuple.Create(newFrom, newTo);
}
示例6: GetRandomFlagColors_Category
private static FlagColorCategory GetRandomFlagColors_Category(FlagColorCategory[] chooseFrom, Tuple<ColorHSV, FlagColorCategory>[] existing)
{
if (chooseFrom.Length == 1)
{
return chooseFrom[0];
}
Random rand = StaticRandom.GetRandomForThread();
int infiniteLoopDetector = 0;
// There are more than one to choose from. Pick one that hasn't been picked before
// For example { Black, White }, and White is used. Need to return Black
int index = -1;
while (true)
{
index = rand.Next(chooseFrom.Length);
if (!existing.Any(o => o.Item2 == chooseFrom[index]))
{
return chooseFrom[index];
}
infiniteLoopDetector++;
if (infiniteLoopDetector > 1000)
{
throw new ApplicationException("Infinite loop detected");
}
}
}
示例7: GetVoronoiCtrlPoints_TwoLines
private static Point3D[] GetVoronoiCtrlPoints_TwoLines(Tuple<Point3D, ITriangle, double>[][] hits, ITriangleIndexed[] asteroid)
{
if (hits.Length != 2 || hits.Any(o => o.Length != 2))
{
throw new ArgumentException("This method expects 2 hits, each with two endpoints");
}
// Examine hits
Tuple<int, double>[] hitsByLength = hits.
Select((o, i) => Tuple.Create(i, (o[1].Item1 - o[0].Item1).Length)).
OrderByDescending(o => o.Item2).
ToArray();
double totalLength = hitsByLength.Sum(o => o.Item2);
Tuple<int, double>[] hitsByPercentLength = hitsByLength.
Select(o => Tuple.Create(o.Item1, o.Item2 / totalLength)).
ToArray();
// Define control point cones
var aabb = Math3D.GetAABB(asteroid);
double aabbLen = (aabb.Item2 - aabb.Item1).Length;
double entryRadius = aabbLen * .03;
double exitRadius = aabbLen * .15;
double maxAxisLength = aabbLen * .75;
List<Point3D> retVal = new List<Point3D>();
//TODO: Instead of a fixed number here, figure out how many control points to make based on the total
//length of the hits in relation to the volume of the asteroid
for (int cntr = 0; cntr < 3; cntr++)
{
int index = UtilityCore.GetIndexIntoList(StaticRandom.NextDouble(), hitsByPercentLength);
retVal.AddRange(ExplosionForceWorker.GetVoronoiCtrlPoints_AroundLine_Cone(hits[index][0].Item1, hits[index][1].Item1, StaticRandom.Next(2, 5), entryRadius, exitRadius, maxAxisLength));
}
return retVal.ToArray();
#region OLD THOUGHTS
//DIFFICULT: This should be doable, but seems more difficult than it's worth (also very hardcoded and specific - not very natural)
// Draw a line between the two entry points, and another line between the two exit points
// (or reverse one line if the shots come from opposite directions)
//
// Choose a 5th point that is the midpoint of the segment: Math3D.GetClosestPoints_Line_Line()
//
// No choose control points that will have those 4 triangles as edge faces
//FAIL: The plate is very likely not coplanar
// Create a plate with the four hitpoints as verticies
//
// Choose two points on either side of the plate (equidistant)
#endregion
}
示例8: IntersectDates
public static Tuple<Tuple<DateTime, RollResultItem>[], Tuple<DateTime, RollResultItem>[]> IntersectDates(Tuple<DateTime, RollResultItem>[] series1, Tuple<DateTime, RollResultItem>[] series2)
{
var commonDates = series1.Select(s => s.Item1).Concat(series2.Select(s => s.Item1)).Distinct();
var list1 = new List<Tuple<DateTime, RollResultItem>>();
var list2 = new List<Tuple<DateTime, RollResultItem>>();
foreach (var date in commonDates)
{
if (series1.Any(s => s.Item1 == date))
list1.Add(series1.First(s => s.Item1 == date));
else
list1.Add(new Tuple<DateTime, RollResultItem>(date, new RollResultItem(){Value = double.NaN}));
if (series2.Any(s => s.Item1 == date))
list2.Add(series2.First(s => s.Item1 == date));
else
list2.Add(new Tuple<DateTime, RollResultItem>(date, new RollResultItem() { Value = double.NaN }));
}
return new Tuple<Tuple<DateTime, RollResultItem>[], Tuple<DateTime, RollResultItem>[]>(list1.ToArray(), list2.ToArray());
}
示例9: IsStupidBrowser
private static bool IsStupidBrowser(Tuple<string, decimal>[] current, NancyContext context)
{
// If there's one or less accept headers then we can't be a stupid
// browser so just bail out early
if (current.Length <= 1)
{
return false;
}
var maxScore = current.First().Item2;
if (IsPotentiallyBrokenBrowser(context.Request.Headers.UserAgent)
&& !current.Any(h => h.Item2 == maxScore && string.Equals(HtmlContentType, h.Item1, StringComparison.OrdinalIgnoreCase)))
{
return true;
}
return false;
}
示例10: GetUniquePoints
private static void GetUniquePoints(out Point[] uniquePoints, out Tuple<int, int>[] segments, Tuple<Point, Point>[] lineSegments)
{
// Find the unique points
List<Point> uniquePointList = new List<Point>();
foreach (Point point in UtilityCore.Iterate(lineSegments.Select(o => o.Item1), lineSegments.Select(o => o.Item2)))
{
if (!uniquePointList.Any(o => Math2D.IsNearValue(point, o)))
{
uniquePointList.Add(point);
}
}
uniquePoints = uniquePointList.ToArray();
// Convert the line segments into indices
segments = lineSegments.
Select(o => Tuple.Create(IndexOfPoint(uniquePointList, o.Item1), IndexOfPoint(uniquePointList, o.Item2))). // using the list, because an out param can't be used in a lambda, and I didn't feel like making a copy of the array
Where(o => o.Item1 != o.Item2).
Select(o => o.Item1 < o.Item2 ? o : Tuple.Create(o.Item2, o.Item1)). // force the item 1 to be the smaller index (so that the distinct will work properly)
Distinct(). // get rid of duplicate segments
ToArray();
if (segments.Any(o => o.Item1 < 0 || o.Item2 < 0))
{
throw new ApplicationException("Unique point wasn't found");
}
}
示例11: FitnessTracker
private readonly double _ruleCount; // storing this as a double to speed up the score get
#endregion
#region Constructor
public FitnessTracker(ArcBot bot, Tuple<IFitnessRule, double>[] rules)
{
if (bot != null)
{
if (rules.Any(o => o.Item1.Bot.Token != bot.Token))
{
throw new ArgumentException("All rules must be for the same bot");
}
}
this.Bot = bot;
_rules = rules;
_ruleCount = _rules.Length;
}
示例12: GetRange
/// <summary>
/// This returns the range that all guns can support
/// </summary>
/// <remarks>
/// Say gun0 can go from 1 to 3
/// and gun1 can go from 2 to 4
///
/// The return would be 2 to 3
///
/// If there's a gap, an exception is thrown
/// </remarks>
private static Tuple<double, double> GetRange(Tuple<int, ProjectileGun>[] guns)
{
double? max = null;
double? min = null;
for (int cntr = 0; cntr < guns.Length; cntr++)
{
Tuple<double, double> range = guns[cntr].Item2.CaliberRange;
// Min
if (min == null)
{
min = range.Item1;
}
else if (range.Item1 > min.Value)
{
min = range.Item1;
}
// Max
if (max == null)
{
max = range.Item2;
}
else if (range.Item2 < max.Value)
{
max = range.Item2;
}
}
if (min == null || max == null)
{
throw new ArgumentException("There were no guns passed in");
}
// Verify
if (guns.Any(o => o.Item2.CaliberRange.Item1 > max.Value) || guns.Any(o => o.Item2.CaliberRange.Item2 < min.Value))
{
throw new ArgumentException("There is a gap in caliber ranges");
}
return Tuple.Create(min.Value, max.Value);
}
示例13: TransitionToCandidates
private void TransitionToCandidates(Tuple<long, WinnerList.WinningBean>[] deadLive, Tuple<long, WinnerList.WinningBean>[] deadFinalists, long[] removedTokens)
{
// These are ships that died, and were on the live winner list
if (deadLive != null && deadLive.Length > 0)
{
foreach (var win in deadLive)
{
// Store this as a finalist
this.Candidates.Add(win.Item2.Ship.GetNewDNA(), win.Item2.Score);
}
}
// Apply final scores to the dead finalists
if (deadFinalists != null && deadFinalists.Length > 0)
{
foreach (var final in deadFinalists)
{
TrackingCandidate finalist = _finalists.Where(o => o.Contains(final.Item1)).FirstOrDefault();
if (finalist == null)
{
throw new ApplicationException("Didn't find the finalist passed in: " + final.Item1);
}
finalist.FinishedShip(final.Item1, final.Item2.Score);
}
}
// There is a chance that a ship died before getting added to _livingFinalistTopScores. If that happens, then it never gets into deadFinalists.
// So look for this case, and set directly into _finalists
if (removedTokens != null && removedTokens.Length > 0)
{
long[] uniqueDead = removedTokens;
if (deadFinalists != null && deadFinalists.Length > 0)
{
uniqueDead = removedTokens.Where(o => !deadFinalists.Any(p => o == p.Item1)).ToArray();
}
foreach (long dead in uniqueDead)
{
TrackingCandidate finalist = _finalists.Where(o => o.Contains(dead)).FirstOrDefault();
if (finalist != null)
{
finalist.FinishedShip(dead, 0d);
}
}
}
}