Example #1
0
        /// <summary>
        /// Transform
        /// </summary>
        public override void TransformBy(LitMath.Matrix3 transform)
        {
            LitMath.Vector2 spnt = transform * this.startPoint;
            LitMath.Vector2 epnt = transform * this.endPoint;
            LitMath.Vector2 mpnt = transform * this.middlePoint;

            _center = transform * _center;
            _radius = (spnt - _center).length;

            double sAngle = LitMath.Vector2.SignedAngleInRadian(
                new LitMath.Vector2(1, 0),
                spnt - _center);
            double eAngle = LitMath.Vector2.SignedAngleInRadian(
                new LitMath.Vector2(1, 0),
                epnt - _center);

            if (LitMath.Vector2.SignedAngle(spnt - _center, mpnt - _center) >= 0)
            {
                this.startAngle = sAngle;
                this.endAngle   = eAngle;
            }
            else
            {
                this.startAngle = eAngle;
                this.endAngle   = sAngle;
            }
        }
Example #2
0
 public Arc(LitMath.Vector2 center, double radius, double startAngle, double endAngle)
 {
     _center         = center;
     _radius         = radius;
     this.startAngle = startAngle;
     this.endAngle   = endAngle;
 }
Example #3
0
        internal LitMath.Vector2 Snap(LitMath.Vector2 posInCanvas)
        {
            LitMath.Vector2 posInModel = _presenter.CanvasToModel(posInCanvas);

            foreach (Entity entity in _presenter.currentBlock)
            {
                List <ObjectSnapPoint> snapPnts = entity.GetSnapPoints();
                if (snapPnts == null || snapPnts.Count == 0)
                {
                    continue;
                }
                foreach (ObjectSnapPoint snapPnt in snapPnts)
                {
                    double dis         = (snapPnt.position - posInModel).length;
                    double disInCanvas = _presenter.ModelToCanvas(dis);
                    if (disInCanvas <= _threshold)
                    {
                        _currObjectSnapPoint = snapPnt;
                        return(snapPnt.position);
                    }
                }
            }

            _currObjectSnapPoint = null;
            return(posInModel);
        }
Example #4
0
        public override EventResult OnMouseDown(MouseEventArgs e)
        {
            switch (_step)
            {
            case Step.Step3_SpecifyPointCenter:
                if (e.Button == MouseButtons.Left)
                {
                    _center = this.pointer.currentSnapPoint;
                    _step   = Step.Step4_SpecifyPointOther;
                }
                break;

            case Step.Step4_SpecifyPointOther:
                if (e.Button == MouseButtons.Left)
                {
                    _point = this.pointer.currentSnapPoint;
                    this.UpdatePolygon();

                    _mgr.FinishCurrentCommand();
                }
                break;
            }

            return(EventResult.Handled);
        }
Example #5
0
        public override EventResult OnMouseMove(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                return(EventResult.Unhandled);
            }

            if (_step == Step.Step1_SelectObjects)
            {
            }
            else if (_step == Step.Step2_SpecifyBasePoint)
            {
            }
            else if (_step == Step.Step3_SpecifySecondPoint)
            {
                LitMath.Vector2 preTranslation = this.translation;
                _pathLine.endPoint = this.pointer.currentSnapPoint;
                LitMath.Vector2 offset = this.translation - preTranslation;
                foreach (Entity copy in _copys)
                {
                    copy.Translate(offset);
                }
            }

            return(EventResult.Handled);
        }
