public static string CalculateRelationship(Individual rootPerson, Individual indToFind) { if (rootPerson.Equals(indToFind)) { return("root person"); } CommonAncestor commonAncestor = indToFind.CommonAncestor; long rootDistance = (long)(BigInteger.Log(commonAncestor.Ind.Ahnentafel) / Math.Log(2.0)); long toFindDistance = commonAncestor.Distance; // DIRECT DESCENDANT - PARENT if (toFindDistance == 0) { string relation = indToFind.IsMale ? "father" : "mother"; indToFind.RelationSort = rootDistance; return((commonAncestor.Step ? "step " : string.Empty) + AggrandiseRelationship(relation, rootDistance, 0)); } // DIRECT DESCENDANT - CHILD if (rootDistance == 0) { string relation = indToFind.IsMale ? "son" : "daughter"; indToFind.RelationSort = -toFindDistance; indToFind.RelationType = Individual.DESCENDANT; return((commonAncestor.Step ? "step " : string.Empty) + AggrandiseRelationship(relation, toFindDistance, 0)); } // EQUAL DISTANCE - SIBLINGS / PERFECT COUSINS if (rootDistance == toFindDistance) { switch (toFindDistance) { case 1: return((commonAncestor.Step ? "half " : string.Empty) + (indToFind.IsMale ? "brother" : "sister")); case 2: return("cousin"); default: return($"{OrdinalSuffix(toFindDistance - 1)} cousin"); } } // AUNT / UNCLE if (toFindDistance == 1) { string relation = indToFind.IsMale ? "uncle" : "aunt"; return(AggrandiseRelationship(relation, rootDistance, 1)); } // NEPHEW / NIECE if (rootDistance == 1) { string relation = indToFind.IsMale ? "nephew" : "niece"; return(AggrandiseRelationship(relation, toFindDistance, 1)); } // COUSINS, GENERATIONALLY REMOVED long cousinOrdinal = Math.Min(rootDistance, toFindDistance) - 1; long cousinGenerations = Math.Abs(rootDistance - toFindDistance); return($"{OrdinalSuffix(cousinOrdinal)} cousin {FormatPlural(cousinGenerations)} removed"); }
public void SetChildrenCommonRelation(Individual parent, CommonAncestor commonAncestor) { foreach (Individual child in Children) { if (child.CommonAncestor == null || child.CommonAncestor.distance > commonAncestor.distance + 1) { child.CommonAncestor = new CommonAncestor(commonAncestor.ind, commonAncestor.distance + 1, !child.IsNaturalChildOf(parent) || commonAncestor.step); } } }
public void SetChildrenCommonRelation(Individual parent, CommonAncestor commonAncestor) { if (parent is null || commonAncestor is null) { return; } foreach (var child in Children) { if (child.CommonAncestor is null || child.CommonAncestor.Distance > commonAncestor.Distance + 1) { child.CommonAncestor = new CommonAncestor(commonAncestor.Ind, commonAncestor.Distance + 1, !child.IsNaturalChildOf(parent) || commonAncestor.Step); } } }