Exemple #1
0
        public override void Draw(Graphics g, float scale = 1.0f)
        {
            if (_start_point.Equals(_end_point))
            {
                return;
            }

            PointF _scaledStartPoint = new PointF(_start_point.X * scale, _start_point.Y * scale);
            PointF _scaledEndPoint   = new PointF(_end_point.X * scale, _end_point.Y * scale);

            if (_pen == null || _invalidated)
            {
                _pen           = new Pen(new LinearGradientBrush(_scaledStartPoint, _scaledEndPoint, _color, _end_color));
                _pen.Width     = _width;
                _pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Center;

                _invalidated = false;
            }

            _pen.ScaleTransform(scale, scale);

            Matrix rotationMatrix = new Matrix();

            rotationMatrix.RotateAt(-_angle, _scaledStartPoint, MatrixOrder.Append);

            Matrix originalMatrix = g.Transform;

            g.Transform = rotationMatrix;
            g.DrawLine(_pen, _scaledStartPoint, _scaledEndPoint);
            g.Transform = originalMatrix;
        }
Exemple #2
0
 public void TestEquals()
 {
     Assert.AreEqual(pt11_99, pt11_99, "EQ#1");
     Assert.AreEqual(pt11_99, new PointF(1.1F, 9.9F), "EQ#2");
     Assert.IsFalse(pt11_99.Equals(pt11_0), "EQ#3");
     Assert.IsFalse(pt11_99.Equals(pt0_11), "EQ#4");
     Assert.IsFalse(pt11_0.Equals(pt0_11), "EQ#5");
 }
Exemple #3
0
        public static void EqualityTest_NotPointF()
        {
            var point = new PointF(0, 0);

            Assert.False(point.Equals(null));
            Assert.False(point.Equals(0));
            Assert.False(point.Equals(new Point(0, 0)));
        }
Exemple #4
0
        public static void EqualityTest_NotPointF()
        {
            var point = new PointF(0, 0);

            Assert.False(point.Equals(null));
            Assert.False(point.Equals(0));
            Assert.True(point.Equals(new Point(0, 0)));          // Implicit cast
            Assert.False(point.Equals((object)new Point(0, 0))); // No implicit cast
        }
Exemple #5
0
        //checks if triangle has common vertex with given point
        public bool commonVertex(PointF point)
        {
            bool common = false;

            if (point.Equals(this.p1) ||
                point.Equals(this.p2) ||
                point.Equals(this.p3))
            {
                common = true;
            }

            return(common);
        }
Exemple #6
0
        public override VerbResult Float(EditableView.ClickPosition position)
        {
            if (m_DefinedVertices < 2)
            {
                return(base.Float(position));
            }
            // actually floating point 1 in this case and 0 and 2 are fixed
            PointF pt = position.Snapped;

            if (pt.Equals(Vertices[1]))
            {
                return(VerbResult.Unchanged);
            }

            // find point on base line closest to floating point.
            PointF closest = Geometry.ClosestPointOnLine(Vertices[0], Vertices[2], pt);
            // vector from that to float gives us the vector for the second axis (effectively it's ony the length that matters)
            PointF centre         = Geometry.MidPoint(Vertices[0], Vertices[2]);
            SizeF  halfSecondAxis = closest.VectorTo(pt);

            Vertices[1]  = centre + halfSecondAxis;
            Vertices[3]  = centre - halfSecondAxis;
            m_Acceptable = !Geometry.PointApproxOnLine(Vertices[0], Vertices[2], Vertices[1]);

            m_Bounds = CalculateBounds();
            DiscardPath();
            return(VerbResult.Continuing);
        }
