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 / 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();
@cdiggins
cdiggins / vector3-generated-example.cs
Created October 16, 2022 19:28
Example of Plato code, and generated backing C# code, for a Vector3 class.
/*
* This is a sample of the auto-generated code currently produced by Plato
* along with the code it was generated from.
* Plato and the generated code is compatible with .NET Standard 2.0 and C# 8.0
*/
using System;
namespace Plato2
{
/// <summary>
@cdiggins
cdiggins / inlining.cs
Created March 11, 2022 19:31
On the Importance of Inlining
[Test]
public static void Inlining()
{
var length = 1000;
// Our Two Lambdas
Func<int, bool> Lt5 = x => x < 5;
Func<int, int, int> AddInts = (x, y) => x + y;
// Original expression
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
public static class VimApi
{
/// <summary>
/// Represents a node in a VIM scene and provides access to useful information about the object associated with that node.

array.h

A C++11 header-only library of array containers, views, and iterators that provide a standard interface to different layouts of data in memory, as well as to computed data.

This is a single header file with no other dependencies (including STL) which means it is portable, fast to compile, and easy to include in different projects.

Unlike std::array the size of ara3d::array is specified in the constructor. It is rare in practice that array sizes are known at compile time. The ara3d::array_view is similar to stl::span but permits writing of data elements. If read-only semantics are desired then the ara3d::const_array_view structure can be used.

Design Rationale

#pragma once
/*
This is a C++14 wrapper around a number of STL algorithms that operate directly on an STL random access container, valarrays,
Boost range, or even a C style array. It also works of course on the various Ara 3D array classes.
The underlying container is only required to supply an implementation of standalone
begin/end functions or begin/end member functions.
The goal is to facilitate using the STL algorithms library by reducing the amount of boilerplate
/*
Ara 3d Array Operations Library
Copyright 2018, Ara 3D
Usage permitted under terms of MIT Licenese
This is a header-only library of generic algorithms that operate on random-access indexable containers such as
std::vector, std::array, and std::valarray from the STL, and raw C arrays.
It also works on ara3d::array, ara3d::func_array, and so forth.
This enhances algorithms found in the
STL library with algorithms designed specifically for arrays (like slicing, selecting, and striding).
/*
Ara 3d Array Library
Copyright 2018, Ara 3D, Inc.
Usage licensed under terms of MIT Licenese
*/
#pragma once
namespace ara3d
{
// Iterator for accessing of items at fixed byte offsets in memory