I'm creating a program in C# that do not allow intersecting lines. How will I modify my code? Thank you.
I've already attached the whole source code of my program for you to check the other class I've included.But here's the code for the drawing process:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form3 : Form
{
private Boolean _calculateDouglasPeuckerReduction = false;
private List<WindowsFormsApplication2.PointEnhanced> _amerenPoints = new List<WindowsFormsApplication2.PointEnhanced>();
public Form3()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
List<System.Drawing.Point> drawingPoints = new List<System.Drawing.Point>();
foreach (WindowsFormsApplication2.PointEnhanced point in _amerenPoints)
{
drawingPoints.Add(new System.Drawing.Point(Convert.ToInt32(point.X), Convert.ToInt32(point.Y)));
}
if (drawingPoints.Count > 2)
{
e.Graphics.DrawLines(new Pen(Brushes.Black, 2), drawingPoints.ToArray());
lblOriginal2.Text = drawingPoints.Count.ToString();
if (_calculateDouglasPeuckerReduction)
{
List<WindowsFormsApplication2.PointEnhanced> points = Utility2.DouglasPeuckerReduction(_amerenPoints, Convert.ToDouble(nudTolerance2.Value));
drawingPoints = new List<System.Drawing.Point>();
foreach (WindowsFormsApplication2.PointEnhanced point in points)
{
drawingPoints.Add(new System.Drawing.Point(Convert.ToInt32(point.X), Convert.ToInt32(point.Y)));
}
e.Graphics.DrawLines(new Pen(Brushes.Red, 2), drawingPoints.ToArray());
lblSimplified2.Text = drawingPoints.Count.ToString();
}
}
base.OnPaint(e);
}
private void Form3_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_amerenPoints.Add(new WindowsFormsApplication2.PointEnhanced(e.X, e.Y));
this.Invalidate();
}
}
private void Form3_MouseUp(object sender, MouseEventArgs e)
{
//DO the calculation
_calculateDouglasPeuckerReduction = true;
this.Invalidate();
}
private void Form3_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_amerenPoints.Clear();
_calculateDouglasPeuckerReduction = false;
}
}
private void nudTolerance2_ValueChanged(object sender, EventArgs e)
{
this.Invalidate();
}
private void Form3_Load(object sender, EventArgs e)
{
}
}
}