Equals() public method

public Equals ( object obj ) : bool
obj object
return bool
Ejemplo n.º 1
0
 public Line2DBase(PointF p1, PointF p2, Pen pen)
 {
     this.Pen = pen;
     if (!p1.Equals(p2))
     {
         Point1 = p1;
         Point2 = p2;
     }
     else
     {
         throw new System.ArithmeticException("Points are equals");
     }
 }
Ejemplo n.º 2
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));
 }
        private void pb_Paint(object sender, PaintEventArgs e)
        {
            Image img;
            img = ShapeMaker.Properties.Resources.bg;

            PointF loopBack = new PointF(-9999, -9999);
            PointF Oldxy = new PointF(-9999, -9999);

            ImageAttributes attr = new ImageAttributes();
            ColorMatrix mx = new ColorMatrix();
            mx.Matrix33 = (1001f - (float)opaque.Value) / 1000f;
            attr.SetColorMatrix(mx);
            using (TextureBrush texture =
                new TextureBrush(img, new Rectangle(0, 0, img.Width, img.Height), attr))
            {
                texture.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
                e.Graphics.FillRectangle(texture, e.ClipRectangle);
            }
            attr.Dispose();

            int ltype = 0;
            bool ctype = false;
            bool mpmode = false;
            bool islarge = false;
            bool revsweep = false;
            try
            {
                int j;
                for (int jj = -1; jj < Lines.Count; jj++)
                {
                    j = jj + 1;
                    if (j == Lines.Count && LineList.SelectedIndex == -1) j = -1;
                    PointF[] line;

                    if (j > -1)
                    {
                        if (j == LineList.SelectedIndex)
                        {
                            line = pbpoint;
                            ltype = getLType();
                            ctype = Loop.Checked;
                            mpmode = MPMode.Checked;
                            islarge = Big.Checked;
                            revsweep = Sweep.Checked;
                            //continue;
                        }
                        else
                        {
                            line = (Lines[j] as PData).Lines;
                            ltype = (Lines[j] as PData).LineType;
                            ctype = (Lines[j] as PData).ClosedType;
                            mpmode = (Lines[j] as PData).LoopBack;
                            islarge = (Lines[j] as PData).IsLarge;
                            revsweep = (Lines[j] as PData).RevSweep;
                        }
                    }
                    else
                    {
                        line = pbpoint;
                        ltype = getLType();
                        ctype = Loop.Checked;
                        mpmode = MPMode.Checked;
                        islarge = Big.Checked;
                        revsweep = Sweep.Checked;
                    }

                    PointF[] pts = new PointF[line.Length];
                    PointF[] Qpts = new PointF[line.Length];
                    for (int i = 0; i < line.Length; i++)
                    {
                        float x = (sender as PictureBox).ClientSize.Width * line[i].X;
                        float y = (sender as PictureBox).ClientSize.Height * line[i].Y;
                        pts[i] = new PointF(x, y);
                    }
                    #region cube to quad
                    if (ltype == (int)LineTypes.Quadratic || ltype == (int)LineTypes.SmoothQuadratic)
                    {
                        for (int i = 0; i < line.Length; i++)
                        {
                            int PT = getPtype(i);
                            if (PT == 0)
                            {
                                Qpts[i] = pts[i];
                            }
                            else if (PT == 1)
                            {
                                Qpts[i] = new PointF(pts[i].X * 2f / 3f + pts[i - 1].X * 1f / 3f,
                                    pts[i].Y * 2f / 3f + pts[i - 1].Y * 1f / 3f);
                            }
                            else if (PT == 2)
                            {
                                Qpts[i] = new PointF(pts[i - 1].X * 2f / 3f + pts[i + 1].X * 1f / 3f,
                                    pts[i - 1].Y * 2f / 3f + pts[i + 1].Y * 1f / 3f);
                            }

                            else if (PT == 3)
                            {
                                Qpts[i] = pts[i];
                            }
                        }

                    }
                    #endregion

                    bool islinked = true;
                    if (pts.Length > 0 && !Oldxy.Equals(pts[0]))
                    {
                        loopBack = new PointF(pts[0].X, pts[0].Y);
                        islinked = false;
                    }

                    //render lines
                    e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

                    if ((Control.ModifierKeys & Keys.Control) != Keys.Control)
                    {
                        #region draw handles
                        if ((j == -1 || j == LineList.SelectedIndex) && line.Length >= 1) //buffer draw
                        {

                            if ((ctype || mpmode) && pts.Length > 1)
                            {
                                e.Graphics.DrawRectangle(new Pen(AnchorColor), loopBack.X - 4, loopBack.Y - 4, 6, 6);
                            }
                            else if (islinked)
                            {
                                PointF[] tri = {new PointF(pts[0].X, pts[0].Y - 4f),
                                                new PointF(pts[0].X + 3f, pts[0].Y + 3f),
                                                new PointF(pts[0].X - 4f, pts[0].Y + 3f)};
                                e.Graphics.DrawPolygon(new Pen(AnchorColor), tri);
                            }
                            else
                            {

                                e.Graphics.DrawEllipse(new Pen(AnchorColor), pts[0].X - 4, pts[0].Y - 4, 6, 6);
                            }

                            for (int i = 1; i < pts.Length; i++)
                            {

                                switch (ltype)
                                {
                                    case (int)LineTypes.Straight:
                                        e.Graphics.DrawEllipse(Pens.Black, pts[i].X - 4, pts[i].Y - 4, 6, 6);
                                        break;
                                    case (int)LineTypes.Ellipse:
                                        if (i == 4)
                                        {
                                            PointF mid = pointAverage(pts[0], pts[4]);
                                            e.Graphics.DrawEllipse(Pens.Black, pts[4].X - 4, pts[4].Y - 4, 6, 6);
                                            if (!MacroCircle.Checked || LineList.SelectedIndex != -1)
                                            {
                                                e.Graphics.DrawRectangle(Pens.Black, pts[1].X - 4, pts[1].Y - 4, 6, 6);
                                                e.Graphics.FillEllipse(Brushes.Black, pts[3].X - 4, pts[3].Y - 4, 6, 6);
                                                e.Graphics.FillRectangle(Brushes.Black, pts[2].X - 4, pts[2].Y - 4, 6, 6);

                                                e.Graphics.DrawLine(Pens.Black, mid, pts[1]);
                                                e.Graphics.DrawLine(Pens.Black, mid, pts[2]);
                                                e.Graphics.DrawLine(Pens.Black, mid, pts[3]);

                                            }
                                            e.Graphics.DrawLine(Pens.Black, pts[0], pts[4]);
                                        }
                                        break;
                                    case (int)LineTypes.Quadratic:
                                        if (getPtype(i) == 1)
                                        {
                                            e.Graphics.DrawEllipse(Pens.Black, pts[i].X - 4, pts[i].Y - 4, 6, 6);
                                            e.Graphics.DrawLine(Pens.Black, pts[i - 1], pts[i]);
                                            e.Graphics.DrawEllipse(Pens.Black, pts[i + 2].X - 4, pts[i + 2].Y - 4, 6, 6);
                                            e.Graphics.DrawLine(Pens.Black, pts[i], pts[i + 2]);
                                        }
                                        break;
                                    case (int)LineTypes.SmoothQuadratic:
                                        if (getPtype(i) == 3)
                                        {
                                            e.Graphics.DrawEllipse(Pens.Black, pts[i].X - 4, pts[i].Y - 4, 6, 6);
                                        }
                                        break;
                                    case (int)LineTypes.Cubic:
                                    case (int)LineTypes.SmoothCubic:
                                        if (getPtype(i) == 1 & !MacroCubic.Checked)
                                        {
                                            e.Graphics.DrawEllipse(Pens.Black, pts[i].X - 4, pts[i].Y - 4, 6, 6);
                                            e.Graphics.DrawLine(Pens.Black, pts[i - 1], pts[i]);
                                            e.Graphics.DrawEllipse(Pens.Black, pts[i + 2].X - 4, pts[i + 2].Y - 4, 6, 6);
                                            e.Graphics.DrawEllipse(Pens.Black, pts[i + 1].X - 4, pts[i + 1].Y - 4, 6, 6);
                                            e.Graphics.DrawLine(Pens.Black, pts[i + 1], pts[i + 2]);
                                        }
                                        else if (getPtype(i) == 3 & MacroCubic.Checked)
                                        {
                                            e.Graphics.DrawEllipse(Pens.Black, pts[i].X - 4, pts[i].Y - 4, 6, 6);
                                        }

                                        break;
                                }

                            }

                        }
                        #endregion
                    }

                    #region drawlines
                    using (Pen p = new Pen(LineColors[ltype]))
                    {
                        p.DashStyle = DashStyle.Solid;
                        p.Width = 1;

                        if (line.Length > 3 && (ltype == (int)LineTypes.Quadratic || ltype == (int)LineTypes.SmoothQuadratic))
                        {
                            try
                            {
                                e.Graphics.DrawBeziers(p, Qpts);
                            }
                            catch { }
                        }
                        else if (line.Length > 3 && (ltype == (int)LineTypes.Cubic || ltype == (int)LineTypes.SmoothCubic))
                        {
                            try
                            {
                                e.Graphics.DrawBeziers(p, pts);
                            }
                            catch { }
                        }
                        else if (line.Length > 1 && ltype == (int)LineTypes.Straight)
                        {
                            if (MacroRect.Checked && j == -1 && LineList.SelectedIndex == -1)
                            {
                                for (int i = 1; i < pts.Length; i++)
                                {
                                    e.Graphics.DrawLine(p, new PointF(pts[i - 1].X, pts[i - 1].Y),
                                    new PointF(pts[i].X, pts[i - 1].Y));
                                    e.Graphics.DrawLine(p, new PointF(pts[i].X, pts[i - 1].Y),
                                    new PointF(pts[i].X, pts[i].Y));
                                    e.Graphics.DrawLine(p, new PointF(pts[i].X, pts[i].Y),
                                    new PointF(pts[i - 1].X, pts[i].Y));
                                    e.Graphics.DrawLine(p, new PointF(pts[i - 1].X, pts[i].Y),
                                    new PointF(pts[i - 1].X, pts[i - 1].Y));

                                }
                            }
                            else
                            {

                                e.Graphics.DrawLines(p, pts);
                            }
                        }
                        else if (line.Length == 5 && ltype == (int)LineTypes.Ellipse)
                        {
                            PointF mid = pointAverage(pts[0], pts[4]);
                            if (MacroCircle.Checked && j == -1 && LineList.SelectedIndex == -1)
                            {
                                float far = pythag(pts[0], pts[4]);
                                e.Graphics.DrawEllipse(p, mid.X - far / 2f, mid.Y - far / 2f, far, far);
                            }
                            else
                            {
                                float l = pythag(mid, pts[1]);
                                float h = pythag(mid, pts[2]);
                                float a = (float)(Math.Atan2(pts[3].Y - mid.Y, pts[3].X - mid.X) * 180 / Math.PI);
                                if ((int)h == 0 || (int)l == 0)
                                {
                                    PointF[] nullLine = new PointF[] { pts[0], pts[4] };
                                    e.Graphics.DrawLines(p, nullLine);
                                }
                                else
                                {

                                    using (GraphicsPath gp = new GraphicsPath())
                                    {
                                        AddPath(gp, pts[0]
                                        , l, h, a,
                                        (islarge) ? 1 : 0,
                                        (revsweep) ? 1 : 0,
                                        pts[4]);
                                        e.Graphics.DrawPath(p, gp);
                                    }
                                    if (j == -1 && line.Length >= 1)
                                    {
                                        if (!MacroCircle.Checked || LineList.SelectedIndex != -1)
                                        {
                                            using (GraphicsPath gp = new GraphicsPath())
                                            {
                                                AddPath(gp, pts[0]
                                                , l, h, a,
                                                (islarge) ? 0 : 1,
                                                (revsweep) ? 0 : 1,
                                                pts[4]);
                                                using (Pen p2 = new Pen(Color.LightGray))
                                                {
                                                    p2.DashStyle = DashStyle.Dash;
                                                    e.Graphics.DrawPath(p2, gp);
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                        }
                        //join line
                        bool noJoin = false;
                        if (j == -1)
                        {
                            if (MacroCircle.Checked && Ellipse.Checked) noJoin = true;
                            if (MacroRect.Checked && StraightLine.Checked) noJoin = true;
                        }

                        if (!mpmode)
                        {
                            if (!noJoin && ctype && pts.Length > 1)
                            {
                                e.Graphics.DrawLine(p, pts[0], pts[pts.Length - 1]);//preserve
                                loopBack = pts[pts.Length - 1];
                            }
                        }
                        else
                        {
                            //if (!noJoin && ctype && pts.Length > 1)
                            if (!noJoin && pts.Length > 1)
                            {
                                e.Graphics.DrawLine(p, pts[pts.Length - 1], loopBack);

                                loopBack = pts[pts.Length - 1];
                            }
                        }
                    }
                    #endregion
                    Oldxy = pts[pts.Length - 1];
                }
            }
            catch { }//(Exception ex) { label7.Text = ex.Message; }
        }
        private void MakePath()
        {
            int ltype = 0;
            bool ctype = false;
            bool mpmode = false;
            bool islarge = false;
            bool revsweep = false;
            PointF loopBack = new PointF(-9999, -9999);
            PointF Oldxy = new PointF(-9999, -9999);

            Array.Resize(ref PGP, Lines.Count);

            for (int j = 0; j < Lines.Count; j++)
            {
                PointF[] line;
                try
                {
                    PGP[j] = new GraphicsPath();
                }
                catch (Exception e) { MessageBox.Show(e.Message); }

                line = (Lines[j] as PData).Lines;
                ltype = (Lines[j] as PData).LineType;
                ctype = (Lines[j] as PData).ClosedType;
                mpmode = (Lines[j] as PData).LoopBack;
                islarge = (Lines[j] as PData).IsLarge;
                revsweep = (Lines[j] as PData).RevSweep;

                PointF[] pts = new PointF[line.Length];
                PointF[] Qpts = new PointF[line.Length];
                for (int i = 0; i < line.Length; i++)
                {
                    float x = (float)OutputScale.Value * (float)SuperSize.Width / 100f * line[i].X;
                    float y = (float)OutputScale.Value * (float)SuperSize.Height / 100f * line[i].Y;
                    pts[i] = new PointF(x, y);
                }
                #region cube to quad
                if (ltype == (int)LineTypes.Quadratic || ltype == (int)LineTypes.SmoothQuadratic)
                {
                    for (int i = 0; i < line.Length; i++)
                    {
                        int PT = getPtype(i);
                        if (PT == 0)
                        {
                            Qpts[i] = pts[i];
                        }
                        else if (PT == 1)
                        {
                            Qpts[i] = new PointF(pts[i].X * 2f / 3f + pts[i - 1].X * 1f / 3f,
                                pts[i].Y * 2f / 3f + pts[i - 1].Y * 1f / 3f);
                        }
                        else if (PT == 2)
                        {
                            Qpts[i] = new PointF(pts[i - 1].X * 2f / 3f + pts[i + 1].X * 1f / 3f,
                                pts[i - 1].Y * 2f / 3f + pts[i + 1].Y * 1f / 3f);
                        }

                        else if (PT == 3)
                        {
                            Qpts[i] = pts[i];
                        }
                    }

                }
                #endregion

                if (pts.Length > 0 && !Oldxy.Equals(pts[0]))
                {
                    loopBack = new PointF(pts[0].X, pts[0].Y);
                }
                //render lines

                #region drawlines

                if (line.Length > 3 && (ltype == (int)LineTypes.Quadratic || ltype == (int)LineTypes.SmoothQuadratic))
                {
                    try
                    {
                        PGP[j].AddBeziers(Qpts);
                    }
                    catch { }
                }
                else if (line.Length > 3 && (ltype == (int)LineTypes.Cubic || ltype == (int)LineTypes.SmoothCubic))
                {
                    try
                    {
                        PGP[j].AddBeziers(pts);
                    }
                    catch { }
                }
                else if (line.Length > 1 && ltype == (int)LineTypes.Straight)
                {

                    PGP[j].AddLines(pts);

                }
                else if (line.Length == 5 && ltype == (int)LineTypes.Ellipse)
                {
                    PointF mid = pointAverage(pts[0], pts[4]);

                    float l = pythag(mid, pts[1]);
                    float h = pythag(mid, pts[2]);
                    float a = (float)(Math.Atan2(pts[3].Y - mid.Y, pts[3].X - mid.X) * 180 / Math.PI);
                    if ((int)h == 0 || (int)l == 0)
                    {
                        PointF[] nullLine = new PointF[] { pts[0], pts[4] };
                        PGP[j].AddLines(nullLine);
                    }
                    else
                    {

                        AddPath(PGP[j], pts[0]
                            , l, h, a,
                            (islarge) ? 1 : 0,
                            (revsweep) ? 1 : 0,
                            pts[4]);
                    }

                }
                //if (ctype && pts.Length > 1)
                //{
                //    PointF[] points = new PointF[] { pts[0], pts[pts.Length - 1] };
                //    PGP[j].AddLines(points);
                //}
                if (!mpmode)
                {
                    if (ctype && pts.Length > 1)
                    {
                        PointF[] points = new PointF[] { pts[0], pts[pts.Length - 1] };
                        PGP[j].AddLines(points);
                        loopBack = pts[pts.Length - 1];
                    }
                }
                else
                {
                    if (pts.Length > 1)
                    {
                        PointF[] points = new PointF[] { loopBack, pts[pts.Length - 1] };
                        PGP[j].AddLines(points);
                        loopBack = pts[pts.Length - 1];
                    }
                }
                #endregion
                Oldxy = pts[pts.Length - 1];
            }
        }
Ejemplo n.º 5
0
		private bool PreDrawLineOrArc(object param, DrawType drawtype, PointF from, PointF to)
		{
			PaintEventArgs e = (PaintEventArgs)param;

			if (from.Equals(to))
			{
				if (drawtype == DrawType.LaserCut)
					e.Graphics.DrawEllipse(GetPen(drawtype, LineDrawType.Dot), from.X, from.Y, 1, 1);
				else
					e.Graphics.DrawEllipse(GetPen(drawtype, LineDrawType.Dot), from.X, from.Y, 4, 4);

				return false;
			}
			return true;
		}
Ejemplo n.º 6
0
		//Removes points that are line with each other
		protected internal void RefinePoints()
		{
			if (Points.Count < 3) return;

			PointF lastPoint = new PointF();
			int index = 0;
			int loop = 0;

			//Loop through and see if there is an index to remove
			//Use the loop variable to make sure havent entered endless loop
			while (index < Points.Count && loop < Points.Count)
			{
				index = 0;
				loop += 1;
				foreach (PointF point in Points)
				{
					if (index > 0)
					{
						//Check if x co-ordinates are within the grain but not equal
						if (Math.Abs(point.X - lastPoint.X) < 1 && point.X != lastPoint.X)
						{
							if (lastPoint.Equals(Points[0]))
							{
								Points[index] = new PointF(lastPoint.X,point.Y);
							}
							else
							{
								Points[index-1] = new PointF(point.X,LastPoint.Y);
							}
							break;
						}
						//Check y coordinates are not equal but within the grain
						else if (Math.Abs(point.Y - lastPoint.Y) < 1 && point.Y != lastPoint.Y)
						{
							if (lastPoint.Equals(Points[0]))
							{
								Points[index] = new PointF(point.X,lastPoint.Y);
							}
							else
							{
								Points[index-1] = new PointF(lastPoint.X,point.Y);
							}
							break;
						}
					}
					lastPoint = (PointF) Points[index];
					index+=1;
				}
			}
			
			PointF secondLast = new PointF();
			PointF refPoint = new PointF();
			int remove = 0;

			while (remove != -1)
			{
				remove = -1;
				
				//Loop through and see if there is an index to remove
				foreach (PointF point in Points)
				{
					if (!lastPoint.IsEmpty)
					{
						if (!secondLast.IsEmpty)
						{
							//Check if x coordinates are in line
							if (secondLast.X == lastPoint.X && lastPoint.X == point.X)
							{	
								remove = Points.IndexOf(lastPoint);
								break;
							}
							//Check if y coordinates are in line
							if (secondLast.Y == lastPoint.Y && lastPoint.Y == point.Y)
							{	
								remove = Points.IndexOf(lastPoint);
								break;
							}
						}
						secondLast = lastPoint;
					}
					lastPoint = point;
				}

				//Remove point if required
				if (remove != -1) Points.RemoveAt(remove);
			}
		}
Ejemplo n.º 7
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);
		}
Ejemplo n.º 8
0
        private void setPoint2(PointF p = new PointF())
        {
            if (tabControl1.SelectedTab.Equals(tabCalibrate))
                {
                    if (!p.Equals(calibratePoint1.Point))
                        calibratePoint2.Point = p;
                    else
                        MessageBox.Show("Points can not be it the same location!");

                    if (!calibratePoint1.IsEmpty() && !calibratePoint2.IsEmpty()) // setPoint for calibration
                    {
                        distanceBetweenCalibratePoints = GetDistanceBetween(calibratePoint1.Point, calibratePoint2.Point);

                        CalculateScale();
                    }
                }
                else if (tabControl1.SelectedTab.Equals(tabAnalyze) && level == 3) // setPoint for analyze
                {
                    if (!p.Equals(images.getActual().point1.Point))
                    {
                        if (!images.getActual().point1.IsEmpty())
                        {

                            double distance = GetDistanceBetween(images.getActual().point1.Point, p);
                            double ratio = distanceBetweenCalibratePoints / distance;
                            double vectorX = ((p.X - images.getActual().point1.Point.X) * ratio) * (Double.Parse(tb_real_length.Text, CultureInfo.InvariantCulture) / 100) * (Double.Parse(tb_ideal_legth.Text, CultureInfo.InvariantCulture) / Double.Parse(tb_scale.Text, CultureInfo.InvariantCulture));
                            double vectorY = ((p.Y - images.getActual().point1.Point.Y) * ratio) * (Double.Parse(tb_real_length.Text, CultureInfo.InvariantCulture) / 100) * (Double.Parse(tb_ideal_legth.Text, CultureInfo.InvariantCulture) / Double.Parse(tb_scale.Text, CultureInfo.InvariantCulture));
                            images.getActual().setPoint2(new PointF((float)(images.getActual().point1.Point.X + vectorX), (float)(images.getActual().point1.Point.Y + vectorY)));

                            UpdateObjectFixedPoints();
                            UpdateInfo();
                        }
                        else
                            images.getActual().setPoint2(p);

                    }
                    else
                        MessageBox.Show("Points can not be it the same location!");
                }

                imageBox.Invalidate();
        }
Ejemplo n.º 9
0
		//Creates the solution from the calculated nodes as vectors
		public ArrayList GetSolution()
		{
			///Add an additional node to the end if the solution didnt match the goal
			if (mSolution.Equals(mGoal) || mSolution.Parent == null)
			{
				mGoal = mSolution;
			}
			else
			{
				//If in line then add the goal as a node to the solution, else move the solution node
				if (mSolution.X == mGoal.X || mSolution.Y == mGoal.Y)
				{
					mGoal.Parent = mSolution;
				}
				else
				{
					RouteNode extra = new RouteNode();
					extra.Parent = mSolution; 

					//Set node coordinates
					extra.X = (mSolution.X == mSolution.Parent.X) ? mSolution.X : mGoal.X;
					extra.Y = (mSolution.Y == mSolution.Parent.Y) ? mSolution.Y : mGoal.Y;
					
					//Link the goal to the new node and add it
					mGoal.Parent = extra;
				}
			}

			ArrayList list = new ArrayList();
			
			RouteNode previous = mGoal;
			RouteNode node = mGoal.Parent;
			
			list.Add(new PointF(previous.X, previous.Y));

			//Only one or two items
			if (node == null || node.Parent == null) return list;

			while (node.Parent != null)
			{
				if (!((previous.X == node.Parent.X) || (previous.Y == node.Parent.Y)))
				{
					list.Insert(0, new PointF(node.X, node.Y));
					previous = node;
				}
				node = node.Parent;
			}

			//Add the start node
			PointF start = new PointF(node.X, node.Y);
			if (!start.Equals((PointF) list[0])) list.Insert(0, start);
			
			return list;
		}
Ejemplo n.º 10
0
        protected void ManageMouseMoveDrawing(System.Windows.Forms.MouseEventArgs e, PointF mouseValuePoint)
        {
            switch (this.DrawingMode)
            {
                case GraphDrawMode.AddSAR:
                    if (this.DrawingStep == GraphDrawingStep.SelectItem)
                    {
                        // first point is already selected, draw new line
                        if (!selectedValuePoint.Equals(mouseValuePoint))
                        {
                            DrawTmpSAR(this.foregroundGraphic, mouseValuePoint);
                        }
                    }
                    break;
                case GraphDrawMode.AddLine:
                    if (this.DrawingStep == GraphDrawingStep.ItemSelected)
                    {
                        // first point is already selected, draw new line
                        if (!selectedValuePoint.Equals(mouseValuePoint))
                        {
                            DrawTmpItem(this.foregroundGraphic, this.DrawingPen, new Line2D(selectedValuePoint, mouseValuePoint), true, true);
                        }
                    }
                    break;
                case GraphDrawMode.AddSegment:
                    if (this.DrawingStep == GraphDrawingStep.ItemSelected)
                    {
                        // first point is already selected, draw new line
                        if (!selectedValuePoint.Equals(mouseValuePoint))
                        {
                            DrawTmpSegment(this.foregroundGraphic, this.DrawingPen, selectedValuePoint, mouseValuePoint, true, true);
                        }
                    }
                    break;
                case GraphDrawMode.AddHalfLine:
                    if (this.DrawingStep == GraphDrawingStep.ItemSelected)
                    {
                        // first point is already selected, draw new line
                        if (!selectedValuePoint.Equals(mouseValuePoint))
                        {
                            DrawTmpHalfLine(this.foregroundGraphic, this.DrawingPen, selectedValuePoint, mouseValuePoint, true, true);
                        }
                    }
                    break;
                case GraphDrawMode.FanLine:
                    if (this.DrawingStep == GraphDrawingStep.ItemSelected)
                    {
                        // first point is already selected, draw new line
                        if (!selectedValuePoint.Equals(mouseValuePoint))
                        {
                            DrawTmpItem(this.foregroundGraphic, this.DrawingPen, new Line2D(selectedValuePoint, mouseValuePoint), true, true);
                        }
                    }
                    break;
                case GraphDrawMode.AndrewPitchFork:
                    switch (this.DrawingStep)
                    {
                        case GraphDrawingStep.SelectItem: // Selecting the second point
                            if (andrewPitchFork != null && !andrewPitchFork.Point1.Equals(mouseValuePoint))
                            {
                                DrawTmpSegment(this.foregroundGraphic, this.DrawingPen, andrewPitchFork.Point1, mouseValuePoint, true, true);
                            }
                            break;
                        case GraphDrawingStep.ItemSelected: // Selecting third point

                            if (mouseValuePoint.Equals(andrewPitchFork.Point1) || mouseValuePoint.Equals(andrewPitchFork.Point2))
                            {
                                break;
                            }
                            andrewPitchFork.Point3 = mouseValuePoint;
                            try
                            {
                                foreach (Line2DBase newLine in andrewPitchFork.GetLines(this.DrawingPen))
                                {
                                    DrawTmpItem(this.foregroundGraphic, this.DrawingPen, newLine, true, true);
                                }
                            }
                            catch (System.ArithmeticException)
                            {
                            }
                            break;
                        default:   // Shouldn't come there
                            break;
                    }
                    break;
                case GraphDrawMode.CopyLine:
                    switch (this.DrawingStep)
                    {
                        case GraphDrawingStep.SelectItem: // Select the line to copy
                            HighlightClosestLine(e);
                            break;
                        case GraphDrawingStep.ItemSelected: // Create new // line
                            if (selectedLineIndex != -1)
                            {
                                Line2D paraLine = ((Line2DBase)this.drawingItems[selectedLineIndex]).GetParallelLine(mouseValuePoint);
                                this.DrawTmpItem(this.foregroundGraphic, this.DrawingPen, paraLine, true, true);
                            }
                            break;
                        default:   // Shouldn't come there
                            break;
                    }
                    break;
                case GraphDrawMode.CutLine:
                    if (this.DrawingStep == GraphDrawingStep.SelectItem)
                    {
                        HighlightCutLine(e, mouseValuePoint, (Control.ModifierKeys & Keys.Control) == 0);
                    }
                    break;
                case GraphDrawMode.DeleteItem:
                    if (this.DrawingStep == GraphDrawingStep.SelectItem)
                    {
                        HighlightClosestLine(e);
                    }
                    break;
                default:
                    break;
            }
        }
Ejemplo n.º 11
0
		internal override bool allowModify(PointF current)
		{
			if (!snapToNodeBorder)
				current = flowChart.AlignPointToGrid(current);

			if (modifyHandle == 0 && current.Equals(points[points.Count-1]))
				return false;
			if (modifyHandle == points.Count-1 && current.Equals(points[0]))
				return false;
			if (modifyHandle == 0 || modifyHandle == points.Count-1)
			{
				Node node = flowChart.GetNodeAt(current);
				objNewDest = node;

				if (node == null)
					return flowChart.AllowUnconnectedArrows && flowChart.confirmModify(this);

				if (node.notInteractive())
					return false;
				if (!node.canHaveArrows(modifyHandle == 0))
					return false;

				bool changingOrg = modifyHandle == 0;
				if (!flowChart.requestAttach(this, changingOrg, node))
					return false;

				// check for reflexive links
				if (!flowChart.AllowRefLinks)
				{
					if (modifyHandle == 0 && node == destLink.getNode())
						return false;
					if (modifyHandle == points.Count-1 && node == orgnLink.getNode())
						return false;
				}

				// check for repeated links
				bool linkedObjChanges =	node !=
					(changingOrg ? orgnLink.getNode() : destLink.getNode());
				if (!flowChart.AllowLinksRepeat && linkedObjChanges)
				{
					if (modifyHandle == 0 && node.alreadyLinked(destLink.getNode()))
						return false;
					if (modifyHandle == points.Count-1 &&
						orgnLink.getNode().alreadyLinked(node))
						return false;
				}

				flowChart.setAutoAnchors(node);
			}
			else 
				if (style == ArrowStyle.Cascading &&
				(modifyHandle == 1 || modifyHandle == points.Count - 2))
			{
				int h = modifyHandle;
				PointF ptp = points[h-1];
				PointF ptn = points[h+1];
				if ((cascadeStartHorizontal && h%2 > 0) || (!cascadeStartHorizontal && h%2 == 0))
				{
					ptp.Y = points[h].Y;
					ptn.X = points[h].X;
				}
				else
				{
					ptp.X = points[h].X;
					ptn.Y = points[h].Y;
				}
				if (modifyHandle == 1 && !ptp.Equals(points[0]))
					if (!orgnLink.canMoveLink(ptp))
						return false;
				if (modifyHandle == points.Count - 2 && !ptn.Equals(points[points.Count-1]))
					if (!destLink.canMoveLink(ptn))
						return false;
			}

			RectangleF rc = getBoundingRect();
			if (flowChart.rectRestrict(ref rc))
				return false;

			return flowChart.confirmModify(this);
		}
Ejemplo n.º 12
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);
     }
 }
Ejemplo n.º 13
0
        /*
         * This method gives points that crawls along an edge of the spiral, described below.
         */

        internal PointF GetNextPointInEdge(PointF current)
        {
            do
            {
                if (current.Equals(CurrentCorner))
                {
                    CurrentCorner = GetSpiralNext(CurrentCorner);
                    if (CurrentCorner.Equals(spiralEndSentinel)) return spiralEndSentinel;
                }
                current = current.X == CurrentCorner.X
                              ? new PointF(current.X, edgeDirection(current.Y))
                              : new PointF(edgeDirection(current.X), current.Y);
            } while (!mainArea.Contains(current));
            return current;
        }
Ejemplo n.º 14
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));
 }
