From ce95630cc67bf656947263f5fe099009ca8f1256 Mon Sep 17 00:00:00 2001 From: Meizar Date: Fri, 1 Aug 2025 06:36:02 +0700 Subject: [PATCH] cleanup --- WebApp/Coordinate.cs | 15 +-------------- WebApp/Helper.cs | 19 +++++++++++++++++++ WebApp/ImageGenerator.cs | 9 +++++++-- WebApp/Program.cs | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/WebApp/Coordinate.cs b/WebApp/Coordinate.cs index 2998d29..0b94bee 100644 --- a/WebApp/Coordinate.cs +++ b/WebApp/Coordinate.cs @@ -11,20 +11,7 @@ internal record Coordinate public Coordinate(string name) { Name = name; - int row = 0; - int col = 0; - foreach (var item in name) - { - if (item >= 'A') - { - row = row * 26 + (item - 'A' + 1); - } - else if (item >= '0') - { - col = col * 10 + (item - '0'); - } - } - + (int row, int col) = Helper.ToRowCol(name); Row = row; Col = col; } diff --git a/WebApp/Helper.cs b/WebApp/Helper.cs index 4fd0f14..23766d7 100644 --- a/WebApp/Helper.cs +++ b/WebApp/Helper.cs @@ -14,4 +14,23 @@ public static class Helper } return result; } + + public static (int Row, int Col) ToRowCol(string letters) + { + int row = 0; + int col = 0; + foreach (var item in letters) + { + if (item >= 'A') + { + row = row * 26 + (item - 'A' + 1); + } + else if (item >= '0') + { + col = col * 10 + (item - '0'); + } + } + + return (row, col); + } } \ No newline at end of file diff --git a/WebApp/ImageGenerator.cs b/WebApp/ImageGenerator.cs index 4e1cdac..a482e59 100644 --- a/WebApp/ImageGenerator.cs +++ b/WebApp/ImageGenerator.cs @@ -4,7 +4,7 @@ namespace WebApp; public class ImageGenerator { - public byte[] GenerateImage3(RequestBody requestBody) + public byte[] GenerateImage(RequestBody requestBody) { string[] inputs = requestBody.CanvasRect.Split(":"); double scale = requestBody.OutputScale; @@ -42,7 +42,12 @@ public class ImageGenerator mat = mat.Resize(new Size(width, height)); } - Rect origin = new Rect((item.Col - 1) * a1Mat.Cols, (item.Row - 1) * a1Mat.Rows, a1Mat.Cols, a1Mat.Rows); + Rect origin = new Rect( + (item.Col - 1) * a1Mat.Cols, + (item.Row - 1) * a1Mat.Rows, + a1Mat.Cols, + a1Mat.Rows); + var offset = origin.Location; var roi = origin.Intersect(globalRoI); if (roi.Width == 0 || roi.Height == 0) return; diff --git a/WebApp/Program.cs b/WebApp/Program.cs index 4664708..0590479 100644 --- a/WebApp/Program.cs +++ b/WebApp/Program.cs @@ -35,7 +35,7 @@ app.MapPost("/api/image/generate", ( RequestBody requestBody ) => { ImageGenerator imageGenerator = new ImageGenerator(); - var png = imageGenerator.GenerateImage3( requestBody ); + var png = imageGenerator.GenerateImage( requestBody ); return Results.File(png, "image/png", "result.png"); }) .WithName("ImageGenerator")