Exemple #7
0
        public override VerbResult Float(EditableView.ClickPosition position)
        {
            // let the base class take care of positioning the first line
            if (m_DefinedVertices < 2)
            {
                return(base.Float(position));
            }
            // need to calculate the coordinates of the fourth point.  We can add the 1>2 vector onto point 0
            Debug.Assert(Vertices.Count == 4);
            PointF newPoint = Geometry.PerpendicularPoint(Vertices[0], Vertices[1], position.Snapped);

            if (newPoint.Equals(Vertices[2]))
            {
                return(VerbResult.Unchanged);
            }
            if (newPoint.ApproxEqual(Vertices[1]))
            {
                return(VerbResult.Rejected);
            }
            Vertices[2] = newPoint;
            SizeF vector = Vertices[1].VectorTo(Vertices[2]);

            Vertices[3]  = PointF.Add(Vertices[0], vector);
            m_Bounds     = CalculateBounds();
            m_Acceptable = !VerticesFormLine(0);
            DiscardPath();
            return(VerbResult.Continuing);
        }
Exemple #8
0
        public bool CanBuilt(PointF pos)
        {
            if (Mode != ControlMode.Build)
            {
                return(false);
            }

            foreach (var item in Form1.gameObjects.OfType <Enemy>())
            {
                if (pos.Equals(PointExtensions.RoundPointF(item.WorldPosition)) || pos.Equals(GameField.MyGameField.Start) || pos.Equals(GameField.MyGameField.Finish))
                {
                    return(false);
                }
            }
            return(true);
        }
        public static IEnumerable <PointF> DensifyPoints(IEnumerable <PointF> points, double step)
        {
            PointF prevPoint = new PointF(3.40282347E+38f, 3.40282347E+38f);

            foreach (PointF point in points)
            {
                if (prevPoint.X != 3.4028234663852886E+38 && !prevPoint.Equals(point))
                {
                    PointF pointF     = point;
                    float  dx         = pointF.X - prevPoint.X;
                    PointF pointF2    = point;
                    float  dy         = pointF2.Y - prevPoint.Y;
                    int    stepCountX = (int)Math.Round(Math.Abs((double)dx / step));
                    int    stepCountY = (int)Math.Round(Math.Abs((double)dy / step));
                    int    stepCount  = Math.Max(stepCountX, stepCountY);
                    if (stepCount > 0)
                    {
                        float stepX = dx / (float)stepCount;
                        float stepY = dy / (float)stepCount;
                        for (int i = 0; i < stepCount - 1; i++)
                        {
                            prevPoint.X += stepX;
                            prevPoint.Y += stepY;
                            yield return(prevPoint);
                        }
                    }
                }
                yield return(point);

                prevPoint = point;
            }
        }
Exemple #10
0
        internal static IEnumerable <PointF> DensifyPoints(IEnumerable <PointF> points, double step)
        {
            PointF prevPoint = new PointF(float.MaxValue, float.MaxValue);

            foreach (PointF point in points)
            {
                if (prevPoint.X != float.MaxValue && !prevPoint.Equals(point))
                {
                    float num       = point.X - prevPoint.X;
                    float num2      = point.Y - prevPoint.Y;
                    int   val       = (int)Math.Round(Math.Abs((double)num / step));
                    int   val2      = (int)Math.Round(Math.Abs((double)num2 / step));
                    int   stepCount = Math.Max(val, val2);
                    if (stepCount > 0)
                    {
                        float stepX = num / (float)stepCount;
                        float stepY = num2 / (float)stepCount;
                        for (int i = 0; i < stepCount - 1; i++)
                        {
                            prevPoint.X += stepX;
                            prevPoint.Y += stepY;
                            yield return(prevPoint);
                        }
                    }
                }
                yield return(point);

                prevPoint = point;
            }
        }
Exemple #11
0
        public override void Draw(Graphics g)
        {
            if (_start_point.Equals(_end_point))
            {
                return;
            }

            if (_pen == null)
            {
                _pen           = new Pen(new LinearGradientBrush(_start_point, _end_point, _color, _end_color));
                _pen.Width     = _width;
                _pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Center;
            }

            g.DrawLine(_pen, _start_point, _end_point);
        }
