Пример #1
0
        public bool JoinIfAble(LineBlock other, out LineBlock joined)
        {
            // if appendable
            var sameDirection = Vector2.Angle(_direction, other._direction) <= 0;

            if (sameDirection)
            {
                if (Start == other.End)
                {
                    joined = new LineBlock(other.Start, End);
                    return(true);
                }

                if (End == other.Start)
                {
                    joined = new LineBlock(Start, other.End);
                    return(true);
                }
            }

            // if totally blocked
            var isThisShorter = _angle < other._angle;
            var longer        = isThisShorter ? other : this;
            var shorter       = isThisShorter ? this : other;

            if (longer.IsBlocking(shorter.Start) && longer.IsBlocking(shorter.End))
            {
                joined = longer;
                return(true);
            }

            // not joined, useless
            joined = this;
            return(false);
        }
Пример #2
0
        public void AddLineBlock(LineBlock lineBlock)
        {
            var newLineBlock = lineBlock;

            for (var i = 0; i < _lineBlocks.Count; i++)
            {
                var block = _lineBlocks[i];
                if (!block.JoinIfAble(newLineBlock, out var joined))
                {
                    continue;
                }
                _lineBlocks.RemoveAt(i);
                i--;
                MinusPointCount(newLineBlock.Start);
                MinusPointCount(newLineBlock.End);
                newLineBlock = joined;
            }

            _lineBlocks.Add(newLineBlock);
            PlusPointCount(newLineBlock.Start);
            PlusPointCount(newLineBlock.End);
        }