Skip to content

Commit 587d36a

Browse files
committedSep 15, 2021
Crlf/lf consistency
Added palette reverse. Tried to make encoding and line endings consistent.
1 parent 3066555 commit 587d36a

File tree

4 files changed

+72
-23
lines changed

4 files changed

+72
-23
lines changed
 

‎Clr.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ public static bool Contains (in Clr c, in float v)
458458
/// <returns>the evaluation</returns>
459459
public static bool EqAlphaSatArith (in Clr a, in Clr b)
460460
{
461-
return (int) (0.5f + Utils.Clamp (a.a, 0.0f, 1.0f) * 0xff) ==
462-
(int) (0.5f + Utils.Clamp (b.a, 0.0f, 1.0f) * 0xff);
461+
return (int) (0.5f + Utils.Clamp (a._a, 0.0f, 1.0f) * 0xff) ==
462+
(int) (0.5f + Utils.Clamp (b._a, 0.0f, 1.0f) * 0xff);
463463
}
464464

465465
/// <summary>
@@ -471,12 +471,12 @@ public static bool EqAlphaSatArith (in Clr a, in Clr b)
471471
/// <returns>the evaluation</returns>
472472
public static bool EqRgbSatArith (in Clr a, in Clr b)
473473
{
474-
return (int) (0.5f + Utils.Clamp (a.b, 0.0f, 1.0f) * 0xff) ==
475-
(int) (0.5f + Utils.Clamp (b.b, 0.0f, 1.0f) * 0xff) &&
476-
(int) (0.5f + Utils.Clamp (a.g, 0.0f, 1.0f) * 0xff) ==
477-
(int) (0.5f + Utils.Clamp (b.g, 0.0f, 1.0f) * 0xff) &&
478-
(int) (0.5f + Utils.Clamp (a.r, 0.0f, 1.0f) * 0xff) ==
479-
(int) (0.5f + Utils.Clamp (b.r, 0.0f, 1.0f) * 0xff);
474+
return (int) (0.5f + Utils.Clamp (a._b, 0.0f, 1.0f) * 0xff) ==
475+
(int) (0.5f + Utils.Clamp (b._b, 0.0f, 1.0f) * 0xff) &&
476+
(int) (0.5f + Utils.Clamp (a._g, 0.0f, 1.0f) * 0xff) ==
477+
(int) (0.5f + Utils.Clamp (b._g, 0.0f, 1.0f) * 0xff) &&
478+
(int) (0.5f + Utils.Clamp (a._r, 0.0f, 1.0f) * 0xff) ==
479+
(int) (0.5f + Utils.Clamp (b._r, 0.0f, 1.0f) * 0xff);
480480
}
481481

482482
/// <summary>

‎ClrGradient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ protected int BisectRight (in float step)
356356
int high = this.keys.Count;
357357
while (low < high)
358358
{
359-
// The | 0 is floor div?
359+
// The | 0 is floor div.
360360
int middle = (low + high) / 2 | 0;
361361
if (step < this.keys[middle].Step)
362362
high = middle;

‎Palette.cs

+62-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Generic;
43
using System.Text;
54

@@ -495,10 +494,13 @@ public string Name
495494
/// <param name="author">author</param>
496495
public Palette (in string name = "Palette", in string author = "Anonymous")
497496
{
498-
// TODO: Implement a Palette.Tag inner class which has a name
497+
// TODO: Consider a Palette.Tag inner class which has a name
499498
// and an int[] array which references indices in the palette.
500499
// Each palete will have a list/array of tags, which allow the
501500
// user to cluster together a palette into arbitrary groups.
501+
// Problem is that it will be a challenge to keep tag indices
502+
// up-to-date when the palette changes, entries are removed, etc.
503+
// Maybe use a list of Entries, since they are classes.
502504
this.Name = name;
503505
this.Author = author;
504506
}
@@ -694,6 +696,54 @@ public static Palette Concat (in Palette a, in Palette b, in Palette target)
694696
return target;
695697
}
696698

