1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Drawing;
|
---|
24 |
|
---|
25 | namespace HeuristicLab.Visualization {
|
---|
26 | public class Line : LinearPrimitiveBase {
|
---|
27 | public Line(IChart chart, PointD start, PointD end)
|
---|
28 | : base(chart, start, end) {
|
---|
29 | }
|
---|
30 | public Line(IChart chart, PointD start, PointD end, Pen pen)
|
---|
31 | : base(chart, start, end, pen, null) {
|
---|
32 | }
|
---|
33 |
|
---|
34 | public override bool ContainsPoint(PointD point) {
|
---|
35 | if (base.ContainsPoint(point)) return true;
|
---|
36 |
|
---|
37 | double penWidthX = Chart.PixelToWorldRatio.Width * (Pen.Width + 3);
|
---|
38 | double penWidthY = Chart.PixelToWorldRatio.Height * (Pen.Width + 3);
|
---|
39 |
|
---|
40 | if ((point.X < (Math.Min(Start.X, End.X) - (penWidthX / 2))) ||
|
---|
41 | (point.Y < (Math.Min(Start.Y, End.Y) - (penWidthY / 2))) ||
|
---|
42 | (point.X > (Math.Max(Start.X, End.X) + (penWidthX / 2))) ||
|
---|
43 | (point.Y > (Math.Max(Start.Y, End.Y) + (penWidthY / 2)))) {
|
---|
44 | return false;
|
---|
45 | }
|
---|
46 |
|
---|
47 | // calculate distance between point P(X,Y) and line
|
---|
48 | // d(P,g) = |AP.n|/|n|
|
---|
49 | Offset start_end = End - Start;
|
---|
50 | Offset n = new Offset(start_end.DY, -1 * start_end.DX);
|
---|
51 | Offset start_point = point - Start;
|
---|
52 | double d = Math.Abs(start_point.DX * n.DX + start_point.DY * n.DY) / n.Length;
|
---|
53 |
|
---|
54 | return d <= Math.Max(penWidthX, penWidthY) / 2;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public override void Draw(Graphics graphics) {
|
---|
58 | graphics.DrawLine(Pen, Chart.TransformWorldToPixel(Start), Chart.TransformWorldToPixel(End));
|
---|
59 | base.Draw(graphics);
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|