using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Research.DynamicDataDisplay.Common;
using Microsoft.Research.DynamicDataDisplay.Filters;
namespace Microsoft.Research.DynamicDataDisplay
{
///
/// Contains extension methods that perform coordinate space transformations.
///
public static class CoordinateTransformExtensions
{
#region Points
///
/// Transforms point in data coordinates to screen coordinates.
///
/// Point in data coordinates
/// CoordinateTransform used to perform transformation
/// Point in screen coordinates
public static Point DataToScreen(this Point dataPoint, CoordinateTransform transform)
{
return transform.DataToScreen(dataPoint);
}
///
/// Transforms point in screen coordinates to data coordinates.
///
/// Point in screen coordinates
/// CoordinateTransform used to perform transformation
/// Point in data coordinates
public static Point ScreenToData(this Point screenPoint, CoordinateTransform transform)
{
return transform.ScreenToData(screenPoint);
}
///
/// Transforms point in screen coordinates to viewport coordinates.
///
/// Point in screen coordinates
/// CoordinateTransform used to perform transformation
/// Point in viewport coordinates
public static Point ScreenToViewport(this Point screenPoint, CoordinateTransform transform)
{
return transform.ScreenToViewport(screenPoint);
}
///
/// Transforms point in viewport coordinates to screen coordinates.
///
/// Point in viewport coordinates
/// CoordinateTransform used to perform transformation
/// Point in screen coordinates
public static Point ViewportToScreen(this Point viewportPoint, CoordinateTransform transform)
{
return transform.ViewportToScreen(viewportPoint);
}
///
/// Transforms point in viewport coordinates to data coordinates.
///
/// Point in viewport coordinates
/// CoordinateTransform used to perform transformation
/// Point in data coordinates
public static Point ViewportToData(this Point viewportPoint, CoordinateTransform transform)
{
return transform.DataTransform.ViewportToData(viewportPoint);
}
///
/// Transforms point in data coordinates to viewport coordinates.
///
/// Point in data coordinates
/// CoordinateTransform used to perform transformation
/// Point in viewport coordinates
public static Point DataToViewport(this Point dataPoint, CoordinateTransform transform)
{
return transform.DataTransform.DataToViewport(dataPoint);
}
///
/// Transforms point in data coordinates to viewport coordinates.
///
/// Point in data coordinates
/// CoordinateTransform used to perform transformation
/// Point in viewport coordinates
public static Point DataToViewport(this Point dataPoint, DataTransform transform)
{
return transform.DataToViewport(dataPoint);
}
#endregion
#region Rects
///
/// Transforms rectangle from screen coordinates to data coordinates.
///
/// Rectangle in screen coordinates
/// CoordinateTransform used to perform transformation
/// Rectangle in data coordinates
public static Rect ScreenToData(this Rect screenRect, CoordinateTransform transform)
{
Point p1 = screenRect.BottomLeft.ScreenToData(transform);
Point p2 = screenRect.TopRight.ScreenToData(transform);
return new Rect(p1, p2);
}
///
/// Transforms rectangle from data coordinates to screen coordinates.
///
/// Rectangle in data coordinates
/// CoordinateTransform used to perform transformation
/// Rectangle in screen coordinates
public static Rect DataToScreen(this DataRect dataRect, CoordinateTransform transform)
{
Point p1 = dataRect.XMaxYMax.DataToScreen(transform);
Point p2 = dataRect.XMinYMin.DataToScreen(transform);
return new Rect(p1, p2);
}
///
/// Transforms rectangle from screen coordinates to viewport coordinates.
///
/// Rectangle in screen coordinates
/// CoordinateTransform used to perform transformation
/// Rectangle in viewport coordinates
public static DataRect ScreenToViewport(this Rect screenRect, CoordinateTransform transform)
{
Point p1 = screenRect.BottomLeft.ScreenToViewport(transform);
Point p2 = screenRect.TopRight.ScreenToViewport(transform);
return new DataRect(p1, p2);
}
///
/// Transforms rectangle from viewport coordinates to screen coordinates.
///
/// Rectangle in viewport coordinates
/// CoordinateTransform used to perform transformation
/// Rectangle in screen coordinates
public static Rect ViewportToScreen(this DataRect viewportRect, CoordinateTransform transform)
{
Point p1 = viewportRect.XMaxYMax.ViewportToScreen(transform);
Point p2 = viewportRect.XMinYMin.ViewportToScreen(transform);
return new Rect(p1, p2);
}
///
/// Transforms rectangle from viewport coordinates to data coordinates.
///
/// Rectangle in viewport coordinates
/// CoordinateTransform used to perform transformation
/// Rectangle in data coordinates
public static DataRect ViewportToData(this DataRect viewportRect, CoordinateTransform transform)
{
Point p1 = viewportRect.XMaxYMax.ViewportToData(transform);
Point p2 = viewportRect.XMinYMin.ViewportToData(transform);
return new DataRect(p1, p2);
}
///
/// Transforms rectangle from data coordinates to viewport coordinates.
///
/// Rectangle in data coordinates
/// CoordinateTransform used to perform transformation
/// Rectangle in viewport coordinates
public static DataRect DataToViewport(this DataRect dataRect, CoordinateTransform transform)
{
Point p1 = dataRect.XMaxYMax.DataToViewport(transform);
Point p2 = dataRect.XMinYMin.DataToViewport(transform);
return new DataRect(p1, p2);
}
///
/// Transforms rectangle from viewport coordinates to data coordinates.
///
/// Rectangle in viewport coordinates
/// CoordinateTransform used to perform transformation
/// Rectangle in data coordinates
public static DataRect ViewportToData(this DataRect viewportRect, DataTransform transform)
{
Point p1 = transform.ViewportToData(viewportRect.XMaxYMax);
Point p2 = transform.ViewportToData(viewportRect.XMinYMin);
return new DataRect(p1, p2);
}
///
/// Transforms rectangle from data coordinates to viewport coordinates.
///
/// Rectangle in data coordinates
/// CoordinateTransform used to perform transformation
/// Rectangle in viewport coordinates
public static DataRect DataToViewport(this DataRect dataRect, DataTransform transform)
{
Point p1 = transform.DataToViewport(dataRect.XMinYMin);
Point p2 = transform.DataToViewport(dataRect.XMaxYMax);
return new DataRect(p1, p2);
}
#endregion
#region Collections
///
/// Transforms index-wrapped points from viewport to screen coordinate systems.
///
/// The viewport points.
/// The transform.
///
public static IEnumerable> ViewportToScreen(this IEnumerable> viewportPoints, CoordinateTransform transform)
{
foreach (var index in viewportPoints)
{
Point pt = index.Data.ViewportToScreen(transform);
var copy = index;
copy.Data = pt;
yield return copy;
}
}
public static IEnumerable ViewportToScreen(this IEnumerable viewportPoints, CoordinateTransform transform)
{
foreach (var point in viewportPoints)
{
yield return point.ViewportToScreen(transform);
}
}
public static IEnumerable DataToScreen(this IEnumerable dataPoints, CoordinateTransform transform)
{
foreach (var point in dataPoints)
{
yield return point.DataToScreen(transform);
}
}
public static IEnumerable> DataToScreen(this IEnumerable> viewportPoints, CoordinateTransform transform)
{
foreach (var index in viewportPoints)
{
Point pt = index.Data.DataToScreen(transform);
var copy = index;
copy.Data = pt;
yield return copy;
}
}
///
/// Transforms list of points from data coordinates to screen coordinates.
///
/// Points in data coordinates
/// CoordinateTransform used to perform transformation
/// Points in screen coordinates
public static List DataToScreenAsList(this IEnumerable dataPoints, CoordinateTransform transform)
{
ICollection iCollection = dataPoints as ICollection;
List res;
if (iCollection != null)
{
res = new List(iCollection.Count);
}
else
{
res = new List();
}
foreach (var point in dataPoints)
{
res.Add(transform.DataToScreen(point));
}
return res;
}
///
/// Transforms list of points from data coordinates to screen coordinates.
///
/// Coordinate transform used to perform transformation
/// Points in data coordinates
/// List of points in screen coordinates
[SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
public static List DataToScreenAsList(this CoordinateTransform transform, IEnumerable dataPoints)
{
return dataPoints.DataToScreenAsList(transform);
}
///
/// Transforms list of points from data coordinates to viewport coordinates.
///
/// Points in data coordinates
/// Data transform used to perform transformation
/// List of points in viewport coordinates
public static IEnumerable DataToViewport(this IEnumerable dataPoints, DataTransform transform)
{
foreach (Point pt in dataPoints)
{
yield return pt.DataToViewport(transform);
}
}
public static IEnumerable> DataToViewport(this IEnumerable> viewportPoints, CoordinateTransform transform)
{
foreach (var index in viewportPoints)
{
Point pt = index.Data.DataToViewport(transform);
var copy = index;
copy.Data = pt;
yield return copy;
}
}
public static IEnumerable DataToViewport(this IEnumerable dataPoints, CoordinateTransform transform)
{
return dataPoints.DataToViewport(transform.DataTransform);
}
public static IEnumerable ScreenToViewport(this IEnumerable screenPoints, CoordinateTransform transform)
{
foreach (Point pt in screenPoints)
{
yield return pt.ScreenToViewport(transform);
}
}
public static IEnumerable> ScreenToViewport(this IEnumerable> viewportPoints, CoordinateTransform transform)
{
foreach (var index in viewportPoints)
{
Point pt = index.Data.ScreenToViewport(transform);
var copy = index;
copy.Data = pt;
yield return copy;
}
}
public static IEnumerable ScreenToData(this IEnumerable screenPoints, CoordinateTransform transform)
{
foreach (Point pt in screenPoints)
{
yield return pt.ScreenToData(transform);
}
}
public static IEnumerable> ScreenToData(this IEnumerable> viewportPoints, CoordinateTransform transform)
{
foreach (var index in viewportPoints)
{
Point pt = index.Data.ScreenToData(transform);
var copy = index;
copy.Data = pt;
yield return copy;
}
}
#endregion
}
}