699+
/// <summary>
700+
/// Reverses the source palette.
701+
/// </summary>
702+
/// <param name="source">source palette</param>
703+
/// <param name="target">target palette</param>
704+
/// <returns>reversed palette</returns>
705+
public static Palette Reverse (in Palette source, in Palette target)
706+
{
707+
return Palette.Reverse (source, 0, source.entries.Length, target);
708+
}
709+
710+
/// <summary>
711+
/// Reverses a subset of the source palette.
712+
/// </summary>
713+
/// <param name="source">source palette</param>
714+
/// <param name="index">start index</param>
715+
/// <param name="length">sample length</param>
716+
/// <param name="target">target palette</param>
717+
/// <returns>reversed palette</returns>
718+
public static Palette Reverse (in Palette source, in int index, in int length, in Palette target)
719+
{
720+
Entry[ ] sourceEntries = source.entries;
721+
int sourceLen = sourceEntries.Length;
722+
723+
Entry[ ] reversedEntries = new Entry[sourceLen];
724+
System.Array.Copy (sourceEntries, 0, reversedEntries, 0, sourceLen);
725+
726+
int valIdx = Utils.Mod (index, sourceLen);
727+
int valLen = Utils.Clamp (length, 1, sourceLen);
728+
System.Array.Reverse (reversedEntries, valIdx, valLen);
729+
730+
if (Object.ReferenceEquals (source, target))
731+
{
732+
target.entries = reversedEntries;
733+
}
734+
else
735+
{
736+
target.entries = Entry.Resize (target.entries, sourceLen);
737+
for (int i = 0; i < sourceLen; ++i)
738+
{
739+
Entry reversed = reversedEntries[i];
740+
target.entries[i].Set (reversed.Color, reversed.Name);
741+
}
742+
}
743+
744+
return target;
745+
}
746+
697747
/// <summary>
698748
/// Returns a palette with three primary colors -- red, green and blue --
699749
/// and three secondary colors -- yellow, cyan and magenta -- in the
@@ -721,20 +771,19 @@ public static Palette Rgb (in Palette target)
721771
/// Returns a subset of a palette.
722772
/// </summary>
723773
/// <param name="source">source palette</param>
724-
/// <param name="startIndex">start count</param>
725-
/// <param name="count">sample count</param>
774+
/// <param name="index">start index</param>
775+
/// <param name="length">sample length</param>
726776
/// <param name="target">target palette</param>
727777
/// <returns>subset</returns>
728-
public static Palette Subset (in Palette source, in int startIndex, in int count, in Palette target)
778+
public static Palette Subset (in Palette source, in int index, in int length, in Palette target)
729779
{
730-
int valCount = Utils.Max (1, count);
731-
732780
Entry[ ] sourceEntries = source.entries;
733-
Entry[ ] subsetEntries = new Entry[valCount];
734-
int srcLen = sourceEntries.Length;
735-
for (int i = 0; i < valCount; ++i)
781+
int sourceLen = sourceEntries.Length;
782+
int valLen = Utils.Clamp (length, 1, sourceLen);
783+
Entry[ ] subsetEntries = new Entry[valLen];
784+
for (int i = 0; i < valLen; ++i)
736785
{
737-
int k = Utils.Mod (startIndex + i, srcLen);
786+
int k = Utils.Mod (index + i, sourceLen);
738787
subsetEntries[i] = sourceEntries[k];
739788
}
740789

@@ -744,8 +793,8 @@ public static Palette Subset (in Palette source, in int startIndex, in int count
744793
}
745794
else
746795
{
747-
target.entries = Entry.Resize (target.entries, valCount);
748-
for (int i = 0; i < valCount; ++i)
796+
target.entries = Entry.Resize (target.entries, valLen);
797+
for (int i = 0; i < valLen; ++i)
749798
{
750799
Entry subsetEntry = subsetEntries[i];
751800
target.entries[i].Set (subsetEntry.Color, subsetEntry.Name);

‎PolyType.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <summary>
1+
/// <summary>
22
/// The polygon type to be used when constructing new meshes.
33
/// </summary>
44
public enum PolyType : int

0 commit comments

Comments
 (0)
Please sign in to comment.