Skip to content

Instantly share code, notes, and snippets.

View Kittoes0124's full-sized avatar
🏠
Working from home

David Smith Kittoes0124

🏠
Working from home
View GitHub Profile
public static class ShaderHelpers
{
private static readonly Vector3 m_normal_xxx = new Vector3(1f, 1f, 1f);
private static readonly Vector3 m_normal_xyy = new Vector3(1f, -1f, -1f);
private static readonly Vector3 m_normal_yxy = new Vector3(-1f, 1f, -1f);
private static readonly Vector3 m_normal_yyx = new Vector3(-1f, -1f, 1f);
public static float Clamp(float value, float x, float y) {
if (x > y) {
var z = x;
@page "/HexCoordinates"
<BECanvas Width="1200" Height="1200" @ref="m_canvasReference"></BECanvas>
@code {
/// <summary>
///
/// </summary>
/// <remarks>
/// https://www.iquilezles.org/www/index.htm
public static bool IsApproximatelyEqual(Func<ulong, ulong> x, Func<ulong, ulong> y, Func<ulong> randomNumberGenerator) {
var result = true;
for (var i = 0UL; (i < 9223372036854775808UL); i = NextPowerOfTwo(i)) { // monotonic testing
var cube = NextCube(i);
var square = NextSquare(i);
for (var j = 1UL; (j < 11UL); ++j) {
var cubeA = (cube + j);
var cubeS = (cube - j);
public static class FigurateNumbers {
public static ulong NthHexagonal(ulong value) => checked((2UL * NthSquare(value)) - value);
public static ulong NthOblong(ulong value) => checked(value * (value + 1UL));
public static ulong NthPentagonal(ulong value) => checked(((3UL * NthSquare(value)) - value) >> 1);
public static ulong NthPhiCubic(ulong value) => unchecked((1UL + CubeRoot(value)) >> 1);
public static ulong NthPhiSquare(ulong value) => unchecked((1UL + SquareRoot(value)) >> 1);
public static ulong NthTriangular(ulong value) => checked(((value * (value + 1UL))) >> 1);
}
public static bool IsApproximatelyEqual(Func<ulong, ulong> x, Func<ulong, ulong> y, Func<ulong> randomNumberGenerator) {
var result = true;
/*
Reference:
https://www.ietf.org/rfc/rfc4122.txt
https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
*/
export class Guid {
private static bth: string[] = (new Array<number>(256)).fill(0).map((_, i) => i.toString(16).padStart(2, "0"));
private readonly m_value: Uint32Array;
public interface ISecureRandom
{
uint Next(uint x, uint y);
}
public sealed class SecureRandom : ISecureRandom
{
private static readonly RandomNumberGenerator DefaultRandomNumberGenerator = new RNGCryptoServiceProvider();
public static SecureRandom DefaultInstance => new SecureRandom(DefaultRandomNumberGenerator);
@Kittoes0124
Kittoes0124 / Vulkan - Hello Triangle.cs
Last active January 6, 2020 04:13
Uses the ByteTerrace.Native.Vulkan library to implement the code found in this guide: https://vulkan-tutorial.com/Drawing_a_triangle.
/*
Install-Package ByteTerrace.Native.Vulkan
*/
using ByteTerrace.Native.Vulkan;
using ByteTerrace.Native.Vulkan.Enums;
using ByteTerrace.Native.Vulkan.Handles;
using ByteTerrace.Native.Vulkan.Structs;
using ByteTerrace.Native.Windows;
using System;
using System;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security;
namespace ByteTerrace.Windows.Api
{
static class BitwiseHelpers
{
public static uint ConcatBits(ushort highPart, ushort lowPart) => ((((uint)highPart) << 16) | lowPart);
public sealed class Die
{
private readonly int m_numberOfSides;
private readonly IRandomNumberGenerator m_rng;
public Die(int numberOfSides, IRandomNumberGenerator rng) {
if (0 > numberOfSides) {
throw new ArgumentOutOfRangeException(actualValue: numberOfSides, message: "value must be greater than zero", paramName: nameof(numberOfSides));
}
/// <summary>
///
/// </summary>
/// <remarks>
/// https://www.redblobgames.com/grids/hexagons
/// </remarks>
public readonly struct HexCoordinate
{
private const double SquareRootOfThree = 1.7320508075688772d;
private const double SquareRootOfThreeHalved = (SquareRootOfThree * 0.5d);