Ejemplo n.º 15
0
 /*
      * This method gives points that crawls along an edge of the spiral, described below.
      */
 internal PointF GetNextPointInEdge(PointF Current)
 {
     do
         {
             if (Current.Equals(_CurrentCorner))
             {
                 _CurrentCorner = GetSpiralNext(_CurrentCorner);
                 if (_CurrentCorner.Equals(_SpiralEndSentinel)) return _SpiralEndSentinel;
             }
             Current = Current.X == _CurrentCorner.X
                           ? new PointF(Current.X, _EdgeDirection(Current.Y))
                           : new PointF(_EdgeDirection(Current.X), Current.Y);
         } while (!_MainArea.Contains(Current));
         return Current;
 }
Ejemplo n.º 16
0
        public GraphicsPath GetGraphicsPath()
        {
            if(gp == null)
            {
                gp = new GraphicsPath();

                PointF initPoint = new PointF(0, 0);
                PointF lastPoint = new PointF(0,0);

                SvgPathSegList segments = (SvgPathSegList)PathSegList;
                SvgPathSeg segment;

                int nElems = segments.NumberOfItems;

                for(int i = 0; i<nElems; i++)
                {
                    segment = (SvgPathSeg) segments.GetItem(i);

                    if(segment is SvgPathSegMoveto)
                    {
                        SvgPathSegMoveto seg = (SvgPathSegMoveto) segment;
                        gp.StartFigure();
                        lastPoint = initPoint = seg.AbsXY;
                    }
                    else if(segment is SvgPathSegLineto)
                    {
                        SvgPathSegLineto seg = (SvgPathSegLineto) segment;
                        PointF p = seg.AbsXY;
                        gp.AddLine(lastPoint.X, lastPoint.Y, p.X, p.Y);

                        lastPoint = p;
                    }
                    else if(segment is SvgPathSegCurveto)
                    {
                        SvgPathSegCurveto seg = (SvgPathSegCurveto)segment;
                        PointF xy = seg.AbsXY;
                        PointF x1y1 = seg.CubicX1Y1;
                        PointF x2y2 = seg.CubicX2Y2;
                        gp.AddBezier(lastPoint.X, lastPoint.Y, x1y1.X, x1y1.Y, x2y2.X, x2y2.Y, xy.X, xy.Y);

                        lastPoint = xy;
                    }
                    else if(segment is SvgPathSegArc)
                    {
                        SvgPathSegArc seg = (SvgPathSegArc)segment;
                        PointF p = seg.AbsXY;
                        if (lastPoint.Equals(p))
                        {
                            // If the endpoints (x, y) and (x0, y0) are identical, then this
                            // is equivalent to omitting the elliptical arc segment entirely.
                        }
                        else if (seg.R1 == 0 || seg.R2 == 0)
                        {
                            // Ensure radii are valid
                            gp.AddLine(lastPoint, p);
                        }
                        else
                        {
                            CalculatedArcValues calcValues = seg.GetCalculatedArcValues();

                            GraphicsPath gp2 = new GraphicsPath();
                            gp2.StartFigure();
                            gp2.AddArc(
                                calcValues.Cx - calcValues.CorrRx,
                                calcValues.Cy - calcValues.CorrRy,
                                calcValues.CorrRx*2,
                                calcValues.CorrRy*2,
                                calcValues.AngleStart,
                                calcValues.AngleExtent
                                );

                            Matrix matrix = new Matrix();
                            matrix.Translate(
                                -calcValues.Cx,
                                -calcValues.Cy
                                );
                            gp2.Transform(matrix);

                            matrix = new Matrix();
                            matrix.Rotate(seg.Angle);
                            gp2.Transform(matrix);

                            matrix = new Matrix();
                            matrix.Translate(calcValues.Cx, calcValues.Cy);
                            gp2.Transform(matrix);

                            gp.AddPath(gp2, true);
                        }

                        lastPoint = p;
                    }
                    else if(segment is SvgPathSegClosePath)
                    {
                        gp.CloseFigure();
                        lastPoint = initPoint;
                    }
                }

                string fillRule = GetPropertyValue("fill-rule");
                if(fillRule == "evenodd") gp.FillMode = FillMode.Alternate;
                else gp.FillMode = FillMode.Winding;
            }

            return gp;
        }
