Skip to content

Instantly share code, notes, and snippets.

View cdiggins's full-sized avatar
🐉
Eliminating Lines of Code

Christopher Diggins cdiggins

🐉
Eliminating Lines of Code
View GitHub Profile
@cdiggins
cdiggins / concept-examples.plato.cs
Created December 14, 2022 16:30
Example of concepts in action
class ConceptExamples
{
Number Lerp(Number a, Number b, double t)
=> a * t + b * (1.0 - t);
Number Dot(Vector v)
=> (v * v).Sum().Sqrt();
Number Sum(Array xs)
=> xs.Aggregate((x, y) => x + y);
@cdiggins
cdiggins / Algebra.plato.cs
Last active December 3, 2022 16:35
Work in progress of expressing algebraic concepts
namespace Plato;
#region Groups
// https://en.wikipedia.org/wiki/Algebraic_group
interface IGroup<T>
where T : IGroup<T>
{
T GroupOperation(T x);
}
@cdiggins
cdiggins / PMoveTowards.cs
Created November 23, 2022 17:10
Unity Interpolation demo script
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
[ExecuteAlways]
public class PMoveTowards : MonoBehaviour
{
@cdiggins
cdiggins / animation-clip.cs
Created November 18, 2022 22:20
Animation Clip
public interface IAnimationCurve
{
double this[double t] { get; }
double Duration { get; }
}
public class AnimationClip<T> : IAnimationClip<T>
{
public AnimationClip(IAnimationCurve curve, T from, T to, Func<T, T, double, T> lerp)
@cdiggins
cdiggins / animation-engine.cs
Created November 18, 2022 16:59
Tween / Animation Engine Interface Proposal
public interface IAnimator
{
IArray<IAnimation> Animations { get; }
IAnimator Start(IAnimation anim);
IAnimator End(IAnimation anim);
IAnimator IsRunning();
T Drive<T>(IAnimation animation, Func<T, T, float, T> lerp);
}
@cdiggins
cdiggins / csharp-versus-plato-types.cs
Created November 16, 2022 07:25
Overview of different ways to represent types in C# compared to Plato
// Here is the basic class
public class Vector2_ClassNaive
{
public double x, y;
}
// Once we decide immutability is a good thing
public class Vector2_ClassWithFields
{
public readonly double x, y;
@cdiggins
cdiggins / math-types.plato.cs
Created October 28, 2022 21:12
Math class definitions in Plato
using System;
using Plato;
public class VectorAttribute : Attribute { }
public class ValueAttribute : Attribute { }
public class MeasureAttribute : Attribute { }
public class NumberAttribute : Attribute { }
public class IntervalAttribute : Attribute { }
namespace Plato
@cdiggins
cdiggins / structs.cs
Created October 22, 2022 00:49
Core Types for the Plato Geometry and Math Library
using System;
namespace Plato
{
public partial struct Float2 : IVector<float>
{
public float X { get; }
public float Y { get; }
}
@cdiggins
cdiggins / units-of-measure.cs
Created October 18, 2022 15:48
Units of Measure in C# Experiment
public class Unit { }
public class Kilograms : Unit { }
public class Seconds : Unit { }
public class Meters : Unit { }
public class Radians : Unit { }
public class MultiplyUnits<TUnit1, TUnit2> : Unit where TUnit1 : Unit where TUnit2 : Unit { }
public class DivideUnits<TUnit1, TUnit2> : Unit where TUnit1 : Unit where TUnit2 : Unit { }
public class Measure<T> where T : Unit
{
@cdiggins
cdiggins / measures.plato.cs
Created October 18, 2022 02:11
Examples of Units of Measure in the Plato Standard Library
public partial struct Angle : INumber
{
public double Radians { get; }
public const double RadiansPerRevolution = Math.PI * 2;
public const double DegreesPerRevolution = 360;
public const string InternalUnit = nameof(Radians);
public static Angle FromRadians(double radians) => new Angle(radians);
public static Angle FromRevolutions(double revolutions) => revolutions * RadiansPerRevolution;
public static Angle FromDegrees(double degrees) => FromRevolutions(DegreesPerRevolution / degrees);
public double ToDegrees() => DegreesPerRevolution * ToRevolutions();