Exemple #12
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     base.OnMouseMove(e);
     if (m_CurrentTool != null && m_CurrentTool is PartSelectionTool && m_SelectedPart != null)
     {
         if (e.Button != MouseButtons.Left)
         {
             return;
         }
         PointF newloc = AlignToGrid(new PointF(e.X - m_SelectionOffset.X, e.Y - m_SelectionOffset.Y));
         if (newloc.Equals(m_SelectedPart.Location) == false)
         {
             if (m_GrabHandle == null)
             {
                 m_SelectedPart.Location = AlignToGrid(new PointF(e.X - m_SelectionOffset.X, e.Y - m_SelectionOffset.Y));
             }
             else
             {
                 m_GrabHandle.Location = AlignToGrid(new PointF(e.X - m_SelectionOffset.X, e.Y - m_SelectionOffset.Y));
             }
             RaiseChangedEvent();
             UpdateBackground();
             UpdateDrawing();
             Invalidate();
         }
     }
 }
Exemple #13
0
        public static void EqualityTest_NotPointF()
        {
            var point = new PointF(0, 0);

            Assert.False(point.Equals(null));
            Assert.False(point.Equals(0));

            // If PointF implements IEquatable<PointF> (e.g. in .NET Core), then classes that are implicitly
            // convertible to PointF can potentially be equal.
            // See https://github.com/dotnet/runtime/issues/16050.
            bool expectsImplicitCastToPointF = typeof(IEquatable <PointF>).IsAssignableFrom(point.GetType());

            Assert.Equal(expectsImplicitCastToPointF, point.Equals(new Point(0, 0)));

            Assert.False(point.Equals((object)new Point(0, 0))); // No implicit cast
        }
Exemple #14
0
 public bool Equals(AnimationLine p)
 {
     return(_color.Equals(p._color) &&
            _end_color.Equals(p._end_color) &&
            _start_point.Equals(p._start_point) &&
            _end_point.Equals(p._end_point) &&
            _width.Equals(p._width));
 }
Exemple #15
0
 public void CalcPosition(float shift, PointF target)
 {
     if (!target.Equals(pos))
     {
         pos.X = CalcCoord(pos.X, target.X, shift);
         pos.Y = CalcCoord(pos.Y, target.Y, shift);
     }
 }
Exemple #16
0
 /// <summary>
 /// Handles the action related to a click event (nothing)
 /// </summary>
 /// <param name="sender">the picture box</param>
 /// <param name="e">the mouse event</param>
 internal override void ClickEvent(object sender, EventArgs e)
 {
     if (!lastDownPosition.Equals(new PointF(-1, -1)) && this.downPosition.Equals(new PointF(-1, -1)))
     {
         destiniation = currentPosition;
         DirectBees();
     }
 }
Exemple #17
0
 public bool contains(SuperPoint point)
 {
     if (p.Equals(point.P) || q.Equals(point.P))
     {
         return(true);
     }
     return(false);
 }
Exemple #18
0
        public bool contains(PointF point)
        {
            if (p.Equals(point) || q.Equals(point))
            {
                return(true);
            }

            return(false);
        }
Exemple #19
0
        public void EqualityTest(float x, float y)
        {
            PointF pLeft  = new PointF(x, y);
            PointF pRight = new PointF(y, x);

            if (x == y)
            {
                Assert.True(pLeft == pRight);
                Assert.False(pLeft != pRight);
                Assert.True(pLeft.Equals(pRight));
                Assert.Equal(pLeft.GetHashCode(), pRight.GetHashCode());
                return;
            }

            Assert.True(pLeft != pRight);
            Assert.False(pLeft == pRight);
            Assert.False(pLeft.Equals(pRight));
        }
Exemple #20
0
        internal bool TryPoint(PointF trialPoint, SizeF rectangle)
        {
            if (trialPoint.Equals(spiralEndSentinel))
            {
                return(true);
            }
            var trailRectangle = new RectangleF(trialPoint, rectangle);

            return(!Occupied.Any(x => x.IntersectsWith(trailRectangle)));
        }
