BenMcLean
BenMcLean
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
No description
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
Yeah I was able to clean up Claude's solution and it is beautiful now.
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
No description
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
Attached is Claude's wrong solution.
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
No description
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
anyway the problem of the moment is getting the purple and orange lines representing startX and endX to the correct positions on each scanline
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
I don't actually NEED all of those per se because the point of my library is to render voxels but they'd be nice to have.
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
Yeah and that is a really good article so thanks. I'm bookmarking that because I had planned to implement Bresenham's lines, triangles, circles and ellipses at some point only I haven't got around to it yet.
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
My Parallelize is like Select except it'll run multi-threaded if the runtime allows multi-threading while acting just like regular Select if it doesn't allow multi-threading.
/// <summary>
/// Parallelizes the execution of a Select query while preserving the order of the source sequence.
/// </summary>
public static List<TResult> Parallelize<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector) => [.. source
.Select((element, index) => (element, index))
.AsParallel()
.Select(sourceTuple => (result: selector(sourceTuple.element), sourceTuple.index))
.OrderBy(resultTuple => resultTuple.index)
.AsEnumerable()
.Select(resultTuple => resultTuple.result)];
/// <summary>
/// Parallelizes the execution of a Select query while preserving the order of the source sequence.
/// </summary>
public static List<TResult> Parallelize<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector) => [.. source
.Select((element, index) => (element, index))
.AsParallel()
.Select(sourceTuple => (result: selector(sourceTuple.element), sourceTuple.index))
.OrderBy(resultTuple => resultTuple.index)
.AsEnumerable()
.Select(resultTuple => resultTuple.result)];
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
you run the unit test and it writes the animation to "rotated.gif' inside the test project's bin folder ... or wherever else you decide to send it to on your computer by modifying that string. you just open the gif to see the result
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
I got my unit test lookin pretty slick.
using SixLabors.ImageSharp;

namespace UpscaleAndRotate.Test;

public class UpscaleAndRotateTest
{
[Theory]
[InlineData(160, 319, 1, 1, 64, 10, "rotated.gif")]
public void RotateTest(ushort width, ushort height, byte scaleX, byte scaleY, ushort numFrames, int frameDelay, string path)
{
byte[] texture = new byte[width * height << 2].DrawBoundingBox(width);
byte[][] frames = ImageMaker.SameSize(
frames: [.. Enumerable.Range(0, numFrames)
.Parallelize(i => (texture
.Rotate(
rotatedWidth: out ushort rotatedWidth,
rotatedHeight: out ushort _,
radians: Math.Tau * ((double)i / numFrames),
scaleX: scaleX,
scaleY: scaleY,
width: width), rotatedWidth))],
width: out ushort newWidth,
height: out _);
ImageMaker.AnimatedGif(
width: newWidth,
frameDelay: frameDelay,
frames: frames)
.SaveAsGif(path);
}
}
using SixLabors.ImageSharp;

namespace UpscaleAndRotate.Test;

public class UpscaleAndRotateTest
{
[Theory]
[InlineData(160, 319, 1, 1, 64, 10, "rotated.gif")]
public void RotateTest(ushort width, ushort height, byte scaleX, byte scaleY, ushort numFrames, int frameDelay, string path)
{
byte[] texture = new byte[width * height << 2].DrawBoundingBox(width);
byte[][] frames = ImageMaker.SameSize(
frames: [.. Enumerable.Range(0, numFrames)
.Parallelize(i => (texture
.Rotate(
rotatedWidth: out ushort rotatedWidth,
rotatedHeight: out ushort _,
radians: Math.Tau * ((double)i / numFrames),
scaleX: scaleX,
scaleY: scaleY,
width: width), rotatedWidth))],
width: out ushort newWidth,
height: out _);
ImageMaker.AnimatedGif(
width: newWidth,
frameDelay: frameDelay,
frames: frames)
.SaveAsGif(path);
}
}
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
and the challenge is to implement the only TODO
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
I created a minimum reproduction project. The visualization is created by running the only unit test. https://github.com/BenMcLean/UpscaleAndRotate
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
yeah. i think this should save a lot of CPU and RAM actually, especially on large images and even more when I need to run the same algorithm on Z-slices of a voxel model to make sprite stacks
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
but then again i have never actually drawn those out so i probably should
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
i had started to get the corners in order to try to figure out how to get the intercepts of the lines between the corners which would be the real startX and endX
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
i'm trying to get the correct startX for each scanline, which is only going to be the minimum corner on the one scanline that happens to intersect the corner. also one of the corners is always going to be on x=0 as per the method description
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
I guess I need to make that. The whole thing's open source but it's part of a huge library
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
I mean, I can write code but I suck at math
29 replies
CC#
Created by BenMcLean on 12/6/2024 in #help
Upscaling and rotating texture
Rather than just fixing the code, I'd appreciate if anyone could even just describe the correct approach to solving this.
29 replies