1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows.Media;
|
---|
6 | using System.Windows;
|
---|
7 |
|
---|
8 | namespace Microsoft.Research.DynamicDataDisplay.Charts.Shapes
|
---|
9 | {
|
---|
10 | /// <summary>
|
---|
11 | /// Represents a ray in viewport space.
|
---|
12 | /// </summary>
|
---|
13 | public class ViewportRay : ViewportLine
|
---|
14 | {
|
---|
15 | private readonly LineGeometry geometry = new LineGeometry();
|
---|
16 | private double direction = -1;
|
---|
17 |
|
---|
18 | /// <summary>
|
---|
19 | /// Initializes a new instance of the <see cref="ViewportRay"/> class.
|
---|
20 | /// </summary>
|
---|
21 | public ViewportRay() { }
|
---|
22 |
|
---|
23 | /// <summary>
|
---|
24 | /// Gets or sets the direction of ViewportRay.
|
---|
25 | /// Positive value means that line will be drawn up to positive infinity,
|
---|
26 | /// and negative - up to negative infinity. Default value is negative.
|
---|
27 | /// </summary>
|
---|
28 | /// <value>The direction.</value>
|
---|
29 | public double Direction
|
---|
30 | {
|
---|
31 | get { return direction; }
|
---|
32 | set { direction = value; }
|
---|
33 | }
|
---|
34 |
|
---|
35 | protected override void UpdateUIRepresentationCore()
|
---|
36 | {
|
---|
37 | base.UpdateUIRepresentationCore();
|
---|
38 |
|
---|
39 | Viewport2D viewport = Plotter.Viewport;
|
---|
40 | double deltaX = Point1.X - Point2.X;
|
---|
41 | double deltaY = Point1.Y - Point2.Y;
|
---|
42 | double m = deltaY / deltaX;
|
---|
43 | double b = Point1.Y - Point1.X * deltaY / deltaX;
|
---|
44 |
|
---|
45 | Func<double, double> func = x => m * x + b;
|
---|
46 |
|
---|
47 | double xMin = viewport.Visible.XMin;
|
---|
48 | double xMax = viewport.Visible.XMax;
|
---|
49 | Point p1 = new Point(xMin, func(xMin)).DataToScreen(viewport.Transform);
|
---|
50 | Point p2 = new Point(xMax, func(xMax)).DataToScreen(viewport.Transform);
|
---|
51 |
|
---|
52 | if (direction > 0)
|
---|
53 | p1 = Point2.DataToScreen(viewport.Transform);
|
---|
54 | else
|
---|
55 | p2 = Point1.DataToScreen(viewport.Transform);
|
---|
56 |
|
---|
57 | geometry.StartPoint = p1;
|
---|
58 | geometry.EndPoint = p2;
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected override Geometry DefiningGeometry
|
---|
62 | {
|
---|
63 | get { return geometry; }
|
---|
64 | }
|
---|
65 | }
|
---|
66 | }
|
---|