Calendar
Mo | Tu | We | Th | Fr | Sa | Su |
---|
28 | 29 | 30 | 31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
Archive
- 2002
- 2003
- 2004
- 2005
- 2006
- 2007
- 2008
- 2009
- 2010
- 2011
- 2012
- 2013
- 2014
- 2015
- 2016
- 2019
- 2020
|
Website may be up and down over next few months. I'm currently doing a complete overhaul of everything.
Going back to simple individual .htm pages, new overall site theme, sanitizing and cleaning up html of all
pages and blog posts, attempting to implement a new tooling and publishing system etc etc.
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only /// <summary>
/// Adds the specified source array to the end of the destination array.
/// </summary>
/// <typeparam name="T">Specifies the generic type of the array.</typeparam>
/// <param name="array">The destination array.</param>
/// <param name="sourceArray">The source array that will be added to the end of the destination array.</param>
/// <returns>Returns the resized and updated destination array.</returns>
public static T[] Add<T>(this T[] array, T[] sourceArray)
{
if (array == null || sourceArray == null || sourceArray.Length == 0)
{
return array;
}
Array.Resize(ref array, array.Length + sourceArray.Length);
sourceArray.CopyTo(array, array.Length - sourceArray.Length);
return array;
}
/// <summary>
/// Adds a new extry to the end of the destination array.
/// </summary>
/// <typeparam name="T">Specifies the generic type of the array.</typeparam>
/// <param name="array">The destination array.</param>
/// <param name="value">The item that will be added to the end of the destination array.</param>
/// <returns>Returns the resized and updated destination array.</returns>
public static T[] Add<T>(this T[] array, T value)
{
if (array == null)
{
return array;
}
Array.Resize(ref array, array.Length + 1);
array[array.Length - 1] = value;
return array;
}
82d87649-d126-4f44-a643-95930baeb75b|0|.0
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only /// <summary>
/// Replaces a sequence of array entries at the specified index.
/// </summary>
/// <typeparam name="T">Specifies the generic type of the array.</typeparam>
/// <param name="array">The destination array.</param>
/// <param name="index">The index in the destination array where replacement takes place.</param>
/// <param name="sourceArray">The source array that will replace the existing entries.</param>
/// <returns>Returns the resized and updated destination array.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// If 'index' is out of bounds of the destination array.
/// </exception>
public static T[] Replace<T>(this T[] array, int index, T[] sourceArray)
{
if (array == null || sourceArray == null || sourceArray.Length == 0)
{
return array;
}
if (index < 0)
{
throw new ArgumentOutOfRangeException("index");
}
if (index > array.Length - 1)
{
throw new ArgumentOutOfRangeException("index");
}
var expandSize = (index + sourceArray.Length) - array.Length;
if (expandSize > 0)
{
Array.Resize(ref array, array.Length + expandSize);
}
sourceArray.CopyTo(array, index);
return array;
}
daa6947f-675b-4fdf-87d8-3b588cd2c2b0|0|.0
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only /// <summary>
/// Inserts one array into another array at the specified index.
/// </summary>
/// <typeparam name="T">Specifies the generic type of the array.</typeparam>
/// <param name="array">The destination array.</param>
/// <param name="index">The index in the destination array where insertion takes place.</param>
/// <param name="sourceArray">The source array that will be inserted.</param>
/// <returns>Returns the resized and updated destination array.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// If 'index' is out of bounds of the destination array.
/// </exception>
public static T[] Insert<T>(this T[] array, int index, T[] sourceArray)
{
if (array == null || sourceArray == null || sourceArray.Length == 0)
{
return array;
}
if (index < 0)
{
throw new ArgumentOutOfRangeException("index");
}
if (index > array.Length + 1)
{
throw new ArgumentOutOfRangeException("index");
}
Array.Resize(ref array, array.Length + sourceArray.Length);
Array.Copy(array, index, array, index + sourceArray.Length, array.Length - sourceArray.Length - index);
sourceArray.CopyTo(array, index);
return array;
}
1666aa75-988b-4cf9-98c5-b40f245b8404|0|.0
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only /// <summary>
/// Removes a depth from the three dimensional sequence.
/// </summary>
/// <typeparam name="T">The type of the array.</typeparam>
/// <param name="array">The array whose values are to be removed.</param>
/// <param name="width">The width of the three dimensional sequence.</param>
/// <param name="height">The height of the three dimensional sequence.</param>
/// <param name="depth">The depth of to be removed from the three dimensional sequence.</param>
/// <returns>Returns the updated three dimensional sequence.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// width or height is less then 1. Or depth is less then 0 or greater then the depth of the three dimensional sequence.
/// </exception>
public static T[] Remove3DDepth<T>(this T[] array, int width, int height, int depth)
{
if (width < 1)
{
throw new ArgumentOutOfRangeException("width");
}
if (height < 1)
{
throw new ArgumentOutOfRangeException("height");
}
var length = width * height;
if (depth < 0 || depth > (array.Length / length))
{
throw new ArgumentOutOfRangeException("depth");
}
return array.RemoveRange(depth * length, length);
}
254882e5-b438-4f50-9dcc-f1cf60e94a51|0|.0
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only /// <summary>
/// Gets the depth of the three dimensional sequence.
/// </summary>
/// <typeparam name="T">The type of the array.</typeparam>
/// <param name="array">The array whose value is to be retrieves.</param>
/// <param name="width">The width of the three dimensional sequence.</param>
/// <param name="height">The height of the three dimensional sequence.</param>
/// <returns>Returns the depth of the three dimensional sequence.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// width or height is less then 1.
/// </exception>
public static int Get3DDepth<T>(this T[] array, int width, int height)
{
if (width < 1)
{
throw new ArgumentOutOfRangeException("width");
}
if (height < 1)
{
throw new ArgumentOutOfRangeException("height");
}
return array.Length / (width * height);
}
567c64d1-369f-4bcc-b834-300a19445fcd|0|.0
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only /// <summary>
/// Inserts a source array into the three dimensional sequence.
/// </summary>
/// <typeparam name="T">The type of the array.</typeparam>
/// <param name="array">The array whose value is to be retrieves.</param>
/// <param name="width">The width of the three dimensional sequence.</param>
/// <param name="height">The height of the three dimensional sequence.</param>
/// <param name="destinationArray">The destination array.</param>
/// <param name="depth">The depth of the three dimensional sequence where insertion takes place.</param>
/// <param name="sourceArray">The source array to be inserted.</param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException">
/// width or height is less then 1. Or depth is less then 0.
/// </exception>
/// <exception cref="ArgumentException">'sourceArray' must not be larger then '(width * height)'.</exception>
/// <remarks>The length of the 'sourceArray' parameter cannot be larger then '(width * height)' otherwise the data it contains would overwrite any data
/// stored at a deeper depth.</remarks>
/// <returns>Returns the updated 'destinationArray'.</returns>
public static T[] Insert3D<T>(this T[] destinationArray, int width, int height, int depth, T[] sourceArray)
{
if (width < 1)
{
throw new ArgumentOutOfRangeException("width");
}
if (height < 1)
{
throw new ArgumentOutOfRangeException("height");
}
if (depth < 0)
{
throw new ArgumentOutOfRangeException("depth");
}
if (sourceArray == null || sourceArray.Length == 0)
{
return destinationArray;
}
// ensure source array is no greater then width * height
if (sourceArray.Length > (width * height))
{
throw new ArgumentException("'sourceArray' must not be larger then '(width * height)'", "sourceArray");
}
if (sourceArray.Length < (width * height))
{
Array.Resize(ref sourceArray, width * height);
}
destinationArray = destinationArray.Insert(depth * (width * height), sourceArray);
// return the updated array
return destinationArray;
}
40f258df-f55d-4beb-9ad0-ff43046c6a96|0|.0
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only /// <summary>
/// Sets the depth of the three dimensional sequence.
/// </summary>
/// <typeparam name="T">The type of the array.</typeparam>
/// <param name="array">The array whose value is to be retrieves.</param>
/// <param name="width">The width of the three dimensional sequence.</param>
/// <param name="height">The height of the three dimensional sequence.</param>
/// <param name="value">The new depth of the three dimensional sequence.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// width or height is less then 1.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">'value' must be greater then 0.</exception>
public static T[] Set3DDepth<T>(this T[] array, int width, int height, int value)
{
if (width < 1)
{
throw new ArgumentOutOfRangeException("width");
}
if (height < 1)
{
throw new ArgumentOutOfRangeException("height");
}
if (value < 1)
{
throw new ArgumentOutOfRangeException("value");
}
// resize the array preserving contents
Array.Resize(ref array, value * (width * height));
return array;
}
85801e47-87c6-4693-8c69-14020c5dca67|0|.0
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only /// <summary>
/// Gets the value in a single dimensional array that represents a three dimensional sequence.
/// </summary>
/// <typeparam name="T">The type of the array.</typeparam>
/// <param name="array">The array whose value is to be retrieves.</param>
/// <param name="width">The width of the three dimensional sequence.</param>
/// <param name="height">The height of the three dimensional sequence.</param>
/// <param name="x">The x index (0 to width - 1).</param>
/// <param name="y">The y index (0 to height - 1).</param>
/// <param name="z">The z index (0 to depth - 1).</param>
/// <returns>Returns the value stored in the array.</returns>
/// <exception cref="ArgumentOutOfRangeException">
/// width or height is less then 1.
/// </exception>
/// <remarks>
/// <p>This method provides an alternative to working with three dimensional arrays "var value = new int[3,3,3];" by operating
/// on a single dimensional array using a math formula to determine the index into the array.</p>
/// <p>Think of a multi-layered image. Each image layer consists of a grid of cells defined by width * height.</p>
/// <p>We can use the formula "layer * (width * height)" to get the starting index of the layer in the array.
/// To get the index in the image we can use the formula "(y * width) + x".
/// Combining these two formulas we can access any grid cell of any layer in the array like so "(layer * (width * height)) + ((y * width) + x)".</p>
/// <p>This method does not perform range checking and will throw index out of range exceptions if invalid arguments are specified.</p></remarks>
public static T Get3D<T>(this T[] array, int width, int height, int x, int y, int z)
{
if (width < 1)
{
throw new ArgumentOutOfRangeException("width");
}
if (height < 1)
{
throw new ArgumentOutOfRangeException("height");
}
return array[(z * (width * height)) + ((y * width) + x)];
}
7b65b1d4-739b-4c53-ad2c-4c3da8360a7c|0|.0
Full repo available at https://bitbucket.org/createdbyx/codefarts.utilities-extension-methods-only
/// <summary>
/// Sets the value in a single dimensional array that represents a three dimensional sequence.
/// </summary>
/// <typeparam name="T">The type of the array.</typeparam>
/// <param name="array">The array whose value is to be set.</param>
/// <param name="width">The width of the three dimensional sequence.</param>
/// <param name="height">The height of the three dimensional sequence.</param>
/// <param name="x">The x index (0 to width - 1).</param>
/// <param name="y">The y index (0 to height - 1).</param>
/// <param name="z">The z index (0 to depth - 1).</param>
/// <param name="value">The value to set.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// width or height is less then 1.
/// </exception>
/// <remarks>
/// <p>This method provides an alternative to working with three dimensional arrays "var value = new int[3,3,3];" by operating
/// on a single dimensional array using a math formula to determine the index into the array.</p>
/// <p>Think of a multi-layered image. Each image layer consists of a grid of cells defined by width * height.</p>
/// <p>We can use the formula "layer * (width * height)" to get the starting index of the layer in the array.
/// To get the index in the image we can use the formula "(y * width) + x".
/// Combining these two formulas we can access any grid cell of any layer in the array like so "(layer * (width * height)) + ((y * width) + x)".</p>
/// <p>This method does not perform range checking and will throw index out of range exceptions if invalid arguments are specified.</p>
/// </remarks>
public static void Set3D<T>(this T[] array, int width, int height, int x, int y, int z, T value)
{
if (width < 1)
{
throw new ArgumentOutOfRangeException("width");
}
if (height < 1)
{
throw new ArgumentOutOfRangeException("height");
}
array[(z * (width * height)) + ((y * width) + x)] = value;
}
6e2ec132-aa6e-4b65-9c7a-0e7cdaf166bc|0|.0
Takes in an array of floats representing pixels ordered left to right top to bottom. Width & height arguments specify the image dimensions. /// <summary>
/// Smoothens out the image.
/// </summary>
/// <param name="image">The source image.</param>
/// <exception cref="ArgumentNullException"><paramref name="getPixel"/> or <paramref name="setPixel"/> is <see langword="null" />.</exception>
public static void Smoothen(this float[] image, int width, int height, Func<int, int, float> getPixel, Action<int, int, float> setPixel, float smoothinValue = 9f)
{
if (getPixel == null)
{
throw new ArgumentNullException("getPixel");
}
if (setPixel == null)
{
throw new ArgumentNullException("setPixel");
}
for (var x = 1; x < width - 1; ++x)
{
for (var y = 1; y < height - 1; ++y)
{
var total = 0f;
for (var u = -1; u <= 1; u++)
{
for (var v = -1; v <= 1; v++)
{
total += getPixel(x + u, y + v);
}
}
setPixel(x, y, total / smoothinValue);
}
}
}
f23c8083-231a-402e-8106-dfb0d004f568|0|.0
|
|