예제 #1
0
        private IEnumerable <NeighbourInfo> CalculateNeighbours(KeyValuePair <Parcel, ISubdivisionContext> subject, NeighbourSet <ISubdivisionContext> nodes)
        {
            foreach (var edge in subject.Key.Edges)
            {
                var query      = new LineSegment2(edge.Start, edge.End);
                var neighbours = nodes.Neighbours(query, MathHelper.ToRadians(5), 1);
                foreach (var neighbour in neighbours)
                {
                    //Do not add self as a neighbour!
                    if (neighbour.Value.Equals(subject.Value))
                    {
                        continue;
                    }

                    yield return(new NeighbourInfo(
                                     neighbour.Value,
                                     neighbour.Segment.Transform(WorldTransformation),
                                     neighbour.SegmentOverlapStart,
                                     neighbour.SegmentOverlapEnd,
                                     query.Transform(WorldTransformation),
                                     neighbour.QueryOverlapStart,
                                     neighbour.QueryOverlapEnd
                                     ));
                }
            }
        }
예제 #2
0
        public void AssertThat_OverlappingLineSegments_AreNeighbours()
        {
            _set.Add(new LineSegment2(new Vector2(0, 0), new Vector2(10, 0)), 1);
            _set.Add(new LineSegment2(new Vector2(5, 0), new Vector2(15, 0)), 2);

            var neighbours = _set.Neighbours(new LineSegment2(new Vector2(0, 0), new Vector2(10, 0)), 0, 0).ToArray();

            // ReSharper disable once ExceptionNotDocumented
            Assert.AreEqual(1, neighbours.Length);
            Assert.AreEqual(new LineSegment2(new Vector2(5, 0), new Vector2(15, 0)), neighbours.Single().Segment);
            Assert.AreEqual(0f, neighbours.Single().SegmentOverlapStart);
            Assert.AreEqual(0.5f, neighbours.Single().SegmentOverlapEnd);
            Assert.AreEqual(0.5f, neighbours.Single().QueryOverlapStart);
            Assert.AreEqual(1.0f, neighbours.Single().QueryOverlapEnd);
            Assert.AreEqual(2, neighbours.Single().Value);
        }