Exemple #21
0
        //TPS中的U函数
        private double U_r(PointF p1, PointF p2)
        {
            if (p1.Equals(p2))
            {
                return(0);
            }
            double r2 = (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y);

            return(r2 * (double)Math.Log(r2));
        }
Exemple #22
0
        public override bool Equals(object obj)
        {
            // If parameter is null return false.
            if (obj == null)
            {
                return(false);
            }

            // If parameter cannot be cast to Point return false.
            Edge e = obj as Edge;

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

            // Return true if the fields match:
            return((A.Equals(e.A) && B.Equals(e.B)) || (A.Equals(e.B) && B.Equals(e.A)));
        }
Exemple #23
0
        private void tmrWaypoint_Tick(object sender, EventArgs e)
        {
            PointF position = new PointF(LocalPlayer.XPos, LocalPlayer.YPos);

            if (!position.Equals(OldPosition))
            {
                OldPosition = position;
                waypoints.Add(position);
            }
        }
Exemple #24
0
        /// <summary>
        /// 基线与峰相交处理
        ///
        /// 保证基线不与峰上的点相交
        /// </summary>
        /// <returns></returns>
        private string BaselineCrossOperate(int index)
        {
            try
            {
                if (index < 0 || index >= _list.Count)
                {
                    return("");
                }
                bool negative = (this[index].PeakPoint.Y < this[index].StartPoint.Y && this[index].PeakPoint.Y < this[index].EndPoint.Y);
                if (negative)
                {
                    return("");
                }

                string operates = "";
                string operate  = "";
                PointF pt       = PointF.Empty;
                //结束基线与峰相交
                if (_list[index].PeakState != Peak.PeakStates.ps_natural)
                {
                    return("");
                }
                bool BaseLineStart = (FrontIndexOf(index) == -1);

                pt = GetStartBaselineCrossPoint(this[index], BaseLineStart);
                if (pt != PointF.Empty && !pt.Equals(this[index].StartPoint))
                {
                    operates = PeakProcessor.ChangeSEPoint(_list, index, Parent[pt.X], true);
                }
                pt = GetEndBaselineCrossPoint(this[index], BaseLineStart);
                if (pt != PointF.Empty && !pt.Equals(this[index].EndPoint))
                {
                    operate = PeakProcessor.ChangeSEPoint(_list, index, Parent[pt.X], false);
                }
                operates += operate;
                return(operates);
            }
            catch
            {
                return("");
            }
        }
Exemple #25
0
 public bool Equivalent(Triangle o)
 {
     if (!IsValid || !o.IsValid)
     {
         return(false);
     }
     if (A.Equals(o.A) && (B.Equals(o.B) && C.Equals(o.C) || B.Equals(o.C) && C.Equals(o.B)))
     {
         return(true);
     }
     if (A.Equals(o.B) && (B.Equals(o.A) && C.Equals(o.C) || B.Equals(o.C) && C.Equals(o.A)))
     {
         return(true);
     }
     if (A.Equals(o.C) && (B.Equals(o.A) && C.Equals(o.B) || B.Equals(o.B) && C.Equals(o.A)))
     {
         return(true);
     }
     return(false);
 }
Exemple #26
0
        public PointF GetStartMaterialWorldPoint()
        {
            var x  = bottomLeftPosition.x;
            var y  = bottomLeftPosition.y;
            var cs = (float)Graphx.CellSize;

            if (direction.Equals(LEFT))
            {
                return(new PointF((x + 1) * cs - 2, (y + 0.5f) * cs));
            }
            if (direction.Equals(RIGHT))
            {
                return(new PointF(x * cs + 2, (y + 0.5f) * cs));
            }
            if (direction.Equals(UP))
            {
                return(new PointF((x + 0.5f) * cs, (y + 1) * cs - 2));
            }
            return(new PointF((x + 0.5f) * cs, y * cs + 2));
        }
