public static bool EdgesCross(PedigreeCoupleEdge a, PedigreeCoupleEdge b, bool hiding) { if (a == null || b == null) { return(false); } if (hiding) { if (!a.u.mother.bloodRelative || !a.u.father.bloodRelative || !a.v.mother.bloodRelative || !a.v.father.bloodRelative) { return(false); } if (!b.u.mother.bloodRelative || !b.u.father.bloodRelative || !b.v.mother.bloodRelative || !b.v.father.bloodRelative) { return(false); } } bool aAndBShareAVertex = false; aAndBShareAVertex = aAndBShareAVertex || a.u == b.u; aAndBShareAVertex = aAndBShareAVertex || a.v == b.u; aAndBShareAVertex = aAndBShareAVertex || a.u == b.v; aAndBShareAVertex = aAndBShareAVertex || a.v == b.v; if (aAndBShareAVertex) { return(false); } double x1 = a.u.point.x; double y1 = a.u.point.y; double x2 = a.v.point.x; double y2 = a.v.point.y; double x3 = b.u.point.x; double y3 = b.u.point.y; double x4 = b.v.point.x; double y4 = b.v.point.y; return(PedigreeUtils.LinesIntersect(x1, y1, x2, y2, x3, y3, x4, y4)); }
private bool LayoutIsValid(PedigreeModel model) { for (int generation = 0; generation < model.maxGenerationalLevel + 1; generation++) { //test for crossed edges foreach (PedigreeCouple coupleA in model.couples) { if (coupleA.GenerationalLevel == generation) { foreach (PedigreeIndividual childA in coupleA.children) { foreach (PedigreeCouple coupleB in model.couples) { if (coupleB.GenerationalLevel == generation) { foreach (PedigreeIndividual childB in coupleB.children) { if (coupleA != coupleB && childA != childB) { double x1 = coupleA.point.x; double y1 = coupleA.point.y; double x2 = childA.point.x; double y2 = childA.point.y; double x3 = coupleB.point.x; double y3 = coupleB.point.y; double x4 = childB.point.x; double y4 = childB.point.y; //does the edge from coupleA to childA //cross the edge from coupleB to childB? if (PedigreeUtils.LinesIntersect(x1, y1, x2, y2, x3, y3, x4, y4)) { //if yes then the layout is not valid return(false); } } } } } } } } //test for individuals inbetween fathers and mothers: //put all individuals in the current generation in a list PedigreeUtils.GetIndividualsInGeneration(model, generation, temp); if (model.couplesGraphIsPlanar) { for (int i = 0; i < temp.Count; i++) { for (int j = 0; j < temp.Count; j++) { if (i != j) { if (Math.Abs(temp[i].point.x - temp[j].point.x) < (model.parameters.horizontalSpacing / 2)) { //if (model.couplesGraphIsPlanar && model.layoutIsValid == false) //{ //if (model.parameters.repelIndividualSetsStrength < 10) //{ // model.parameters.repelIndividualSetsStrength += 0.5; //} //if (model.parameters.couplesAttractionStrength > 0.1) //{ // model.parameters.couplesAttractionStrength -= 0.1; //} //if (model.parameters.layoutCouplesStrength > 0.01) //{ // model.parameters.layoutCouplesStrength -= 0.01; //} //if (model.parameters.centeringForceStrength > 0.01) //{ // model.parameters.centeringForceStrength -= 0.01; //} //if (model.parameters.sibshipShrinkingFacor > 0.01) //{ // model.parameters.sibshipShrinkingFacor -= 0.01; //} //} return(false); } } } } } //for each person who has a spouse, make sure the spouse is next to that person, //otherwise report an invalid layout for (int i = 0; i < temp.Count; i++) { PedigreeIndividual individual = temp[i]; foreach (PedigreeCouple pc in individual.spouseCouples) { if (!model.parameters.hideNonBloodRelatives || (pc.mother.bloodRelative && pc.father.bloodRelative)) { PedigreeIndividual spouse; if (individual.HraPerson.relativeID == pc.mother.HraPerson.relativeID) { spouse = pc.father; } else { spouse = pc.mother; } bool coupleIsSplit = true; if (i > 0) { if (temp[i - 1].HraPerson.relativeID == spouse.HraPerson.relativeID) { coupleIsSplit = false; } } if (i < temp.Count - 1) { if (temp[i + 1].HraPerson.relativeID == spouse.HraPerson.relativeID) { coupleIsSplit = false; } } if (coupleIsSplit) { return(false); } } } //if (individual.spouseCouples.Count == 1) //{ // PedigreeIndividual spouse = individual.Spouse; // bool coupleIsSplit = true; // if (i > 0) // if (temp[i - 1].relativeID == spouse.relativeID) // coupleIsSplit = false; // if (i < temp.Count - 1) // if (temp[i + 1].relativeID == spouse.relativeID) // coupleIsSplit = false; // if (coupleIsSplit) // return false; //} } } return(true); }
private bool LayoutIsValid(PedigreeModel model) { List <PedigreeIndividual> temp = new List <PedigreeIndividual>(); for (int generation = 0; generation <= model.maxGenerationalLevel + 1; generation++) { //test for crossed edges foreach (PedigreeCouple coupleA in model.couples) { if (coupleA.GenerationalLevel == generation) { foreach (PedigreeIndividual childA in coupleA.children) { foreach (PedigreeCouple coupleB in model.couples) { if (coupleB.GenerationalLevel == generation) { foreach (PedigreeIndividual childB in coupleB.children) { if (coupleA != coupleB && childA != childB) { double x1 = coupleA.point.x; double y1 = coupleA.point.y; double x2 = childA.point.x; double y2 = childA.point.y; double x3 = coupleB.point.x; double y3 = coupleB.point.y; double x4 = childB.point.x; double y4 = childB.point.y; //does the edge from coupleA to childA //cross the edge from coupleB to childB? if (PedigreeUtils.LinesIntersect(x1, y1, x2, y2, x3, y3, x4, y4)) { //if yes then the layout is not valid return(false); } } } } } } } } //test for individuals inbetween fathers and mothers: //put all individuals in the current generation in a list PedigreeUtils.GetIndividualsInGeneration(model, generation, temp); for (int i = 0; i < temp.Count; i++) { for (int j = 0; j < temp.Count; j++) { if (i != j) { if (Math.Abs(temp[i].point.x - temp[j].point.x) < (model.parameters.horizontalSpacing / 2)) { return(false); } } } } //for each person who has a spouse, make sure the spouse is next to that person, //otherwise report an invalid layout for (int i = 0; i < temp.Count; i++) { PedigreeIndividual individual = temp[i]; foreach (PedigreeCouple pc in individual.spouseCouples) { PedigreeIndividual spouse; if (individual.HraPerson.relativeID == pc.mother.HraPerson.relativeID) { spouse = pc.father; } else { spouse = pc.mother; } bool coupleIsSplit = true; if (i > 0) { if (temp[i - 1].HraPerson.relativeID == spouse.HraPerson.relativeID) { coupleIsSplit = false; } } if (i < temp.Count - 1) { if (temp[i + 1].HraPerson.relativeID == spouse.HraPerson.relativeID) { coupleIsSplit = false; } } if (coupleIsSplit) { return(false); } } } } return(true); }