//-----------------------------------------------------------------------
//
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
//
// 26-Feb-2009
// Extensions class.
//-----------------------------------------------------------------------
namespace Blacklight.Controls
{
using System;
using System.Windows;
using System.Windows.Media;
///
/// This set of internal extension methods provide general solutions and
/// utilities in a small enough number to not warrant a dedicated extension
/// methods class.
///
internal static partial class Extensions
{
///
/// Inverts a Matrix. The Invert functionality on the Matrix type is
/// internal to the framework only. Since Matrix is a struct, an out
/// parameter must be presented.
///
/// The Matrix object.
/// The matrix to return by an output
/// parameter.
/// Returns a value indicating whether the type was
/// successfully inverted. If the determinant is 0.0, then it cannot
/// be inverted and the original instance will remain untouched.
public static bool Invert(this Matrix m, out Matrix outputMatrix)
{
double determinant = m.M11 * m.M22 - m.M12 * m.M21;
if (determinant == 0.0)
{
outputMatrix = m;
return false;
}
Matrix matCopy = m;
m.M11 = matCopy.M22 / determinant;
m.M12 = -1 * matCopy.M12 / determinant;
m.M21 = -1 * matCopy.M21 / determinant;
m.M22 = matCopy.M11 / determinant;
m.OffsetX = (matCopy.OffsetY * matCopy.M21 - matCopy.OffsetX * matCopy.M22) / determinant;
m.OffsetY = (matCopy.OffsetX * matCopy.M12 - matCopy.OffsetY * matCopy.M11) / determinant;
outputMatrix = m;
return true;
}
///
/// An implementation of the Contains member of string that takes in a
/// string comparison. The traditional .NET string Contains member uses
/// StringComparison.Ordinal.
///
/// The string.
/// The string value to search for.
/// The string comparison type.
/// Returns true when the substring is found.
public static bool Contains(this string s, string value, StringComparison comparison)
{
return s.IndexOf(value, comparison) >= 0;
}
}
}