Ejemplo n.º 17
0
        /// <summary>
        ///   Calculate which movement delta would be acceptable to apply to all currently selected tracks.
        /// </summary>
        /// <param name="delta">The suggested movement delta.</param>
        /// <returns>The adjusted movement delta that is acceptable for all selected tracks.</returns>
        private PointF AcceptableMovementDelta( PointF delta )
        {
            PointF lastDelta;
              do {
            lastDelta = delta;

            foreach( TrackSurrogate selectedTrack in _trackSurrogates ) {
              // Store the length of this track
              float length = selectedTrack.SubstituteFor.End - selectedTrack.SubstituteFor.Start;

              // Calculate the proposed new start for the track depending on the given delta.
              float proposedStart = Math.Max( 0, selectedTrack.SubstituteFor.Start + ( delta.X * ( 1 / _renderingScale.X ) ) );

              // If the movement on this track would move it to the start of the timeline,
              // cap the movement for all tracks.
              // TODO: It could be interesting to enable this anyway through a modifier key.
              if( proposedStart <= 0 ) {
            delta.X = -selectedTrack.SubstituteFor.Start * _renderingScale.X;
            proposedStart = Math.Max( 0, selectedTrack.SubstituteFor.Start + ( delta.X * ( 1 / _renderingScale.X ) ) );
              }

              // Get the index of the selected track to use it as a basis for calculating the proposed new bounding box.
              int trackIndex = TrackIndexForTrack( selectedTrack );
              // Use the calculated values to get a full screen-space bounding box for the proposed track location.
              RectangleF proposed = BoundsHelper.RectangleToTrackExtents(
            new RectangleF {
              X = proposedStart,
              Width = length,
            }, this, trackIndex );

              TrackSurrogate track = selectedTrack;
              IOrderedEnumerable<ITimelineTrack> sortedTracks =
            // All track elements on the same track as the selected one
            _tracks[ trackIndex ].TrackElements
              // Remove the selected tracks and the one we're the substitute for
                                 .Where( t => t != track.SubstituteFor && !_selectedTracks.Contains( t ) )
              // Sort all by their position on the track
                                 .OrderBy( t => t.Start );

              if( BoundsHelper.IntersectsAny( proposed, sortedTracks.Select( t => BoundsHelper.GetTrackExtents( t, this ) ) ) ) {
            // Let's grab a list of the tracks so we can iterate by index.
            List<ITimelineTrack> sortedTracksList = sortedTracks.ToList();
            // If delta points towards left, walk the sorted tracks from the left (respecting the proposed start)
            // and try to find a non-colliding window between track elements.
            if( delta.X < 0 ) {
              for( int elementIndex = 0; elementIndex < sortedTracksList.Count(); elementIndex++ ) {
                // If the right edge of the element is left of our proposed start, then it's too far left to be interesting.
                if( sortedTracksList[ elementIndex ].End < proposedStart ) {
                  continue;
                }

                // The right edge of the element is right of our proposed start. So this is at least the first one we intersect with.
                // So we'll move our proposed start at the end of that element. However, this could cause another collision at the end of our element.
                proposedStart = sortedTracksList[ elementIndex ].End;

                // Are we at the last element? Then there's no need to check further, we can always snap here.
                if( elementIndex == sortedTracksList.Count - 1 ) {
                  break;
                }

                // Does the next element in line collide with the end of our selected track?
                if( sortedTracksList[ elementIndex + 1 ].Start < proposedStart + length ) {
                  continue;
                }

                break;
              }

            } else if( delta.X > 0 ) {
              // If delta points right, walk the sorted tracks from the right and do the same thing as above.
              for( int elementIndex = sortedTracksList.Count() - 1; elementIndex >= 0; elementIndex-- ) {
                // If the left edge of the element is right of our proposed end, then it's too far right to be interesting.
                if( sortedTracksList[ elementIndex ].Start > proposedStart + length ) {
                  continue;
                }

                // The left edge of the element is left of our proposed end. So this is at least the first one we intersect with.
                // So we'll move our proposed end at the start of that element. However, this could cause another collision at the start of our element.
                proposedStart = sortedTracksList[ elementIndex ].Start - length;

                // Are we at the first element? Then there's no need to check further, we can always snap here.
                // We can always snap because we're moving right and this is the first element that is not ourself.
                // So we were placed in front of it anyway and we're now just moving closer to it.
                if( elementIndex == 0 ) {
                  break;
                }

                // Does the next element in line collide with the start of our selected track?
                if( sortedTracksList[ elementIndex - 1 ].End > proposedStart ) {
                  continue;
                }

                break;
              }
            }

            if( delta.X < 0 ) {
              delta.X = Math.Max( delta.X, ( proposedStart - selectedTrack.SubstituteFor.Start ) * _renderingScale.X );
            } else {
              delta.X = Math.Min( delta.X, ( proposedStart - selectedTrack.SubstituteFor.Start ) * _renderingScale.X );
            }
              }

              // If the delta is nearing zero, bail out.
              if( Math.Abs( delta.X ) < 0.001f ) {
            delta.X = 0;
            return delta;
              }
            }
              } while( !lastDelta.Equals( delta ) );

              return delta;
        }
