1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Windows;
|
---|
4 | using Microsoft.Research.DynamicDataDisplay.Common;
|
---|
5 |
|
---|
6 | namespace Microsoft.Research.DynamicDataDisplay
|
---|
7 | {
|
---|
8 | public static class BoundsHelper
|
---|
9 | {
|
---|
10 | /// <summary>Computes bounding rectangle for sequence of points</summary>
|
---|
11 | /// <param name="points">Points sequence</param>
|
---|
12 | /// <returns>Minimal axis-aligned bounding rectangle</returns>
|
---|
13 | public static DataRect GetViewportBounds(IEnumerable<Point> viewportPoints)
|
---|
14 | {
|
---|
15 | DataRect bounds = DataRect.Empty;
|
---|
16 |
|
---|
17 | double xMin = Double.PositiveInfinity;
|
---|
18 | double xMax = Double.NegativeInfinity;
|
---|
19 |
|
---|
20 | double yMin = Double.PositiveInfinity;
|
---|
21 | double yMax = Double.NegativeInfinity;
|
---|
22 |
|
---|
23 | foreach (Point p in viewportPoints)
|
---|
24 | {
|
---|
25 | xMin = Math.Min(xMin, p.X);
|
---|
26 | xMax = Math.Max(xMax, p.X);
|
---|
27 |
|
---|
28 | yMin = Math.Min(yMin, p.Y);
|
---|
29 | yMax = Math.Max(yMax, p.Y);
|
---|
30 | }
|
---|
31 |
|
---|
32 | // were some points in collection
|
---|
33 | if (!Double.IsInfinity(xMin))
|
---|
34 | {
|
---|
35 | bounds = DataRect.Create(xMin, yMin, xMax, yMax);
|
---|
36 | }
|
---|
37 |
|
---|
38 | return bounds;
|
---|
39 | }
|
---|
40 |
|
---|
41 | public static DataRect GetViewportBounds(IEnumerable<Point> dataPoints, DataTransform transform)
|
---|
42 | {
|
---|
43 | return GetViewportBounds(dataPoints.DataToViewport(transform));
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|