private static List <SurfaceMatch> FindOverlaps(List <SurfaceBasicInfo> _aligned_surfaces, double _tolerance)
        {
            List <SurfaceMatch> matches = new List <SurfaceMatch>();

            if (_aligned_surfaces == null)
            {
                return(matches);
            }
            if (_aligned_surfaces.Count < 2)
            {
                return(matches);
            }

            Dictionary <SurfaceBasicInfo, bool> processed = new Dictionary <SurfaceBasicInfo, bool>();

            foreach (SurfaceBasicInfo s in _aligned_surfaces)
            {
                processed.Add(s, false);
            }

            int nrS = _aligned_surfaces.Count;

            for (int i = 0; i < nrS; i++)
            {
                if (processed[_aligned_surfaces[i]])
                {
                    continue;
                }

                for (int j = 0; j < nrS; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }
                    // allow testing against already processed surfaces
                    // in case of one surface overlapping multiple ones (bad building physics design!)

                    // do not test surfaces within the same volume -> by design they should not overlap
                    if (_aligned_surfaces[i].VolumeID == _aligned_surfaces[j].VolumeID)
                    {
                        continue;
                    }

                    SurfaceMatch test_match = new SurfaceMatch(_aligned_surfaces[i], _aligned_surfaces[j]);
                    test_match.PerformPartialContainmentTest(_tolerance);
                    if (test_match.IsContainment)
                    {
                        matches.Add(test_match);
                        processed[_aligned_surfaces[i]] = true;
                        processed[_aligned_surfaces[j]] = true;
                    }
                }
            }

            return(matches);
        }
 public NeighbEdge(NeighbNode _n1, NeighbNode _n2, SurfaceMatch _match)
 {
     this.Node1 = _n1;
     this.Node2 = _n2;
     this.Match = _match;
     this.SetValidity();
     // set navigation
     if (this.IsValid)
     {
         _n1.AddEdge(this);
         _n2.AddEdge(this);
     }
 }
        private static void ClusterAccToAlignmentAlgorithm(ref Dictionary <SurfaceBasicInfo, int> _processed, ref int _cluster_counter)
        {
            for (int i = 0; i < _processed.Count; i++)
            {
                SurfaceBasicInfo s = _processed.ElementAt(i).Key;
                int s_cluster      = _processed.ElementAt(i).Value;
                if (s_cluster > -1)
                {
                    continue;
                }

                // debug
                if (s.VolumeID == 39 && s.IsWall && s.LevelOrLabel == 2 && s.Wall_LowerPoly == 16 && s.Wall_UpperPoly == 17)
                {
                }

                // try to add to cluster
                List <int> tested_clusters = new List <int>();
                for (int c = 0; c < _processed.Count; c++)
                {
                    SurfaceBasicInfo clusterCenter = _processed.ElementAt(c).Key;
                    int clusterIndex = _processed.ElementAt(c).Value;

                    // debug
                    if (clusterCenter.VolumeID == 25 && clusterCenter.IsWall && clusterCenter.LevelOrLabel == 0)
                    {
                    }

                    if (tested_clusters.Contains(clusterIndex))
                    {
                        continue;
                    }
                    tested_clusters.Add(clusterIndex);

                    SurfaceMatch match_test = new SurfaceMatch(s, clusterCenter, 0.1f); // tolerance for the cos
                    match_test.PerformAlignmentTest();
                    if (match_test.IsAlignment)
                    {
                        _processed[s] = clusterIndex;
                        break;
                    }
                }

                // if unsuccessful, initiate another cluster
                if (_processed[s] < 0)
                {
                    _processed[s] = _cluster_counter;
                    _cluster_counter++;
                }
            }
        }
        public override bool Equals(object obj)
        {
            if (!(obj is SurfaceBasicInfo))
            {
                return(base.Equals(obj));
            }
            else
            {
                SurfaceMatch obj_as_sm = obj as SurfaceMatch;

                if (this.Match01 == null || this.Match02 == null || obj_as_sm.Match01 == null || obj_as_sm.Match02 == null)
                {
                    return(false);
                }

                return((this.Match01 == obj_as_sm.Match01 && this.Match02 == obj_as_sm.Match02) ||
                       (this.Match01 == obj_as_sm.Match02 && this.Match02 == obj_as_sm.Match01));
            }
        }