public static void Add(List <seg3d> segs, seg3d s) { if (!Contains(segs, s)) { segs.Add(s); } }
public static void segs_Remove(List <seg3d> segs, seg3d p) { List <seg3d> rm = new List <seg3d>(); List <seg3d> add = new List <seg3d>(); foreach (seg3d q in segs) { //List<seg3d> onlyp = new List<seg3d>(); List <seg3d> onlyq = new List <seg3d>(); //List<seg3d> common = new List<seg3d>(); SegmentsOverlap3d so = ut.CalcSegmentsOverlap3d(p, q, null, onlyq, null); Debug.Assert( (so == SegmentsOverlap3d.SameSegment) || (so == SegmentsOverlap3d.None) || (so == SegmentsOverlap3d.OppositeDirection) || (so == SegmentsOverlap3d.P_On_Q) || (so == SegmentsOverlap3d.Q_On_P) || (so == SegmentsOverlap3d.Overlap) ); switch (so) { case SegmentsOverlap3d.SameSegment: { rm.Add(q); break; } case SegmentsOverlap3d.None: { break; } case SegmentsOverlap3d.OppositeDirection: { break; } case SegmentsOverlap3d.P_On_Q: case SegmentsOverlap3d.Q_On_P: case SegmentsOverlap3d.Overlap: { rm.Add(q); foreach (seg3d ns in onlyq) { segs_Add(add, ns); } break; } } } foreach (seg3d s in rm) { segs.Remove(s); } foreach (seg3d s in add) { segs.Add(s); } }
public static bool Contains(List <seg3d> segs, seg3d s) { foreach (seg3d seg in segs) { if (eq(seg, s)) { return(true); } } return(false); }
public static seg3d find_seg_a(List <seg3d> segs, xyz p, out xyz next) { next = null; seg3d result = null; foreach (seg3d s in segs) { if (fp.eq_inches(s.a, p)) { next = s.b; result = s; break; } } return(result); }
public static void PartitionFace_SplitEdges(List <seg3d> segs, Solid s2, BoundingBox3d bb2, bool reverse) { List <seg3d> rm = new List <seg3d>(); List <seg3d> news = new List <seg3d>(); for (int i = 0; i < segs.Count; i++) { seg3d s = segs[i]; if (bb2.SegmentCannotIntersect(s.a, s.b)) { continue; } for (int j = 0; j < s2.Faces.Count; j++) { Face f2 = s2.Faces[j]; xyz hit = f2.CalcSegmentFaceIntersection_HitOnly(s); if (hit != null) { rm.Add(s); seg3d to_the_face = new seg3d(s.a, hit, s.origin); seg3d away_from_the_face = new seg3d(hit, s.b, s.origin); news.Add(to_the_face); news.Add(away_from_the_face); break; } } } if (news.Count > 0) { PartitionFace_SplitEdges(news, s2, bb2, reverse); foreach (seg3d s in rm) { segs.Remove(s); } foreach (seg3d s in news) { segs.Add(s); } } }
public static bool eq(seg3d s1, seg3d s2) { if ( fp.eq_inches(s1.a, s2.a) && fp.eq_inches(s1.b, s2.b) ) { return(true); } if ( fp.eq_inches(s1.a, s2.b) && fp.eq_inches(s1.b, s2.a) ) { return(true); } return(false); }
private static void FixSegmentDirection(seg3d s1, Face f1, Face f2, bool reverse) { xyz n1 = f1.UnitNormal(); xyz n2 = f2.UnitNormal(); xyz k = xyz.cross(n2, n1).normalize_in_place(); if (reverse) { k.negate_in_place(); } xyz vab = (s1.b - s1.a).normalize_in_place(); if (!fp.eq_unitvec(vab, k)) { xyz t = s1.a; s1.a = s1.b; s1.b = t; } }
public static List <seg3d> CalcIntersection_NotCoplanar(Face f1, Face f2) { List <seg3d> segs_from_f1 = f1.IntersectWithPlaneOfOtherFace(f2); List <seg3d> segs_from_f2 = f2.IntersectWithPlaneOfOtherFace(f1); if ( (segs_from_f1 == null) || (segs_from_f2 == null) || (segs_from_f1.Count == 0) || (segs_from_f2.Count == 0) ) { return(null); } List <seg3d> result = new List <seg3d>(); // TODO these segments are sorted, so we should not need to run through the f2 list for every seg in the f1 list foreach (seg3d s1 in segs_from_f1) { int count = 0; foreach (seg3d s2 in segs_from_f2) { seg3d s3 = ut.CalcUndirectedSegmentsOverlap3d(s1, s2); if (s3 != null) { result.Add(s3); } else { if (count > 0) { break; } } } } return(result); }
public static void segs_Add(List <seg3d> segs, seg3d p, int level) { List <seg3d> add = new List <seg3d>(); // start with the whole seg. we'll remove pieces of it wherever overlaps occur add.Add(p); foreach (seg3d q in segs) { //List<seg3d> onlyp = new List<seg3d>(); //List<seg3d> onlyq = new List<seg3d>(); List <seg3d> common = new List <seg3d>(); SegmentsOverlap3d so = ut.CalcSegmentsOverlap3d(p, q, null, null, common); Debug.Assert( (so == SegmentsOverlap3d.SameSegment) || (so == SegmentsOverlap3d.None) || (so == SegmentsOverlap3d.OppositeDirection) || (so == SegmentsOverlap3d.P_On_Q) || (so == SegmentsOverlap3d.Q_On_P) || (so == SegmentsOverlap3d.Overlap) ); switch (so) { case SegmentsOverlap3d.SameSegment: { segs_Remove(add, p); break; } case SegmentsOverlap3d.None: { break; } case SegmentsOverlap3d.OppositeDirection: { break; } case SegmentsOverlap3d.P_On_Q: case SegmentsOverlap3d.Q_On_P: case SegmentsOverlap3d.Overlap: { foreach (seg3d ns in common) { segs_Remove(add, ns); } break; } } if (add.Count == 0) { // nothing left. we must be done. return; } } foreach (seg3d s in add) { segs.Add(s); } }
public static void segs_Add(List <seg3d> segs, seg3d s) { segs_Add(segs, s, 0); }