Ejemplo n.º 18
0
 private float Interpolate(float value, PointF left, PointF right)
 {
     if (left.Equals(right))
         return left.Y;
     //y = y0 + (y1 - y0)(x - x0)/(x1 - x0)
     //left == point0, right == point1
     var y = left.Y + (right.Y - left.Y)*(value - left.X)/(right.X - left.X);
     return y;
 }
Ejemplo n.º 19
0
		public static bool pointInSegment(PointF pt, PointF sgm1, PointF sgm2)
		{
			RectangleF sgmBounds = RectangleF.FromLTRB(
				Math.Min(sgm1.X, sgm2.X), Math.Min(sgm1.Y, sgm2.Y),
				Math.Max(sgm1.X, sgm2.X), Math.Max(sgm1.Y, sgm2.Y));

			if (pt.X >= sgmBounds.Left && pt.X <= sgmBounds.Right &&
				pt.Y >= sgmBounds.Top && pt.Y <= sgmBounds.Bottom)
			{
				if (sgm1.X == sgm2.X) return pt.X == sgm1.X;
				if (sgm1.Y == sgm2.Y) return pt.Y == sgm1.Y;
				if (pt.Equals(sgm1)) return true;
				if (pt.Equals(sgm2)) return true;

				return (pt.X - sgm1.X)*(sgm2.Y - sgm1.Y) ==
					(pt.Y - sgm1.Y)*(sgm2.X - sgm1.X);
			}

			return false;
		}
Ejemplo n.º 20
0
        public void TestXmlSerialize()
        {
            PointF p = new PointF(0.0f, 0.0f);
             XmlDocument xDoc = Toolbox.XmlSerialize<PointF>(p, new Type[] { typeof(Point) });
             PointF p2 = Toolbox.XmlDeserialize<PointF>(xDoc, new Type[] { typeof(Point) });
             Assert.IsTrue(p.Equals(p2));

             Rectangle rect = new Rectangle(3, 4, 5, 3);
             XmlDocument xDoc2 = Toolbox.XmlSerialize<Rectangle>(rect);
             Rectangle rect2 = Toolbox.XmlDeserialize<Rectangle>(xDoc2);
             Assert.IsTrue(rect.Equals(rect2));
        }
Ejemplo n.º 21
0
 bool CGPointEqualToPoint(PointF newContentOffset, PointF oldContentOffset)
 {
     return newContentOffset.Equals(oldContentOffset);
 }