public IEnumerable <Annotation> InferAnnotations(NewPrimitive toBeSnapped, SnappedPrimitive toBeAnnotated) { // we skip orthogonality inference for spheres if (toBeSnapped is NewSphere) { return(Enumerable.Empty <Annotation>()); } var curvesToSkip = toBeAnnotated.FeatureCurves.Concat(GetSphereFeatureCurves()).ToArray(); var candidates = from firstCurve in toBeAnnotated.FeatureCurves from secondCurve in sessionData.FeatureCurves.Except(curvesToSkip) where AreGoodCandidates(firstCurve, secondCurve) select Tuple.Create(firstCurve, secondCurve); if (candidates.Any()) { var bestCandidate = candidates.Minimizer(pair => DistanceBetweenCurves(pair.Item1, pair.Item2)); var newFeatureCurve = bestCandidate.Item1; var existingFeatureCurve = bestCandidate.Item2; Annotation curveOrthogonality = new OrthogonalAxis { Elements = new FeatureCurve[] { newFeatureCurve, existingFeatureCurve } }; return(UtilsEnumerable.ArrayOf(curveOrthogonality)); } else { return(Enumerable.Empty <Annotation>()); } }
public IEnumerable <Annotation> InferAnnotations(NewPrimitive toBeSnapped, SnappedPrimitive toBeAnnotated) { // we skip coplanarity inference for spheres. if (toBeSnapped is NewSphere) { return(Enumerable.Empty <Annotation>()); } var curvesToSkip = toBeAnnotated.FeatureCurves.Concat(GetSphereFeatureCurves()).ToArray(); var candidates = from firstCurve in toBeAnnotated.FeatureCurves.OfType <CircleFeatureCurve>() from secondCurve in sessionData.FeatureCurves.Except(curvesToSkip).OfType <CircleFeatureCurve>() where AreGoodCandidates(firstCurve, secondCurve) select Tuple.Create(firstCurve, secondCurve); if (candidates.Any()) { var annotations = from candidate in candidates let coplanarity = new Coplanarity { Elements = new FeatureCurve[] { candidate.Item1, candidate.Item2 } } select coplanarity as Annotation; return(annotations); } else { return(Enumerable.Empty <Annotation>()); } }
private IEnumerable <Annotation> SelectBestCandidates(IEnumerable <CandidatePair> candidates) { // eliminate containers that are not visible because their normal faces away from the viewer // (positive Z coordinate). var withVisibleContainers = from pair in candidates where pair.Container.NormalResult.Z < 0 select pair; if (withVisibleContainers.Any()) { // choose the pair such that the projection of the containee's center on the container's normal // has the lowest value var bestCandidate = withVisibleContainers.Minimizer(ContainedCenterOnContainerAxisProjection); // construct the coplanarity annotation and return a singleton enumerable containing it. var annotation = new Coplanarity { Elements = new FeatureCurve[] { bestCandidate.Container, bestCandidate.Contained } }; return(Utils.Enumerable.Singleton(annotation)); } else { return(Enumerable.Empty <Annotation>()); } }
private Tuple <Term, Term[]> TwoSilhouettesNoFeatures(TSnapped snappedPrimitive, ISet <FeatureCurve> annotated) { var sil0 = SegmentApproximator.ApproximateSegment(snappedPrimitive.LeftSilhouette.Points); var sil1 = SegmentApproximator.ApproximateSegment(snappedPrimitive.RightSilhouette.Points); var axis2d = Get2DVector(snappedPrimitive.AxisResult); var sil0Top = GetForwardPoint(sil0, axis2d); var sil0Bot = GetForwardPoint(sil0, -axis2d); var sil1Top = GetForwardPoint(sil1, axis2d); var sil1Bot = GetForwardPoint(sil1, -axis2d); var topFit = ProjectionFit.Compute( snappedPrimitive.TopFeatureCurve, new Point[] { sil0Top, sil1Top }); var botFit = ProjectionFit.Compute( snappedPrimitive.BottomFeatureCurve, new Point[] { sil0Bot, sil1Bot }); if (annotated.Contains(snappedPrimitive.TopFeatureCurve)) { topFit = Enumerable.Empty <Term>(); } if (annotated.Contains(snappedPrimitive.BottomFeatureCurve)) { botFit = Enumerable.Empty <Term>(); } var objective = TermUtils.SafeSum(topFit.Concat(botFit)); var constraints = new Term[] { snappedPrimitive.Axis.NormSquared - 1 }; return(Tuple.Create(objective, constraints)); }
public IEnumerable <Annotation> InferAnnotations(NewPrimitive toBeSnapped, SnappedPrimitive toBeAnnotated) { var toBeAnnotatedCurves = toBeAnnotated.FeatureCurves; var candidateTriples = from i in Enumerable.Range(0, toBeAnnotatedCurves.Length) from j in Enumerable.Range(i + 1, toBeAnnotatedCurves.Length - i - 1) // at this point (i, j) are all the possible pairs of curves without repetitions let allExistingCurves = sessionData.FeatureCurves.Except(toBeAnnotatedCurves) from existingCurve in allExistingCurves where AreGoodCandidates(toBeAnnotatedCurves[i], toBeAnnotatedCurves[j], existingCurve) select new { FistNewCurve = toBeAnnotatedCurves[i], SecondNewCurve = toBeAnnotatedCurves[j], ExistingCurve = existingCurve }; if (candidateTriples.Any()) { var bestCandidate = candidateTriples.Minimizer(triple => ProximityMeasure(triple.FistNewCurve, triple.SecondNewCurve, triple.ExistingCurve)); var annotation = new ColinearCenters { Elements = UtilsEnumerable.ArrayOf(bestCandidate.FistNewCurve, bestCandidate.SecondNewCurve, bestCandidate.ExistingCurve) }; return(UtilsEnumerable.Singleton(annotation)); } else { return(Enumerable.Empty <Annotation>()); } }
/// <summary>Partitions a collection into groups based on a key value. This methods differs from the default <see cref="NetEnumerable.GroupBy{TSource, TKey}(IEnumerable{TSource}, Func{TSource, TKey})"/> /// method in the sense that it will create groups of elements with the same key, only if those elements are adjacent.</summary> /// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam> /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam> /// <param name="source">An <see cref="IEnumerable{TSource}"/> whose elements to partition.</param> /// <param name="keySelector">A function to extract the key for each element.</param> /// <param name="comparer">An <see cref="IEqualityComparer{T}"/> to compare keys.</param> /// <returns>An <see cref="IEnumerable{T}"/> of <see cref="IGrouping{TKey, TSource}"/> where each <see cref="IGrouping{TKey,TSource}"/> object contains a sequence of objects and a key.</returns> public static IEnumerable <IGrouping <TKey, TSource> > Partition <TKey, TSource>(this IEnumerable <TSource> source, Func <TSource, TKey> keySelector, IEqualityComparer <TKey> comparer) { Guard.ArgumentIsNotNull(source, nameof(source), "The IEnumerable instance is mandatory."); Guard.ArgumentIsNotNull(keySelector, nameof(keySelector)); Guard.ArgumentIsNotNull(comparer, nameof(comparer)); List <TSource> sourceList = source.ToList(); if (sourceList.Count <= 1) { return(source.GroupBy(keySelector)); } var indexedCollection = source.Select((item, index) => new { Index = index, Item = item }).ToList(); IEnumerable <IGrouping <TKey, TSource> > result = NetEnumerable.Empty <IGrouping <TKey, TSource> >(); int startOfNextPart = 0; while (startOfNextPart < sourceList.Count) { List <TSource> partition = indexedCollection .Skip(startOfNextPart) .TakeWhile(indexedItem => indexedItem.Index - startOfNextPart == 0 || comparer.Equals(keySelector(indexedItem.Item), keySelector(sourceList.ElementAt(indexedItem.Index - 1)))) .Select(a => a.Item) .ToList(); startOfNextPart += partition.Count; result = result.Concat(partition.GroupBy(keySelector)); } return(result); }
private IEnumerable <Annotation> InferCoplanarity(SnappedPrimitive existing, SnappedPrimitive fresh) { // spheres do not particiate here if (existing is SnappedSphere || fresh is SnappedSphere) { return(Enumerable.Empty <Annotation>()); } var candidates = GetCandidates(existing.FeatureCurves, fresh.FeatureCurves); return(SelectBestCandidates(candidates)); }
private Term[] GetConcreteAnnotationTerm(OrthogonalAxis orthoonalAxes) { if (orthoonalAxes.Elements.Length != 2) { return(Enumerable.Empty <Term>().ToArray()); } var firstNormal = orthoonalAxes.Elements[0].Normal; var secondNormal = orthoonalAxes.Elements[1].Normal; var innerProduct = firstNormal * secondNormal; return(new Term[] { innerProduct }); }
public void FallbackIfEmptyWithEmptySequenceCollectionOptimized() { var source = LinqEnumerable.Empty <int>(); // ReSharper disable PossibleMultipleEnumeration source.FallbackIfEmpty(12).AssertSequenceEqual(12); source.FallbackIfEmpty(12, 23).AssertSequenceEqual(12, 23); source.FallbackIfEmpty(12, 23, 34).AssertSequenceEqual(12, 23, 34); source.FallbackIfEmpty(12, 23, 34, 45).AssertSequenceEqual(12, 23, 34, 45); source.FallbackIfEmpty(12, 23, 34, 45, 56).AssertSequenceEqual(12, 23, 34, 45, 56); source.FallbackIfEmpty(12, 23, 34, 45, 56, 67).AssertSequenceEqual(12, 23, 34, 45, 56, 67); // ReSharper restore PossibleMultipleEnumeration }
static ItemBase( ) { RuleDeriver.Instance.AddItemRuleDeriver( typeof(ItemBase), item => { if (item.Optional) { return(Enumerable.Empty <IRule <IParserResult> >( )); } return(new List <IRule <IParserResult> > { new ItemIsSet(item) }); }); }
private IEnumerable <Annotation> GetConstraintsForSphereWithNonspherePair(SnappedPrimitive nonSphere, SnappedSphere sphere) { var featureCurvesOnSphere = FindFeatureCurvesOnSphere(nonSphere, sphere); if (featureCurvesOnSphere.Any()) { return(FeatureCurvesOnSphereAnnotation(featureCurvesOnSphere, sphere)); } var hasSilhouettesWithEndpointsOnSphere = HasSilhouettesWithEndpointsOnSphere(nonSphere, sphere); if (hasSilhouettesWithEndpointsOnSphere) { return(SilhouettesWithEndpointsOnSphereAnnotation(nonSphere, sphere)); } return(Enumerable.Empty <Annotation>()); }
public IEnumerable <Annotation> InferAnnotations(NewPrimitive toBeSnapped, SnappedPrimitive toBeAnnotated) { // we skip orthogonality inference for spheres if (toBeSnapped is NewSphere) { return(Enumerable.Empty <Annotation>()); } var curvesToSkip = toBeAnnotated.FeatureCurves.Concat(GetSphereFeatureCurves()).ToArray(); var candidates = from firstCurve in toBeAnnotated.FeatureCurves from secondCurve in sessionData.FeatureCurves.Except(curvesToSkip) where AreGoodCandidates(firstCurve, secondCurve) group Tuple.Create(firstCurve, secondCurve) by firstCurve; return(from candidatesGroup in candidates let bestCandidate = candidatesGroup.Minimizer(pair => CurveDistance(pair.Item1, pair.Item2)) select new Cocentrality { Elements = new FeatureCurve[] { bestCandidate.Item1, bestCandidate.Item2 } }); }
private Tuple <Term, Term[]> TwoSilhouettesSingleFeature(TSnapped snappedPrimitive, ISet <FeatureCurve> annotated) { var sil0 = SegmentApproximator.ApproximateSegment(snappedPrimitive.LeftSilhouette.Points); var sil1 = SegmentApproximator.ApproximateSegment(snappedPrimitive.RightSilhouette.Points); var snappedFeatureCurve = snappedPrimitive.TopCurve == null ? snappedPrimitive.BottomFeatureCurve : snappedPrimitive.TopFeatureCurve; var unsnappedFeatureCurve = snappedPrimitive.TopCurve == null ? snappedPrimitive.TopFeatureCurve : snappedPrimitive.BottomFeatureCurve; var sil0Far = GetFarPoint(sil0, snappedFeatureCurve.SnappedTo); var sil1Far = GetFarPoint(sil1, snappedFeatureCurve.SnappedTo); var featureProj = ProjectionFit(snappedFeatureCurve); var farProj = ProjectionFit(unsnappedFeatureCurve, new Point[] { sil0Far, sil1Far }); if (annotated.Contains(unsnappedFeatureCurve)) { farProj = Enumerable.Empty <Term>(); } var objective = TermUtils.SafeSum(featureProj.Concat(farProj)); var constraints = new Term[] { snappedPrimitive.Axis.NormSquared - 1 }; return(Tuple.Create(objective, constraints)); }
public void SingleOrFallbackWithEmptySequenceIListOptimized() { Assert.AreEqual(5, LinqEnumerable.Empty <int>().SingleOrFallback(() => 5)); }
public void SingleOrFallbackWithEmptySequence() { Assert.AreEqual(5, LinqEnumerable.Empty <int>().Select(x => x).SingleOrFallback(() => 5)); }
/// <summary>Initializes a new path collection.</summary> public PathCollection() : this(Enumerable.Empty <TPath>()) { }
public static IEnumerable <T> OrEmpty <T>([CanBeNull] this IEnumerable <T> @this) => @this ?? Enumerable.Empty <T>();
private static IEnumerable <int> GetEmptySequence() { return(LinqEnumerable.Empty <int>()); }
public static IEnumerable <TResult> Empty <TResult>() => LinqEnumerable.Empty <TResult>();