public bool MoveVectorVertex(int vectorX, int vectorY, Vertex v) { Poly poly = Polygons.l.Find(x => x.verticles.Contains(v)); Edge e1 = poly.edges.Find(x => x.to == v); Edge e2 = poly.edges.Find(x => x.from == v); var l = new List <Edge>(); v.x += vectorX; v.y += vectorY; bool temp; if (e1.related != e2) { temp = e2.MakeRelation(l) && e1.MakeRelation(l); } else { temp = e1.MakeRelation(l); } if (!temp) { v.x -= vectorX; v.y -= vectorY; return(false); } return(true); }
static public Bitmap DrawPoly(this Bitmap map, Poly poly) { foreach (Edge e in poly.edges) { e.AddPoints(); map.DrawObject(e.from); map.DrawObject(e); } return(map); }
private void DeleteVericleToolStripMenuItem_Click(object sender, EventArgs e) { Vertex v = Focuss.Object as Vertex; Poly poly = Polygons.FindFocus(); Edge e1 = poly.edges.Find(x => x.to == v); Edge e2 = poly.edges.Find(x => x.from == v); e1.DeleteRelation(); e2.DeleteRelation(); e1.to = e2.to; poly.edges.Remove(e2); poly.verticles.Remove(v); e1.AddPoints(); mainPictureBox.DrawAll(); Focuss.Object = null; }
public GK1() { InitializeComponent(); int w = mainPictureBox.Width; int h = mainPictureBox.Height; trackBarV.Value = 4; trackBarE.Value = 2; int b = 4; Poly poly = new Poly(2, new Vertex(w / 4, h / 4, b), new Vertex(w * 3 / 4, h / 4, b), new Vertex(w * 3 / 4, h * 3 / 4, b), new Vertex(w / 4, h * 3 / 4, b)); Polygons.l = new List <Poly> { poly }; poly.edges[0].CreateRelation(poly.edges[1], Relation.Perpendicular, mainPictureBox); mainPictureBox.DrawAll(); }
private void AddVerticleToolStripMenuItem_Click(object sender, EventArgs e) { Vertex v = new Vertex(RightClick.x, RightClick.y, trackBarV.Value); Edge edge = Focuss.Object as Edge; Edge e1 = new Edge(edge.from, v, trackBarE.Value); Edge e2 = new Edge(v, edge.to, trackBarE.Value); edge.DeleteRelation(); Poly p = Polygons.FindFocus(); p.verticles.Add(v); p.edges.Add(e1); p.edges.Add(e2); p.edges.Remove(edge); mainPictureBox.DrawAll(); Focuss.Object = null; }
private void MainPictureBox_Click(object sender, EventArgs e) { if (Focuss.Object == null && (e as MouseEventArgs).Button == MouseButtons.Left && !Action.moving && !Action.relating) { if (!Action.creating) { mainPictureBox.MouseMove -= MainPictureBox_MouseMove; mainPictureBox.MouseMove += MainPictureBox_MouseMoveCreating; Action.creating = true; CreatingPolygon.l = new List <Vertex> { new Vertex((e as MouseEventArgs).X, (e as MouseEventArgs).Y, trackBarV.Value) }; (mainPictureBox.Image as Bitmap).DrawVerticle(CreatingPolygon.l[0], Color.Black); CreatingPolygon.map = (mainPictureBox.Image as Bitmap).Clone() as Bitmap; } else { Vertex v = new Vertex((e as MouseEventArgs).X, (e as MouseEventArgs).Y, trackBarV.Value); if (v.Same(CreatingPolygon.l[0])) { Action.creating = false; var t = new Poly(trackBarE.Value, CreatingPolygon.l.ToArray()); Polygons.l.Add(t); mainPictureBox.DrawAll(); mainPictureBox.MouseMove -= MainPictureBox_MouseMoveCreating; mainPictureBox.MouseMove += MainPictureBox_MouseMove; return; } else { (mainPictureBox.Image as Bitmap).DrawVerticle(v, Color.Black); CreatingPolygon.map = (mainPictureBox.Image as Bitmap).Clone() as Bitmap; CreatingPolygon.l.Add(v); } } } }
public bool MoveVectorEdge(int vectorX, int vectorY, Vertex v1, Vertex v2) { Poly poly = Polygons.l.Find(x => x.verticles.Contains(v1)); Edge e2 = poly.edges.Find(x => x.from == v1); Edge e1 = poly.edges.Find(x => x.to == v1); Edge e3 = poly.edges.Find(x => x.from == v2); var l = new List <Edge>(); v1.x += vectorX; v1.y += vectorY; v2.x += vectorX; v2.y += vectorY; bool temp; if (e1.related == e3 || e2.related == e3) { temp = e1.MakeRelation(l) && e2.MakeRelation(l); } else if (e1.related == e2) { temp = e1.MakeRelation(l) && e3.MakeRelation(l); } else { temp = e1.MakeRelation(l) && e2.MakeRelation(l) && e3.MakeRelation(l); } if (!temp) { v1.x -= vectorX; v1.y -= vectorY; v2.x -= vectorX; v2.y -= vectorY; return(false); } return(true); }
static public void LoadJson(PictureBox pictureBox) { var fileContent = string.Empty; using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Filter = "txt files (.txt)|*.txt"; if (dialog.ShowDialog() == DialogResult.OK) { var fileStream = dialog.OpenFile(); using (System.IO.StreamReader reader = new System.IO.StreamReader(fileStream)) { fileContent = reader.ReadToEnd(); } } } if (fileContent == string.Empty) { return; } DisposeLabels(); l = new List <Poly>(); var s = fileContent.Split('{', '}'); s = s.Select(x => x).Where(x => x != "" && x != " " && x != ",").ToArray(); int i = 0; while (i < s.Length && !s[i].Contains("points")) { i++; } while (i < s.Length) { List <Vertex> list = new List <Vertex>(); i++; while (!s[i].Contains("relations")) { var xy = s[i].Split(':', ','); int.TryParse(xy[1], out int x); int.TryParse(xy[3], out int y); list.Add(new Vertex(x, y, 4)); i++; } i++; Poly poly = new Poly(2, list.ToArray()); l.Add(poly); while (s[i].Contains("type:")) { var er = s[i].Split(',', ':'); int.TryParse(er[1], out int e1); int.TryParse(er[3], out int e2); int.TryParse(er[5], out int type); poly.edges[e1].CreateRelation(poly.edges[e2], type == 0 ? Relation.Equal : Relation.Perpendicular, pictureBox); i++; } while (i < s.Length && !s[i].Contains("points")) { i++; } } }