Relative.Vec.lightCorect C# (CSharp) 메소드

lightCorect() 공개 메소드

public lightCorect ( ) : void
리턴 void
        public void lightCorect()
        {
            double len = (Math.Abs(mX) + Math.Abs(mY)) / 2;
            mX = len * Math.Sign(mX);
            mY = len * Math.Sign(mY);
        }

Usage Example

예제 #1
0
파일: Form1.cs 프로젝트: Arhirat/Relative
        ButtonStateVar.DragRezult onStartDragL(Vec posScreen)
        {
            switch (mInsert)
            {
            case Insert.Line:
            {
                Vec  world = mTimeSpace.getWorldFromScreen(posScreen);
                Line line  = new Line(world, world.plus(new Vec(20, 20)), Color.Black);
                insert(line);
                mInsert = Insert.None;

                return(new ButtonStateVar.DragRezult(
                           delegate(Vec posScreenNew)
                    {
                        Vec world2 = mTimeSpace.getWorldFromScreen(posScreenNew);
                        line.mPos1 = world2;
                        Invalidate();
                    },
                           null,
                           null));
            }

            case Insert.LineLight:
            {
                Vec  world = mTimeSpace.getWorldFromScreen(posScreen);
                Line line  = new Line(world, world.plus(new Vec(20, 20)), Color.Orange);
                mTimeSpace.add(line);
                mInsert = Insert.None;
                Invalidate();

                return(new ButtonStateVar.DragRezult(
                           delegate(Vec posScreenNew)
                    {
                        Vec delta = posScreenNew.minus(posScreen);
                        delta.lightCorect();
                        Vec world2 = mTimeSpace.getWorldFromScreen(posScreen.plus(delta));
                        line.mPos1 = world2;
                        Invalidate();
                    },
                           null,
                           null));
            }

            case Insert.Invariant:
            {
                mInsert = Insert.None;
                Invalidate();

                return(new ButtonStateVar.DragRezult(
                           delegate(Vec posScreenNew)
                    {
                        Invalidate();
                    },
                           delegate(Vec posScreenNew)
                    {
                        Invalidate();
                    },
                           delegate(Vec posScreenNew, DrawInfo di)
                    {
                        Pen pen = new Pen(Color.LimeGreen);
                        pen.Width = 1;
                        di.drawLine(pen, posScreen, posScreenNew);

                        Vec world = mTimeSpace.getWorldFromScreen(posScreen);
                        Vec worldNew = mTimeSpace.getWorldFromScreen(posScreenNew);
                        double invariant = mTimeSpace.getInvariant(world, worldNew) / (GRID * GRID);
                        di.drawText(invariant.ToString(), posScreenNew.plus(new Vec(10, -10)));
                    }));
            }

            default:
                return(new ButtonStateVar.DragRezult(true));
            }
        }