public override void IntersectWith(GShape gShape) { IntersectionResult res; //if (gShape is GLine) //{ // res = Intersection.ArcLine(this, (GLine)gShape); // if (res.IntersectionPoints.Count == 0) return; // IntersectionResults.Add(res); //} if (gShape is GRectangle) { new IntersectionResult(); foreach (var line in ((GRectangle)gShape).Lines) { res = Intersection.ArcLine(this, line); if (res.IntersectionPoints.Count == 0) { return; } IntersectionResults.Add(res); } } }
private void EditorWindow_MouseDoubleClick(object sender, MouseEventArgs e) { if (ActiveCommand != DrawCommands.Noun) { if (clickCount == 2 && ActiveCommand != DrawCommands.PolyLine) { ActiveCommand = DrawCommands.Noun; //GeometryEngine.AddShape(tempShape); tempShape = null; tempPolyLine = null; clickCount = 0; } else if (clickCount == 2 && ActiveCommand == DrawCommands.PolyLine) { if (tempShape == null) { ActiveCommand = DrawCommands.Noun; } else { GeometryEngine.AddShape(tempShape); } tempShape = null; tempPolyLine = null; clickCount = 0; } else { } return; } }
public void AddShape(GShape gShape) { Shapes.Add(gShape); //return if empty if (Shapes.Count == 0) { return; } CheckIntersection(gShape); }
public override void IntersectWith(GShape gShape) { if (gShape is GCircle) { var res = Intersection.CircleLine((GCircle)gShape, this); if (res.IntersectionPoints.Count > 0) { IntersectionResults.Add(res); } } else if (gShape is GLine) { var res = Intersection.LineLine((GLine)gShape, this); if (res.IntersectionPoints.Count > 0) { IntersectionResults.Add(res); } } else if (gShape is GRectangle) { foreach (var line in ((GRectangle)gShape).Lines) { var res = Intersection.LineLine(line, this); if (res.IntersectionPoints.Count > 0) { IntersectionResults.Add(res); } } } else if (gShape is GPolyLine) { foreach (var line in ((GPolyLine)gShape).Lines) { var res = Intersection.LineLine(line, this); if (res.IntersectionPoints.Count > 0) { IntersectionResults.Add(res); } } } else if (gShape is GCurve) { var res = Intersection.CurveLine((GCurve)gShape, this); if (res.IntersectionPoints.Count == 0) { return; } IntersectionResults.Add(res); } }
private void GetActiveSet(GShape gShape) { if (Shapes.Count <= 1) { return; } foreach (var shape in Shapes.Take(Shapes.Count - 1)) { gShape.IntersectWith(shape); } }
private void CheckIntersection(GShape gShape) { //check intersection // more optimized algo will be done here if (Shapes.Count <= 1) { return; } foreach (var shape in Shapes.Take(Shapes.Count - 1)) { gShape.IntersectWith(shape); } }
private void EditorWindow_MouseUp(object sender, MouseEventArgs e) { switch (ActiveCommand) { case DrawCommands.Line: if (clickCount >= 2) { GeometryEngine.AddShape(tempShape); clickCount = 0; tempShape = null; } break; case DrawCommands.Circle: if (clickCount >= 2) { GeometryEngine.AddShape(tempShape); clickCount = 0; tempShape = null; Debug.WriteLine("draw Circle"); } break; case DrawCommands.Rectangle: if (clickCount >= 2) { GeometryEngine.AddShape(tempShape); clickCount = 0; tempShape = null; } break; case DrawCommands.PolyLine: break; case DrawCommands.Clear: break; case DrawCommands.Noun: break; default: break; } mousepressed = false; EditorWindow.Invalidate(); }
public override void IntersectWith(GShape gShape) { IntersectionResult res; if (gShape is GLine) { res = Intersection.CurveLine(this, (GLine)gShape); if (res.IntersectionPoints.Count == 0) { return; } IntersectionResults.Add(res); } else if (gShape is GRectangle) { res = Intersection.CurveRectangle(this, (GRectangle)gShape); if (res.IntersectionPoints.Count == 0) { return; } IntersectionResults.Add(res); } else if (gShape is GCurve) { res = Intersection.CurveCurve(this, (GCurve)gShape); if (res.IntersectionPoints.Count == 0) { return; } IntersectionResults.Add(res); } }
private void EditorWindow_MouseMove(object sender, MouseEventArgs e) { StatusBar.Message($"X: {e.X} , Y: {e.Y}"); if (ActiveCommand != DrawCommands.Noun && clickCount >= 1) { //delta_Y = p2.Sub(e.Location); var offsetPoint = new PointF(offsetX, offsetY).Scale(Zoom); p2 = (new PointF(e.X, e.Y).Sub(offsetPoint)).Scale(1 / Zoom); switch (ActiveCommand) { case DrawCommands.Line: #region Line tempShape = new GLine(p1, p2); #endregion break; case DrawCommands.Circle: #region Circle tempShape = new GCircle(p1, p1.Distance(p2)); Debug.WriteLine($"x:{p1.X},Y:{p1.Y},R:{p1.Distance(p2)}"); Debug.WriteLine($"offsetX:{offsetX},OffsetY:{ offsetY}"); #endregion break; case DrawCommands.Rectangle: #region Rectangle tempShape = new GRectangle(p1, p2); #endregion break; case DrawCommands.PolyLine: #region PolyLine tempShape = tempPolyLine; if (clickCount == 1) { if (tempPolyLine == null) { tempPolyLine = new GPolyLine(); tempPolyLine.Lines.Add(new GLine(p1, p2)); } else { tempPolyLine.Lines.LastOrDefault().EndPoint = p2; } } else if (clickCount == 2) { //check end line position to exit or continue drawing. var prevLine = tempPolyLine.Lines.LastOrDefault(); tempPolyLine.Lines.Add(new GLine(prevLine.EndPoint, p2)); if (p2.Distance(tempPolyLine.Lines.FirstOrDefault().StartPoint) < Setup.Snap) { GeometryEngine.AddShape(tempShape); clickCount = 0; tempShape = null; tempPolyLine = null; // ActiveCommand = DrawCommands.Noun; } else { clickCount--; } } #endregion break; case DrawCommands.Curve: #region Curve if (clickCount == 1) { tempShape = new GLine(p1, p2); } else if (clickCount == 2) { if (tempShape is GCurve) { ((GCurve)tempShape).Center = p2; } else { var l = (GLine)tempShape; tempShape = new GCurve(l.StartPoint, p2, l.EndPoint); } } else if (clickCount == 3) { ((GCurve)tempShape).Center = p2; GeometryEngine.AddShape(tempShape); clickCount = 0; } #endregion break; case DrawCommands.Parabola: #region Parabola if (clickCount == 1) { tempShape = new GLine(p1, p2); } else if (clickCount == 2) { if (tempShape is GParabola) { ((GParabola)tempShape).Points[2] = p2; } else { var l = (GLine)tempShape; tempShape = new GParabola(l.StartPoint, l.EndPoint, p2); } } else if (clickCount == 3) { ((GParabola)tempShape).Points[2] = p2; GeometryEngine.AddShape(tempShape); clickCount = 0; } #endregion break; case DrawCommands.Clear: break; case DrawCommands.Noun: break; default: break; } EditorWindow.Invalidate(); } else if (clickCount == 0) { MouseEventArgs mouse = e as MouseEventArgs; if (mouse.Button == MouseButtons.Left) { Point mousePosNow = mouse.Location; int deltaX = mousePosNow.X - mouseDown.X; // the distance the mouse has been moved since mouse was pressed int deltaY = mousePosNow.Y - mouseDown.Y; offsetX = (int)(startx + (deltaX / Zoom)); // calculate new offset of image based on the current zoom factor offsetY = (int)(starty + (deltaY / Zoom)); EditorWindow.Invalidate(); } } }
public virtual void IntersectWith(GShape gShape) { }
public static void Intersect(GShape s1, GShape s2) { }
public override void IntersectWith(GShape gShape) { IntersectionResult result; if (gShape is GLine) { foreach (var line in Lines) { result = Intersection.LineLine((GLine)gShape, line); if (result.IntersectionPoints.Count > 0) { IntersectionResults.Add(result); } } } else if (gShape is GCircle) { foreach (var line in Lines) { result = Intersection.CircleRectangle((GCircle)gShape, this); if (result.IntersectionPoints.Count == 0) { return; } IntersectionResults.Add(result); } } else if (gShape is GRectangle) { foreach (var line in Lines) { foreach (var recLine in ((GRectangle)gShape).Lines) { result = Intersection.LineLine(line, recLine); if (result.IntersectionPoints.Count == 0) { continue; } IntersectionResults.Add(result); } } } else if (gShape is GPolyLine) { foreach (var line in Lines) { foreach (var pLine in ((GPolyLine)gShape).Lines) { result = Intersection.LineLine(line, pLine); if (result.IntersectionPoints.Count == 0) { continue; } IntersectionResults.Add(result); } } } else if (gShape is GCurve) { result = Intersection.CurveRectangle((GCurve)gShape, this); if (result.IntersectionPoints.Count == 0) { return; } IntersectionResults.Add(result); } }