Exemple #1
0
        public override void EndSelection(Vector2[] points)
        {
            base.EndSelection(points);
            // When currently a subrange is selected, switch to full range on click.
            if (_subrange)
            {
                _startPoint += _minPlane;
                _algorithm.CompleteRange(_startPoint);
                _subrangePlane = Plane;
            }
            // Select subrange.
            else
            {
                Vector2 minV = new Vector2(
                    Math.Min(points[0].X, points[1].X),
                    Math.Min(points[0].Y, points[1].Y));

                // Int2 values.
                Int2 min = (Int2)minV;
                Vector2 maxV = points[0] + points[1] - minV;
                Int2 max = (Int2)maxV;

                min = Int2.Max(min, new Int2(0)).AsInt2();
                min = Int2.Min(min, _globalMaxPlane).AsInt2();

                max = Int2.Min(max, _globalMaxPlane).AsInt2();
                max = Int2.Max((Int2)max, new Int2(0)).AsInt2();

                if (min.X - max.X == 0 || min.Y - max.Y == 0)
                {
                    return;
                }

                _startPoint = _startPoint - min;

                if (!_startPoint.IsPositive() || _startPoint > max - min)
                    _startPoint = (max - min) / 2;

                _algorithm.Subrange(min, max - min, _startPoint);
                _subrangePlane = new Plane(Plane, new Vector3(min.X, min.Y, 0));
                _minPlane = min;
                _maxPlane = max;
            }

            _subrange = !_subrange;
        }