I have been trying all day and have had many attempts but not luck. I have the following Linq query that returns results.
This query returns IEnumerable<sketchEntity>:
var temp = from entity in remainingEntities
where entity.EndPoint.FuzzyEqual(matchPoint, _tolerance)
select entity;
This query returns (IEnumerable<sketchEntity>, end)
var temp = (from entity in remainingEntities
where entity.EndPoint.FuzzyEqual(matchPoint, _tolerance)
select entity, ChainMatchType.End);
Neither of these is what I want. Each result in the final IEnumerable needs to be a named tuple with each tuple having a ISketchEntity and ChainMatchType:
List<(ISketchEntity sketchEntityName, ChainMatchType MatchName)>
I will be doing similar queries three different times.
- When certain types of ISketchEntities match an EndPoint.
- When certain types of ISketchEntities match a StartPoint.
- When certain types of ISketchEntities match a CenterPoint.
When I run each query I want to add the type of result using the Enum to denote the type of match.
public enum ChainMatchType
{
Start,
End,
Center
}
My plan is to combine all three queries into one result before returning the result.
How can I format my LINQ to get the result into a named tuple:
Name DataType
entity: ISketchEntity
MatchType: ChainMatchType
EDIT FuzzyEquals is a custom extension. It compares two points using a +/- tolerance. I am working with CAD data and past history tells me that sometimes two points can be close enough to be equal but don't have exactly the same coordinates.
public static bool FuzzyEqual(this ISketchPoint sp, ISketchPoint other, double tolerance)
{
if (
sp.X > other.X - tolerance && sp.X < other.X + tolerance &&
sp.Y > other.Y - tolerance && sp.Y < other.Y + tolerance &&
sp.Z > other.Z - tolerance && sp.Z < other.Z + tolerance
)
return true;
return false;
}
After seeing it just now I guess it could be simplified to:
public static bool FuzzyEqual(this ISketchPoint sp, ISketchPoint other, double tolerance)
{
return sp.X > other.X - tolerance && sp.X < other.X + tolerance &&
sp.Y > other.Y - tolerance && sp.Y < other.Y + tolerance &&
sp.Z > other.Z - tolerance && sp.Z < other.Z + tolerance;
}