Skip to content

Instantly share code, notes, and snippets.

View Artromskiy's full-sized avatar
🧭
Wanna be hired

Artromskiy

🧭
Wanna be hired
View GitHub Profile
@Artromskiy
Artromskiy / SpanExtensions
Last active August 31, 2024 12:53
C# Span Extensions. Distinct elements, Count of repetitions per element. Useful when count of elements is less than 300
using System;
using System.Collections.Generic;
namespace Utilities;
public static class SpanExtensions
{
public static int Distinct<T>(this Span<T> items)
{
EqualityComparer<T> comparer = EqualityComparer<T>.Default;
@Artromskiy
Artromskiy / Helpers.cs
Last active October 13, 2024 20:39
Fast local TRS matrix C# MIT
using System.Numerics;
using System.Runtime.CompilerServices;
public static class Helpers
{
private static Matrix4x4 LocalMatrix(Vector3 translation, Quaternion rotation, Vector3 scale)
{
// every element in matrix except of translation
// ends up being multiplied by 2, so we multiply whole vector by sqrt2
// to skip multiplication at the end