Example #1
0
        //
        public void ModifyWrapInfo(string txt, int len, ref WLine wl, int stt)
        {
            // 設定幅での折り返しを実行する。
            // 行の途中からの変更の場合、sttが開始addressを指している
            Painter p  = cvs_.getPainter();
            int     ww = cvs_.wrapWidth();

            while (stt < len)
            {
                int i, w;
                for (w = 0, i = stt; i < len; ++i)
                {
                    if (txt[i] == '\t')
                    {
                        w = p.nextTab(w);
                    }
                    else
                    {
                        w += p.W(txt[i]);
                    }

                    if (w > ww)
                    {
                        break;                 // 幅が設定値を超えた所でおしまい
                    }
                }
                wl.Add(stt = (i == stt?i + 1:i));
            }
        }
Example #2
0
        //
        public void ReWrapAll()
        {
            // 折り返し幅に変更があった場合に、全ての行の
            // 折り返し位置情報を変更する。
            int ww = cvs_.wrapWidth();

            int vln = 0;

            for (int i = 0, ie = doc_.tln(); i < ie; ++i)
            {
                WLine wl = wrap_[i];
                wl.ForceSize(1);
                //wl.RemoveRange(1, wl.Count - 2);

                if (wl.width < ww)
                {
                    // 設定した折り返し幅より短い場合は一行で済む。
                    wl.Add(doc_.len(i));
                    ++vln;
                }
                else
                {
                    // 複数行になる場合
                    ModifyWrapInfo(doc_.tl(i).ToString(), doc_.len(i), ref wl, 0);
                    vln += wl.rln();
                }
            }
            vlNum_ = vln;
        }
Example #3
0
        public void PerpendicularSlope()
        {
            //assign
            Geometry.MarginOfError = 0.001;
            WLine a = new WLine(new WPoint(0, -4.0 / 9.0), new WPoint(-4.0 / 6.0, 0));
            //act
            double result = a.PerpendicularSlope;

            //assert
            Assert.AreEqual(3.0 / 2.0, result);
        }
Example #4
0
        /// <summary>
        /// 指定した一行のみ折り返しを修正。
        /// 昔は再描画範囲の計算のために、表示行数の変化を返していたが、
        /// これは上位ルーチン側で vln() を比較すれば済むし、
        /// むしろその方が効率的であるため廃止した。
        /// </summary>
        /// <param name="s"></param>
        /// <returns>
        /// 2: "折り返しあり" or "この行が横に一番長くなった"
        /// 1: "この行以外のどこかが最長"
        /// 0: "さっきまでこの行は最長だったが短くなっちゃった"
        /// で、上位ルーチンにm_TextCx修正の必要性を伝える。
        /// </returns>
        int ReWrapSingle(DPos s)
        {
            // 旧情報保存
            WLine wl       = wrap_[s.tl];
            int   oldVRNum = wl.rln();
            int   oldWidth = wl.width;

            // 横幅更新
            wl.width = CalcLineWidth(doc_.tl(s.tl).ToString(), doc_.len(s.tl));

            if (wl.width < cvs_.wrapWidth())
            {
                // 設定した折り返し幅より短い場合は一行で済む。
                wl[1] = doc_.len(s.tl);
                wl.ForceSize(2);
            }
            else
            {
                // 複数行になる場合
                int vr = 1, stt = 0;
                while (wl[vr] < s.ad)          // while( vr行目は変更箇所より手前 )
                {
                    stt = wl[vr++];            // stt = 次の行の行頭のアドレス
                }
                // 変更箇所以降のみ修正
                wl.ForceSize(vr);
                ModifyWrapInfo(doc_.tl(s.tl).ToString(), doc_.len(s.tl), ref wl, stt);
            }

            // 表示行の総数を修正
            vlNum_ += (wl.rln() - oldVRNum);

            // 折り返しなしだと総横幅の更新が必要
            //if( cvs_.wrapType() == NOWRAP )
            if (cvs_.wrapType == WrapType.NonWrap)
            {
                if (textCx_ <= wl.width)
                {
                    textCx_ = wl.width;
                    return(2);
                }
                else if (textCx_ == oldWidth)
                {
                    return(0);
                }
                else
                {
                    return(1);
                }
            }
            return(2);
        }
Example #5
0
        public void GetPerpendicularIntersect()
        {
            //assign
            Geometry.MarginOfError = 0.001;
            WLine  a = new WLine(new WPoint(0, 15.0 / 6.0), new WPoint(15.0 / 8.0, 0));
            WPoint c = new WPoint(3, -4);
            //act
            WPoint result = a.GetPerpendicularIntersect(c);

            //assert
            Assert.IsTrue(Geometry.WithinMarginOfError(21.0 / 5.0, result.X));
            Assert.IsTrue(Geometry.WithinMarginOfError(-31.0 / 10.0, result.Y));
        }
Example #6
0
        public void Overlaps_WPoint_PointIsOutsideLineSegment()
        {
            //arrange
            Geometry.MarginOfError   = 0.001;
            Geometry.CoordinatePlane = Geometry.CoordinatePlanes.Screen;
            WLine  line  = new WLine(new WPoint(1, 0), new WPoint(5, 0));
            WPoint point = new WPoint(0, 0);
            //act
            bool result = line.Overlaps(point);

            //assert
            Assert.IsTrue(result);
        }
