Ejemplo n.º 1
0
        public SegmentList Offset(float distance)
        {
            List <Line2> new_lines = new List <Line2>();
            int          N         = lines.Count;

            // Take each line and offset by distance, and store in
            // new list
            for (int i = 0; i < N; i++)
            {
                Line2 offset_line = lines[i].Line.Offset(distance);
                new_lines.Add(offset_line);
            }
            List <LineSeg> result = new List <LineSeg>();

            for (int i = 0; i < N; i++)
            {
                // i-th line
                Line2 this_line = new_lines[i];
                // Find index of previous line. If i-th is fist line,
                // the j points to last line
                int j = i > 0?i - 1:N - 1;
                // Find index to next line. If i-th is the last line,
                // then k points to fist line
                int   k         = i < N - 1?i + 1:0;
                Line2 prev_line = new_lines[j];
                Line2 next_line = new_lines[k];
                // Trim infinate line based on intersection with
                // previous and next line.
                LineSeg offset_seg = this_line.TrimBetween(prev_line, next_line);
                result.Add(offset_seg);
            }
            // Create new polyline from array of line segments
            return(new SegmentList(result.ToArray()));
        }
Ejemplo n.º 2
0
        void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            Point pt = e.Location;

            if (HasCapturedLine)
            {
                int sel = Moving.index;

                int    dx  = pt.X - Moving.StartMouseMovePoint.X;
                int    dy  = pt.Y - Moving.StartMouseMovePoint.Y;
                Point2 del = new Point2(DrawScale.Width * dx, DrawScale.Height * dy);

                int prev_index = sel > 0?sel - 1:Count - 1;
                int next_index = sel < Count - 1?sel + 1:0;

                Point2 prev_pt = Poly.Lines[prev_index].StartPoint;
                Point2 next_pt = Poly.Lines[next_index].EndPoint;

                LineSeg tseg = new LineSeg(Moving.seg.StartPoint + del, Moving.seg.EndPoint + del);

                Poly.Lines[prev_index] = new LineSeg(prev_pt, tseg.StartPoint);
                Poly.Lines[sel]        = tseg;
                Poly.Lines[next_index] = new LineSeg(tseg.EndPoint, next_pt);

                pictureBox1.Refresh();
                this.Text = string.Format("x={0} y={1} Dragging Line={2}", pt.X, pt.Y, Selected);
            }
            else
            {
                if (Selected >= 0)
                {
                    this.Text = string.Format("x={0} y={1} Hover Line={2}", pt.X, pt.Y, Selected);
                }
                else
                {
                    this.Text = string.Format("x={0} y={1}", pt.X, pt.Y);
                }
            }
            RefreshSelection(pt);
        }
Ejemplo n.º 3
0
 public static void DrawPipe(this Graphics g, float width, LineSeg seg, Color mid_color, Color edge_color)
 {
     DrawPipe(g, width, seg.StartPoint.Center, seg.EndPoint.Center, mid_color, edge_color);
 }
Ejemplo n.º 4
0
 public static void DrawLine(this Graphics g, LineSeg seg, Pen pen)
 {
     g.DrawLine(pen, seg.StartPoint.Center, seg.EndPoint.Center);
 }