private void InsertIntersection(ref IntersectionListEntry intersection) { for (int i = 0; i < m_intersectionList.Count; ++i) { if (m_intersectionList[i].Y > intersection.Y) { m_intersectionList.Insert(i, intersection); return; } } m_intersectionList.Add(intersection); }
private void BuildIntersectionList(float bottom, float top) { Debug.Assert(m_intersectionList.Count == 0); float dy = top - bottom; float invDy = 1.0f / dy; SortedEdgeEntry entry = new SortedEdgeEntry(); GetSortedEdgeEntry(bottom, top, dy, 0, ref entry); m_sortedEdgeList.Add(entry); for (int i = 1; i < m_activeEdgeList.Count; ++i) { GetSortedEdgeEntry(bottom, top, dy, i, ref entry); int j = m_sortedEdgeList.Count - 1; while (j >= 0) { SortedEdgeEntry otherEntry = m_sortedEdgeList[j]; if (CompareSortedEdgeEntries(ref otherEntry, ref entry) == -1) break; float x, y; /*if (entry.DX - otherEntry.DX == 0.0f) { x = entry.XCoord + entry.DX * 0.5f; y = (bottom + top) * 0.5f; } else {*/ float invDxDiff = 1.0f / (entry.DX - otherEntry.DX); y = (otherEntry.QNumerator - entry.QNumerator) * invDxDiff; x = entry.DX * invDy * y + entry.QNumerator * invDy; Debug.Assert(Math.Abs(otherEntry.DX * invDy * y + otherEntry.QNumerator * invDy - x) < 0.001f); //} IntersectionListEntry intersection = new IntersectionListEntry(); intersection.RIndex = entry.Index; intersection.LIndex = otherEntry.Index; intersection.X = x; intersection.Y = y; InsertIntersection(ref intersection); --j; } m_sortedEdgeList.Insert(j + 1, entry); } m_sortedEdgeList.Clear(); }