Example #7
0
        public void GetIntersection_WLine_SecondLineVertical()
        {
            //arrange
            Geometry.MarginOfError   = 0.001;
            Geometry.CoordinatePlane = Geometry.CoordinatePlanes.Screen;
            WLine a = new WLine(new WPoint(36.3639, 305.3639), new WPoint(30, 129));
            WLine b = new WLine(new WPoint(39, 129), new WPoint(39, 171));
            //act
            Intersection result = a.GetIntersection(b);

            //assert
            Assert.IsTrue(result.IsPoint);
        }
Example #8
0
        public void GetIntersectionPointsLine_VerticalLine_A()
        {
            //assign
            Geometry.MarginOfError = 0.01;
            WCircle a = new WCircle(new WPoint(53.8075, 29.1875), 4.6825) / Utilities.UNITS_TO_PIXELS;
            WLine   b = new WLine(new WPoint(51.27, 25), new WPoint(51.27, 19.125)) / Utilities.UNITS_TO_PIXELS;

            //account
            Utilities.SaveDiagram(new IDraw[] { a, b.ToLineSegment() }, nameof(TestCircle));
            //act
            WPoint[] result = a.GetIntersectionPoints(b);
            //assert
            Assert.AreEqual(2, result.Length);
        }
Example #9
0
        public void IsHorizontal_MarginOfError_No()
        {
            //arrange (from real example)
            Geometry.MarginOfError   = 0.001;
            Geometry.CoordinatePlane = Geometry.CoordinatePlanes.Screen;
            WPoint a    = new WPoint(1, 160.06);
            WPoint b    = new WPoint(10, 159.94);
            WLine  line = new WLine(a, b);
            //act
            bool result = line.IsHorizontal;

            //assert
            Assert.IsFalse(result);
        }
Example #10
0
        public void IsVertical_MarginOfError_Yes()
        {
            //arrange (from real example)
            Geometry.MarginOfError   = 0.001;
            Geometry.CoordinatePlane = Geometry.CoordinatePlanes.Screen;
            WPoint a    = new WPoint(160.00000000000006, 1);
            WPoint b    = new WPoint(159.99999999999994, 10);
            WLine  line = new WLine(a, b);
            //act
            bool result = line.IsVertical;

            //assert
            Assert.IsTrue(result);
        }
Example #11
0
        /// <summary>
        /// 指定した分だけ新しく行情報を追加。
        /// &折り返し情報もきちんと計算
        /// </summary>
        /// <param name="ti_s"></param>
        /// <param name="ti_e"></param>
        /// <returns>
        /// 1: "折り返しあり" or "この行が横に一番長くなった"
        /// 0: "この行以外のどこかが最長"
        /// 詳しくは ReWrapSingle() を見よ。
        /// </returns>
        public int InsertMulti(int ti_s, int ti_e)
        {
            int dy = 0, cx = 0;

            for (int i = ti_s; i <= ti_e; ++i)
            {
                WLine  pwl = new WLine();
                string ss  = doc_.tl(i).ToString();
                pwl.Add(CalcLineWidth(doc_.tl(i).ToString(), doc_.len(i)));

                int ww = cvs_.wrapWidth();
                if (pwl.width < cvs_.wrapWidth())
                {
                    // 設定した折り返し幅より短い場合は一行で済む。
                    pwl.Add(doc_.len(i));
                    dy++;
                    if (cx < pwl.width)
                    {
                        cx = pwl.width;
                    }
                }
                else
                {
                    // 複数行になる場合
                    ModifyWrapInfo(doc_.tl(i).ToString(), doc_.len(i), ref pwl, 0);
                    dy += pwl.rln();
                }

                //wrap_.InsertAt( i, pwl );
                wrap_.Insert(i, pwl);
            }

            // 表示行の総数を修正
            vlNum_ += dy;

            // 折り返しなしだと総横幅の更新が必要
            if (cvs_.wrapType == WrapType.NonWrap)
            {
                if (textCx_ <= cx)
                {
                    textCx_ = cx;
                    return(1);
                }
                return(0);
            }
            return(1);
        }
Example #12
0
        /// <summary>
        /// 指定した範囲の行情報を削除
        /// </summary>
        /// <param name="ti_s"></param>
        /// <param name="ti_e"></param>
        /// <returns>
        /// 1: "折り返しあり" or "この行以外のどこかが最長"
        /// 0: "さっきまでこの行は最長だったが短くなっちゃった"
        /// 詳しくは ReWrapSingle() を見よ。
        /// </returns>
        public int DeleteMulti(int ti_s, int ti_e)
        {
            bool widthChanged = false;
            int  dy           = 0;

            // 情報収集しながら削除
            for (int cx = textCx_, i = ti_s; i <= ti_e; ++i)
            {
                WLine wl = wrap_[i];
                dy += wl.rln();
                if (cx == wl.width)
                {
                    widthChanged = true;
                }
            }
            //wrap_.RemoveAt( ti_s, (ti_e-ti_s+1) );
            wrap_.RemoveRange(ti_s, (ti_e - ti_s + 1));

            // 表示行の総数を修正
            vlNum_ -= dy;

            // 折り返しなしだと総横幅の更新が必要
            return((cvs_.wrapType == WrapType.NonWrap && widthChanged) ? 0 : 1);
        }