示例#1
0
        public void Intersects_2b()
        {
            var sut = new LineSegment(new Point(0, 0), new Point(4, 4));

            var result = sut.Intersect(new LineSegment(new Point(-2, 4), new Point(0, 0)));
            Assert.AreEqual(new Point(0, 0), result);
        }
        private static MembershipFunction combine(MembershipFunction first, MembershipFunction second)
        {
            if (!first.Any())
                return second;
            if (!second.Any())
                return first;
            
            var scanPoints = getScanPoints(first, second);
            
            var result = new MembershipFunction();
            for (var i = 0; i < scanPoints.Count; i++)
            {
                var scanPoint = scanPoints[i];

                var valueFirst = first.Apply(scanPoint);
                var valueSecond = second.Apply(scanPoint);

                result.Add(scanPoint, Math.Max(valueFirst, valueSecond));
                
                // Check if there is an intersection between this scan point and the next
                // and add it to the list of scan points:
                var nextKeyFirst = getNextKey(first, scanPoint);
                var nextKeySecond = getNextKey(second, scanPoint);
                if (nextKeyFirst.HasValue && nextKeySecond.HasValue)
                {
                    var nextValueFirst = first[nextKeyFirst.Value];
                    var nextValueSecond = second[nextKeySecond.Value];

                    if (valueFirst >= valueSecond && nextValueFirst < nextValueSecond ||
                        valueFirst < valueSecond && nextValueFirst >= nextValueSecond)
                    {
                        var lineFirst = new LineSegment(new Point(scanPoint, valueFirst),
                            new Point(nextKeyFirst.Value, nextValueFirst));
                        var lineSecond = new LineSegment(new Point(scanPoint, valueSecond),
                            new Point(nextKeySecond.Value, nextValueSecond));

                        var intersection = lineFirst.Intersect(lineSecond);
                        if (intersection != null && !scanPoints.Contains(intersection.X) && intersection.X > scanPoint)
                            scanPoints.Insert(i + 1, intersection.X);
                    }
                }
            }

            return result.ClearUp();
        }
示例#3
0
        public void Dont_Intersects_6()
        {
            var sut = new LineSegment(new Point(0, 0), new Point(4, 4));

            var result = sut.Intersect(new LineSegment(new Point(5, 0), new Point(5, 5)));
            Assert.IsNull(result);
        }
示例#4
0
        public void Intersects_7()
        {
            var sut = new LineSegment(new Point(3, 0.5), new Point(5, 0.5));

            var result = sut.Intersect(new LineSegment(new Point(3, 0.5), new Point(4, 1)));
            Assert.AreEqual(new Point(3, 0.5), result);
        }
示例#5
0
        public void Intersects_5()
        {
            var line1 = new LineSegment(new Point(0, 0), new Point(4, 4));
            var line2 = new LineSegment(new Point(3, 0), new Point(3, 6));

            Assert.AreEqual(new Point(3, 3), line1.Intersect(line2));
            Assert.AreEqual(new Point(3, 3), line2.Intersect(line1));
        }