Exemple #27
0
        public void Normalize()
        {
            const float epsilon = 0.0001f;

            Assert.IsTrue(PointD.Equals(new PointD(-1, 0), new PointD(-1, 0).Normalize(), epsilon));
            Assert.IsTrue(PointD.Equals(new PointD(0, -1), new PointD(0, -0.5).Normalize(), epsilon));
            Assert.IsTrue(PointD.Equals(new PointD(0.447213, 0.894428), pointD.Normalize(), epsilon));

            Assert.IsTrue(PointF.Equals(new PointF(-1, 0), new PointF(-1, 0).Normalize(), epsilon));
            Assert.IsTrue(PointF.Equals(new PointF(0, -1), new PointF(0, -0.5f).Normalize(), epsilon));
            Assert.IsTrue(PointF.Equals(new PointF(0.447213f, 0.894428f), pointF.Normalize(), epsilon));
        }
Exemple #28
0
        public void FromPolar()
        {
            const float epsilon = 0.0001f;

            Assert.IsTrue(PointD.Equals(pointD, PointD.FromPolar(pointD.Length, pointD.Angle), epsilon));
            Assert.IsTrue(PointF.Equals(pointF, PointF.FromPolar(pointF.Length, pointF.Angle), epsilon));
            Assert.AreEqual(pointI, PointI.FromPolar(pointI.Length, pointI.Angle));

            Assert.IsTrue(PointD.Equals(new PointD(-1, -2),
                                        PointD.FromPolar(-pointD.Length, pointD.Angle), epsilon));
            Assert.IsTrue(PointF.Equals(new PointF(-1, -2),
                                        PointF.FromPolar(-pointF.Length, pointF.Angle), epsilon));
            Assert.AreEqual(new PointI(-1, -2), PointI.FromPolar(-pointI.Length, pointI.Angle));
        }
Exemple #29
0
 public override bool Equals(object obj)
 {
     return((obj is PathGradientBrush b) &&
            pathPoints.Equals(b.pathPoints) &&
            wrapMode.Equals(b.wrapMode) &&
            gradientTransform.Equals(b.gradientTransform) &&
            centerColor.Equals(b.centerColor) &&
            focusScales.Equals(b.focusScales) &&
            surroundColors.Equals(b.surroundColors) &&
            colorBlend.Equals(b.colorBlend) &&
            rectangle.Equals(b.rectangle) &&
            centerPoint.Equals(b.centerPoint) &&
            polygonWinding.Equals(b.polygonWinding) &&
            blend.Equals(b.blend));
 }
Exemple #30
0
        /// <summary>
        /// Checks whether the given point lies on the line segment.
        /// </summary>
        public bool ContainsInSegment(PointF point)
        {
            if (point.Equals(_a) || point.Equals(_b))
            {
                return(true);
            }

            if (!Bounds.Contains(point))
            {
                return(false);
            }

            if (_a.X == _b.X)
            {
                return(point.X == _a.X);
            }
            if (_a.Y == _b.Y)
            {
                return(point.Y == _a.Y);
            }

            return((point.X - _a.X) * (_b.Y - _a.Y) ==
                   (point.Y - _a.Y) * (_b.X - _a.X));
        }
Exemple #31
0
 public static void EqualityTest_NotPointF()
 {
     var point = new PointF(0, 0);
     Assert.False(point.Equals(null));
     Assert.False(point.Equals(0));
     Assert.False(point.Equals(new Point(0, 0)));
 }
Exemple #32
0
        public void EqualityTest(float x, float y)
        {
            PointF pLeft = new PointF(x, y);
            PointF pRight = new PointF(y, x);

            if (x == y)
            {
                Assert.True(pLeft == pRight);
                Assert.False(pLeft != pRight);
                Assert.True(pLeft.Equals(pRight));
                Assert.Equal(pLeft.GetHashCode(), pRight.GetHashCode());
                return;
            }

            Assert.True(pLeft != pRight);
            Assert.False(pLeft == pRight);
            Assert.False(pLeft.Equals(pRight));
        }