Beispiel #1
0
        public void Ctor(int w, int h)
        {
            var point = new RoixIntSize(w, h);

            point.Width.Is(w);
            point.Height.Is(h);
        }
Beispiel #2
0
        public SelectFixRectViewModel()
        {
            MouseLeftDownPoint = new ReactivePropertySlim <RoixBorderPoint>(mode: ReactivePropertyMode.None);
            MouseMovePoint     = new ReactivePropertySlim <RoixBorderPoint>();
            ViewBorderSize     = new ReactivePropertySlim <RoixSize>(mode: ReactivePropertyMode.DistinctUntilChanged);

            var imageSourceSize = MyImage.ToRoixIntSize();

            // 画像座標系の固定サイズ枠(これを基準に管理する) 右クリックで固定サイズの枠を描画する
            var clickedFixedRectangleOnImage = MouseLeftDownPoint
                                               .Where(border => border.Border.IsNotZero)
                                               .Select(borderPointOnView =>
            {
                var length         = 100;
                var rectBorderSize = new RoixIntSize(length).ToRoixBorder(imageSourceSize);
                var rectHalfSize   = rectBorderSize.Size / 2d;

                var newCenterPoint = borderPointOnView.ConvertToNewBorderInt(imageSourceSize);
                var newRect        = new RoixBorderIntRect(newCenterPoint - (RoixIntVector)rectHalfSize, rectBorderSize);
                return(newRect.GetClippedBorderIntRect(isPointPriority: false));
            })
                                               .ToReadOnlyReactivePropertySlim();

            // Model通知
            ClickedFixedRectangleToModel = clickedFixedRectangleOnImage
                                           .Where(border => border.Border.IsNotZero)
                                           .Select(borderRectOnView => borderRectOnView.Roi)
                                           .ToReadOnlyReactivePropertySlim();

            // View座標系の選択枠
            ClickedFixedRectangle = clickedFixedRectangleOnImage
                                    .CombineLatest(ViewBorderSize, (rect, border) => rect.ConvertToNewBorder(border).Roi)
                                    .ToReadOnlyReactivePropertySlim();
        }
Beispiel #3
0
        public void Deconstruct()
        {
            var point = new RoixIntSize(1, 2);

            var(w, y) = point;
            w.Is(point.Width);
            y.Is(point.Height);
        }
Beispiel #4
0
        public void ToRoix()
        {
            int      x = 1, y = 2;
            var      ris1 = new RoixIntSize(x, y);
            RoixSize rs1  = (RoixSize)ris1;

            rs1.IsEmpty.IsFalse();
            rs1.Width.Is(ris1.Width);
            rs1.Height.Is(ris1.Height);
        }
Beispiel #5
0
        public void FromRoix()
        {
            double      x = 1.1, y = 2.2;
            var         rs1  = new RoixSize(x, y);
            RoixIntSize ris1 = rs1.ToRoixInt();

            ris1.Width.Is((int)Math.Round(rs1.Width));
            ris1.Height.Is((int)Math.Round(rs1.Height));

            Assert.Throws <ArgumentException>(() => RoixSize.Empty.ToRoixInt());
        }
Beispiel #6
0
        public void Equal()
        {
            int x = 1, y = 2;
            var p1 = new RoixIntSize(x, y);
            var p2 = new RoixIntSize(x, y);

            p1.Equals(p2).IsTrue();
            (p1 == p2).IsTrue();
            (p1 != p2).IsFalse();

            var obj2 = (object)p2;

            p1.Equals(obj2).IsTrue();
        }
Beispiel #7
0
        public void Ctor(int x, int y, int width, int height)
        {
            var point = new RoixIntPoint(x, y);
            var size  = new RoixIntSize(width, height);

            var rect1 = new RoixIntRect(point, size);

            rect1.Location.X.Is(point.X);
            rect1.Location.Y.Is(point.Y);
            rect1.Size.Width.Is(size.Width);
            rect1.Size.Height.Is(size.Height);

            var rect2 = new RoixIntRect(new RoixIntPoint(x, y), new RoixIntSize(width, height));

            rect2.Location.X.Is(point.X);
            rect2.Location.Y.Is(point.Y);
            rect2.Size.Width.Is(size.Width);
            rect2.Size.Height.Is(size.Height);
        }
Beispiel #8
0
        public SelectPointViewModel()
        {
            MouseLeftDownPoint = new ReactivePropertySlim <RoixBorderPoint>(mode: ReactivePropertyMode.None);
            MouseMovePoint     = new ReactivePropertySlim <RoixBorderPoint>();
            ViewBorderSize     = new ReactivePropertySlim <RoixSize>(mode: ReactivePropertyMode.DistinctUntilChanged);

            var imageSourceSize = MyImage.ToRoixIntSize();

            #region CursorPoint
            CursorBorderPoint = MouseMovePoint.ToReadOnlyReactivePropertySlim();

            CursorPointToModel = CursorBorderPoint
                                 .Where(borderPoint => borderPoint.IsNotZero)
                                 .Select(borderPoint => borderPoint.ConvertToNewBorderInt(imageSourceSize).Point)
                                 .ToReadOnlyReactivePropertySlim();
            #endregion

            #region DoubleClickPoint
            var eventAcceptedTime     = DateTime.Now;
            var mouseDoubleClickPoint = MouseLeftDownPoint
                                        .TimeInterval()
                                        .Skip(1)
                                        .Where(ti =>
            {
                // 前回の MouseDown から一定時間が経過していればダブクリと言わない
                if (ti.Interval > TimeSpan.FromMilliseconds(500))
                {
                    return(false);
                }

                var now = DateTime.Now;

                // 前回のダブクリ受付から一定時間が経過するまでは、次のダブクリを受け付けない
                if (now - eventAcceptedTime < TimeSpan.FromMilliseconds(500))
                {
                    return(false);
                }

                eventAcceptedTime = now;        // ダブクリ受付時間の更新
                return(true);
            })
                                        .Select(x => x.Value)
                                        .ToReadOnlyReactivePropertySlim(mode: ReactivePropertyMode.None);

            // 画像座標系の点(これを基準に管理する)
            var selectedPointOnImage = mouseDoubleClickPoint
                                       .Select(borderPoint =>
            {
                var borderInt = borderPoint.ConvertToNewBorderInt(imageSourceSize);
                return(borderInt.ClipToSize(borderInt.Border - 1));
            })
                                       .ToReadOnlyReactivePropertySlim();

            SinglePoint = selectedPointOnImage
                          .CombineLatest(ViewBorderSize, (intPoint, viewSize) =>
            {
                var leftTop       = intPoint.ConvertToNewBorder(viewSize).Point;
                var halfPixelSize = new RoixIntSize(1).ToRoixBorder(imageSourceSize).ConvertToNewBorder(viewSize).Size / 2d;
                return(leftTop + (RoixVector)halfPixelSize);        // 画素の中央部に点を打つためシフト
            })
                          .ToReadOnlyReactivePropertySlim();

            SinglePointToModel = selectedPointOnImage
                                 .Where(borderPoint => borderPoint.Border.IsNotZero)
                                 .Select(borderRectOnView => borderRectOnView.Point)
                                 .ToReadOnlyReactivePropertySlim();
            #endregion
        }