Example #6
0
        public static void DrawRectangle(
            Graphics g, IntPtr pen,
            LitMath.Vector2 pnt1, LitMath.Vector2 pnt2)
        {
            // Extract the Win32 HDC from the Graphics object supplied.
            IntPtr hdc = g.GetHdc();

            //
            SetBkMode(hdc, TRANSPARENT);

            // Set the ROP cdrawint mode to XOR.
            SetROP2(hdc, R2_XORPEN);

            // Select the pen into the device context.
            IntPtr oldPen = SelectObject(hdc, pen);

            // Create a stock NULL_BRUSH brush and select it into the device
            // context so that the rectangle isn't filled.
            IntPtr oldBrush = SelectObject(hdc, GetStockObject(NULL_BRUSH));

            // Now XOR the hollow rectangle on the Graphics object with
            // a dotted outline.
            Rectangle(hdc, (int)pnt1.x, (int)pnt1.y, (int)pnt2.x, (int)pnt2.y);

            // Put the old stuff back where it was.
            SelectObject(hdc, oldBrush); // no need to delete a stock object
            SelectObject(hdc, oldPen);

            // Return the device context to Windows.
            g.ReleaseHdc(hdc);
        }
Example #7
0
        internal static bool BoundingIntersectWithRay(Bounding bounding, Ray ray)
        {
            if (!ray.bounding.IntersectWith(bounding))
            {
                return(false);
            }

            LitMath.Vector2 pkPnt1 = new LitMath.Vector2(bounding.left, bounding.bottom);
            LitMath.Vector2 pkPnt2 = new LitMath.Vector2(bounding.left, bounding.top);
            LitMath.Vector2 pkPnt3 = new LitMath.Vector2(bounding.right, bounding.top);
            LitMath.Vector2 pkPnt4 = new LitMath.Vector2(bounding.right, bounding.bottom);

            double d1 = LitMath.Vector2.Cross(pkPnt1 - ray.basePoint, ray.direction);
            double d2 = LitMath.Vector2.Cross(pkPnt2 - ray.basePoint, ray.direction);
            double d3 = LitMath.Vector2.Cross(pkPnt3 - ray.basePoint, ray.direction);
            double d4 = LitMath.Vector2.Cross(pkPnt4 - ray.basePoint, ray.direction);

            if (d1 * d2 <= 0 || d1 * d3 <= 0 || d1 * d4 <= 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #8
0
        internal static bool BoundingIntersectWithLine(Bounding bounding, LitMath.Line2 line)
        {
            Bounding lineBound = new Bounding(line.startPoint, line.endPoint);

            if (!bounding.IntersectWith(lineBound))
            {
                return(false);
            }

            if (bounding.Contains(line.startPoint) ||
                bounding.Contains(line.endPoint))
            {
                return(true);
            }

            LitMath.Vector2 pkPnt1 = new LitMath.Vector2(bounding.left, bounding.bottom);
            LitMath.Vector2 pkPnt2 = new LitMath.Vector2(bounding.left, bounding.top);
            LitMath.Vector2 pkPnt3 = new LitMath.Vector2(bounding.right, bounding.top);
            LitMath.Vector2 pkPnt4 = new LitMath.Vector2(bounding.right, bounding.bottom);

            double d1 = LitMath.Vector2.Cross(line.startPoint - pkPnt1, line.endPoint - pkPnt1);
            double d2 = LitMath.Vector2.Cross(line.startPoint - pkPnt2, line.endPoint - pkPnt2);
            double d3 = LitMath.Vector2.Cross(line.startPoint - pkPnt3, line.endPoint - pkPnt3);
            double d4 = LitMath.Vector2.Cross(line.startPoint - pkPnt4, line.endPoint - pkPnt4);

            if (d1 * d2 <= 0 || d1 * d3 <= 0 || d1 * d4 <= 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #9
0
 /// <summary>
 /// 完成
 /// </summary>
 public override void Finish()
 {
     _resultGripPos = _mousePosInWorld;
     _entity.SetGripPointAt(_index, _gripPoint, _resultGripPos);
     pointer.UpdateGripPoints();
     base.Finish();
 }
Example #10
0
        /// <summary>
        /// 设置夹点
        /// </summary>
        public override void SetGripPointAt(int index, GripPoint gripPoint, LitMath.Vector2 newPosition)
        {
            switch (gripPoint.type)
            {
            case GripPointType.End:
            {
                this.SetPointAt(index, newPosition);
            }
            break;

            case GripPointType.Mid:
            {
                int numOfVertices = NumberOfVertices;
                int i             = index - numOfVertices;
                if (i >= 0 && i <= numOfVertices - 1)
                {
                    int vIndex1st = i;
                    int vIndex2nd = i + 1;
                    if (vIndex2nd == numOfVertices)
                    {
                        vIndex2nd = 0;
                    }
                    LitMath.Vector2 t = newPosition - gripPoint.position;
                    this.SetPointAt(vIndex1st, (LitMath.Vector2)gripPoint.xData1 + t);
                    this.SetPointAt(vIndex2nd, (LitMath.Vector2)gripPoint.xData2 + t);
                }
            }
            break;

            default:
                break;
            }
        }
Example #11
0
        public override bool Read(string name, out LitMath.Vector2 value)
        {
            value = new LitMath.Vector2(0, 0);
            XmlNode node = _curXmlNode.SelectSingleNode(name);

            if (node == null)
            {
                return(false);
            }

            string strValue = node.InnerText;

            string[] xy = strValue.Split(';');
            if (xy.Length != 2)
            {
                return(false);
            }

            double x = 0;

            if (!double.TryParse(xy[0], out x))
            {
                return(false);
            }
            double y = 0;

            if (!double.TryParse(xy[1], out y))
            {
                return(false);
            }
            value.Set(x, y);

            return(true);
        }
Example #12
0
 /// <summary>
 /// Transform
 /// </summary>
 public override void TransformBy(LitMath.Matrix3 transform)
 {
     LitMath.Vector2 refPnt = _basePoint + _direction;
     _basePoint = transform * _basePoint;
     refPnt     = transform * refPnt;
     _direction = (refPnt - _basePoint).normalized;
 }
Example #13
0
        /// <summary>
        /// Transform
        /// </summary>
        public override void TransformBy(LitMath.Matrix3 transform)
        {
            LitMath.Vector2 pnt = _center + new LitMath.Vector2(_radius, 0);

            _center = transform * _center;
            _radius = (transform * pnt - _center).length;
        }
Example #14
0
        public override EventResult OnMouseDown(MouseEventArgs e)
        {
            switch (_step)
            {
            case Step.Step1_SpecifyPoint1st:
                if (e.Button == MouseButtons.Left)
                {
                    _point1st = this.pointer.currentSnapPoint;
                    _step     = Step.Step2_SpecifyPoint2nd;
                }
                break;

            case Step.Step2_SpecifyPoint2nd:
                if (e.Button == MouseButtons.Left)
                {
                    _point2nd = this.pointer.currentSnapPoint;
                    this.UpdateRectangle();

                    _mgr.FinishCurrentCommand();
                }
                break;
            }

            return(EventResult.Handled);
        }
Example #15
0
 /// <summary>
 /// 设置夹点
 /// </summary>
 public override void SetGripPointAt(int index, GripPoint gripPoint, LitMath.Vector2 newPosition)
 {
     if (index == 0)
     {
         _position = newPosition;
     }
 }
Example #16
0
        private void UpdateReservedBounding()
        {
            LitMath.Vector2 centerInModel = _presenter.CanvasToModel(_center);
            double          sideInModel   = _presenter.CanvasToModel(_side);

            _reservedBounding = new Bounding(centerInModel, sideInModel, sideInModel);
        }
Example #17
0
        internal LitMath.Vector2 Snap(LitMath.Vector2 posInCanvas)
        {
            LitMath.Vector2 posInModel = _presenter.CanvasToModel(posInCanvas);

            foreach (KeyValuePair <ObjectId, List <GripPoint> > kvp in _gripPnts)
            {
                int index = -1;
                foreach (GripPoint gripPnt in kvp.Value)
                {
                    ++index;
                    double          width           = 10;
                    double          height          = 10;
                    LitMath.Vector2 gripPosInCanvas = _presenter.ModelToCanvas(gripPnt.position);
                    gripPosInCanvas.x -= width / 2;
                    gripPosInCanvas.y -= height / 2;
                    LitMath.Rectangle2 rect = new LitMath.Rectangle2(gripPosInCanvas, width, height);

                    if (MathUtils.IsPointInRectangle(posInCanvas, rect))
                    {
                        _currGripPoint      = gripPnt;
                        _currGripEntityId   = kvp.Key;
                        _currGripPointIndex = index;
                        return(gripPnt.position);
                    }
                }
            }

            _currGripPoint      = null;
            _currGripEntityId   = ObjectId.Null;
            _currGripPointIndex = -1;
            return(posInModel);
        }
Example #18
0
        static void Main(string[] args)
        {
            //LitMath.Vector2 v = new LitMath.Vector2(0.7, 0.7);
            //v = LitMath.Vector2.RotateInRadian(v, LitMath.Utils.PI / 2);
            //Console.WriteLine(v.ToString());
            //Console.WriteLine(Math.Asin(0.5).ToString());

            {
                LitMath.Vector3 va    = new LitMath.Vector3(0, 0, 1);
                LitMath.Vector3 vb    = new LitMath.Vector3(0, 1, 0);
                LitMath.Vector3 axis  = new LitMath.Vector3(1, 1, 0);
                double          angle = LitMath.Vector3.SignedAngle(va, vb, axis);
                Console.WriteLine(angle);
            }
            {
                LitMath.Vector3 va    = new LitMath.Vector3(0, 0, 1);
                LitMath.Vector3 vb    = new LitMath.Vector3(0, 0, 1);
                LitMath.Vector3 axis  = new LitMath.Vector3(1, 1, 0);
                double          angle = LitMath.Vector3.SignedAngle(va, vb, axis);
                Console.WriteLine(angle);
            }
            {
                LitMath.Vector3 va    = new LitMath.Vector3(0, 0, 1);
                LitMath.Vector3 vb    = new LitMath.Vector3(0, 1, 0);
                LitMath.Vector3 axis  = new LitMath.Vector3(0, 1, 1);
                double          angle = LitMath.Vector3.SignedAngle(va, vb, axis);
                Console.WriteLine(angle);
            }


            return;

            //LitMath.Vector2 v1 = new LitMath.Vector2(1, 3);
            //Console.WriteLine(v1.ToString());

            LitMath.Line2 line1 = new LitMath.Line2(
                new LitMath.Vector2(0, 0),
                new LitMath.Vector2(10, 0));
            line1.startPoint.x = 10;
            LitMath.Line2 line2 = new LitMath.Line2(
                new LitMath.Vector2(5, 0),
                new LitMath.Vector2(5, 10));

            LitMath.Vector2 intersection = new LitMath.Vector2();
            if (LitMath.Line2.Intersect(line1, line2, ref intersection))
            {
                Console.WriteLine("相交: " + intersection.ToString());
            }

            LitMath.Rectangle2 rect = new LitMath.Rectangle2(new LitMath.Vector2(10, 10), 10, 20);
            Console.WriteLine(rect.ToString());
            Console.WriteLine(rect.leftBottom.ToString());
            Console.WriteLine(rect.leftTop.ToString());
            Console.WriteLine(rect.rightTop.ToString());
            Console.WriteLine(rect.rightBottom.ToString());

            LitMath.Circle2 circle = new LitMath.Circle2(new LitMath.Vector2(25, 25), 10);
            Console.WriteLine(circle.ToString());
            Console.WriteLine(circle.diameter.ToString());
        }
Example #19
0
        public override bool Do(double value, LitMath.Vector2 refPoint)
        {
            if (_arc == null ||
                _result == null)
            {
                return(false);
            }

            double dis = (_arc.center - refPoint).length;

            if (dis > _arc.radius)
            {
                _result.radius = _arc.radius + Math.Abs(value);
            }
            else
            {
                if (_arc.radius <= Math.Abs(value))
                {
                    _result.radius = _arc.radius;
                    return(false);
                }
                else
                {
                    _result.radius = _arc.radius - Math.Abs(value);
                }
            }

            return(true);
        }
Example #20
0
 /// <summary>
 /// 平移
 /// </summary>
 public override void Translate(LitMath.Vector2 translation)
 {
     for (int i = 0; i < this.NumberOfVertices; ++i)
     {
         _vertices[i] += translation;
     }
 }
Example #21
0
        public override EventResult OnMouseMove(MouseEventArgs e)
        {
            switch (_step)
            {
            case Step.Step1_SelectObjects:
                break;

            case Step.Step2_SpecifyBasePoint:
                break;

            case Step.Step3_SpecifySecondPoint:
                LitMath.Vector2 preTranslation = this.translation;
                _pathLine.endPoint = this.pointer.currentSnapPoint;

                LitMath.Vector2 offset = this.translation - preTranslation;
                foreach (Entity tempEntity in _tempItemsToDraw)
                {
                    tempEntity.Translate(offset);
                }
                break;

            default:
                break;
            }

            return(EventResult.Handled);
        }
Example #22
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Bounding(LitMath.Vector2 point1, LitMath.Vector2 point2)
        {
            if (point1.x < point2.x)
            {
                _left  = point1.x;
                _right = point2.x;
            }
            else
            {
                _left  = point2.x;
                _right = point1.x;
            }

            if (point1.y < point2.y)
            {
                _bottom = point1.y;
                _top    = point2.y;
            }
            else
            {
                _bottom = point2.y;
                _top    = point1.y;
            }

            _width  = _right - _left;
            _height = _top - _bottom;
        }
Example #23
0
 internal void OnPaint(Graphics graphics)
 {
     LitMath.Vector2 originInCanvas = _presenter.ModelToCanvas(_origin);
     graphics.DrawImage(_bitmap,
                        (float)originInCanvas.x - _offsetX, (float)originInCanvas.y - _bitmap.Height + _offsetY,
                        new RectangleF(0, 0, _bitmap.Width, _bitmap.Height),
                        GraphicsUnit.Pixel);
 }
Example #24
0
        /// <summary>
        /// 设置夹点
        /// </summary>
        public override void SetGripPointAt(int index, GripPoint gripPoint, LitMath.Vector2 newPosition)
        {
            if (index == 0)
            {
                _center = newPosition;
            }
            else if (index >= 1 && index <= 3)
            {
                LitMath.Vector2 startPoint  = this.startPoint;
                LitMath.Vector2 endPoint    = this.endPoint;
                LitMath.Vector2 middlePoint = this.middlePoint;

                if (index == 1)
                {
                    startPoint  = newPosition;
                    middlePoint = (LitMath.Vector2)gripPoint.xData1;
                }
                else if (index == 2)
                {
                    endPoint    = newPosition;
                    middlePoint = (LitMath.Vector2)gripPoint.xData1;
                }
                else if (index == 3)
                {
                    middlePoint = newPosition;
                }

                LitMath.Circle2 newCircle = LitMath.Circle2.From3Points(
                    startPoint, middlePoint, endPoint);
                if (newCircle.radius > 0)
                {
                    LitMath.Vector2 xPositive  = new LitMath.Vector2(1, 0);
                    double          startAngle = LitMath.Vector2.SignedAngleInRadian(xPositive,
                                                                                     startPoint - newCircle.center);
                    double endAngle = LitMath.Vector2.SignedAngleInRadian(xPositive,
                                                                          endPoint - newCircle.center);
                    double middleAngle = LitMath.Vector2.SignedAngleInRadian(xPositive,
                                                                             middlePoint - newCircle.center);
                    startAngle  = MathUtils.NormalizeRadianAngle(startAngle);
                    endAngle    = MathUtils.NormalizeRadianAngle(endAngle);
                    middleAngle = MathUtils.NormalizeRadianAngle(middleAngle);

                    _center = newCircle.center;
                    _radius = newCircle.radius;
                    if (AngleInArcRange(middleAngle, startAngle, endAngle))
                    {
                        this.startAngle = startAngle;
                        this.endAngle   = endAngle;
                    }
                    else
                    {
                        this.startAngle = endAngle;
                        this.endAngle   = startAngle;
                    }
                }
            }
        }
Example #25
0
 public Bounding(LitMath.Vector2 center, double width, double height)
 {
     _left   = center.x - width / 2.0;
     _right  = center.x + width / 2.0;
     _bottom = center.y - height / 2.0;
     _top    = center.y + height / 2.0;
     _width  = _right - _left;
     _height = _top - _bottom;
 }
Example #26
0
        internal void OnPaint(Graphics graphics)
        {
            if (_isShowAnchor)
            {
                _anchorMgr.OnPaint(graphics);
            }

            switch (_mode)
            {
            case Mode.Default:
            {
                if (_selRect != null)
                {
                    _selRect.OnPaint(graphics);
                }
                else
                {
                    LitMath.Vector2 currSnapPointInCanvas = _presenter.ModelToCanvas(_currSnapPoint);
                    graphics.DrawImage(_bitmap,
                                       (float)(currSnapPointInCanvas.x - _bitmap.Width / 2),
                                       (float)(currSnapPointInCanvas.y - _bitmap.Height / 2));
                }
            }
            break;

            case Mode.Select:
                if (_selRect != null)
                {
                    _selRect.OnPaint(graphics);
                }
                else
                {
                    graphics.DrawImage(_bitmap,
                                       (float)(_pos.x - _bitmap.Width / 2),
                                       (float)(_pos.y - _bitmap.Height / 2));
                }
                break;

            case Mode.Locate:
            {
                LitMath.Vector2 currSnapPointInCanvas = _presenter.ModelToCanvas(_currSnapPoint);
                graphics.DrawImage(_bitmap,
                                   (float)(currSnapPointInCanvas.x - _bitmap.Width / 2),
                                   (float)(currSnapPointInCanvas.y - _bitmap.Height / 2));

                _presenter.canvasDraw.graphics = graphics;
                _snapNodesMgr.OnPaint(_presenter.canvasDraw);
            }
            break;

            case Mode.Drag:
                break;

            default:
                break;
            }
        }
Example #27
0
        /// <summary>
        /// Transform
        /// </summary>
        public override void TransformBy(LitMath.Matrix3 transform)
        {
            LitMath.Vector2 pntX = _center + new LitMath.Vector2(_radiusX, 0);
            LitMath.Vector2 pntY = _center + new LitMath.Vector2(0, _radiusY);

            _center  = transform * _center;
            _radiusX = (transform * pntX - _center).length;
            _radiusY = (transform * pntY - _center).length;
        }
Example #28
0
        public override EventResult OnMouseDown(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _mousePosInWorld = this.pointer.currentSnapPoint;
                _mgr.FinishCurrentCommand();
            }

            return(EventResult.Handled);
        }
Example #29
0
 /// <summary>
 /// 设置夹点
 /// </summary>
 public override void SetGripPointAt(int index, GripPoint gripPoint, LitMath.Vector2 newPosition)
 {
     if (index == 0)
     {
         _startPoint = newPosition;
     }
     else if (index == 1)
     {
         _endPoint = newPosition;
     }
 }
Example #30
0
 /// <summary>
 /// 设置夹点
 /// </summary>
 public override void SetGripPointAt(int index, GripPoint gripPoint, LitMath.Vector2 newPosition)
 {
     if (index == 0)
     {
         _center = newPosition;
     }
     else if (index >= 1 && index <= 4)
     {
         _radius = (newPosition - _center).length;
     }
 }