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) { 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>()); } }