From 8a55297296fbd75c716587c929d6584825ef0eba Mon Sep 17 00:00:00 2001 From: Martin Woodward Date: Fri, 29 Nov 2024 13:48:20 +0000 Subject: [PATCH 1/6] Add extra padding around base --- stl/generator.go | 4 ++-- stl/geometry/geometry.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/stl/generator.go b/stl/generator.go index 7a43a4f..1ad8229 100644 --- a/stl/generator.go +++ b/stl/generator.go @@ -99,8 +99,8 @@ func calculateDimensions(yearCount int) (modelDimensions, error) { if yearCount <= 1 { // Single year case: add padding to both width and depth - width = float64(geometry.GridSize)*geometry.CellSize + 2*geometry.CellSize - depth = float64(7)*geometry.CellSize + 2*geometry.CellSize + width = float64(geometry.GridSize)*geometry.CellSize + 4*geometry.CellSize + depth = float64(7)*geometry.CellSize + 4*geometry.CellSize } else { // Multi-year case: use the multi-year calculation width, depth = geometry.CalculateMultiYearDimensions(yearCount) diff --git a/stl/geometry/geometry.go b/stl/geometry/geometry.go index 55c7868..e804771 100644 --- a/stl/geometry/geometry.go +++ b/stl/geometry/geometry.go @@ -67,13 +67,13 @@ func CreateContributionGeometry(contributions [][]types.ContributionDay, yearInd var triangles []types.Triangle // Base Y offset includes padding and positions each year accordingly - baseYOffset := CellSize + float64(yearIndex)*7*CellSize + baseYOffset := 2*CellSize + float64(yearIndex)*7*CellSize for weekIdx, week := range contributions { for dayIdx, day := range week { if day.ContributionCount > 0 { height := NormalizeContribution(day.ContributionCount, maxContrib) - x := CellSize + float64(weekIdx)*CellSize + x := 2*CellSize + float64(weekIdx)*CellSize y := baseYOffset + float64(dayIdx)*CellSize columnTriangles, err := CreateColumn(x, y, height, CellSize) @@ -91,8 +91,8 @@ func CreateContributionGeometry(contributions [][]types.ContributionDay, yearInd // CalculateMultiYearDimensions calculates dimensions for multiple years func CalculateMultiYearDimensions(yearCount int) (width, depth float64) { // Total width: grid size + padding on both sides - width = float64(GridSize)*CellSize + 2*CellSize + width = float64(GridSize)*CellSize + 4*CellSize // Total depth: (7 days * number of years) + padding on both sides - depth = float64(7*yearCount)*CellSize + 2*CellSize + depth = float64(7*yearCount)*CellSize + 4*CellSize return width, depth } From d06a136bb2f62e57877edf52032619d5e7620b64 Mon Sep 17 00:00:00 2001 From: Martin Woodward Date: Fri, 29 Nov 2024 14:04:00 +0000 Subject: [PATCH 2/6] Adjust multi-year text format to YYYY-YY --- stl/generator.go | 4 ++-- stl/geometry/text.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/generator.go b/stl/generator.go index 1ad8229..44d7ab9 100644 --- a/stl/generator.go +++ b/stl/generator.go @@ -216,8 +216,8 @@ func generateText(username string, startYear int, endYear int, dims modelDimensi // If start year and end year are the same, only show one year if startYear != endYear { - // Make the year 'YY-YY' - embossedYear = fmt.Sprintf("'%02d-'%02d", startYear%100, endYear%100) + // Make the year 'YYYY-YY' + embossedYear = fmt.Sprintf("%04d-%02d", startYear, endYear%100) } textTriangles, err := geometry.Create3DText(username, embossedYear, dims.innerWidth, geometry.BaseHeight) diff --git a/stl/geometry/text.go b/stl/geometry/text.go index 41556d6..fdd7f74 100644 --- a/stl/geometry/text.go +++ b/stl/geometry/text.go @@ -38,7 +38,7 @@ type imageRenderConfig struct { const ( imagePosition = 0.025 usernameOffset = -0.01 - yearPosition = 0.79 + yearPosition = 0.77 defaultContextWidth = 800 defaultContextHeight = 200 From 9d7ac133ff817afda31a8c5cacc5b6e64395deab Mon Sep 17 00:00:00 2001 From: Martin Woodward Date: Fri, 29 Nov 2024 14:30:06 +0000 Subject: [PATCH 3/6] Make text more crisp --- stl/geometry/text.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stl/geometry/text.go b/stl/geometry/text.go index fdd7f74..65e83d0 100644 --- a/stl/geometry/text.go +++ b/stl/geometry/text.go @@ -143,9 +143,9 @@ func renderText(config textRenderConfig) ([]types.Triangle, error) { xPos, config.startY, zPos, - config.voxelScale, + config.voxelScale/2, config.depth, - config.voxelScale, + config.voxelScale/2, ) if err != nil { return nil, errors.New(errors.STLError, "failed to create cube", err) From 2a1fe8f7f83d76a3e573bde071a58244c1a542da Mon Sep 17 00:00:00 2001 From: Martin Woodward Date: Fri, 29 Nov 2024 16:02:01 +0000 Subject: [PATCH 4/6] Fix tests to be aware of larger borders --- stl/geometry/geometry_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/geometry/geometry_test.go b/stl/geometry/geometry_test.go index 3373aa5..fe9906a 100644 --- a/stl/geometry/geometry_test.go +++ b/stl/geometry/geometry_test.go @@ -90,9 +90,9 @@ func TestCalculateMultiYearDimensions(t *testing.T) { wantW float64 wantD float64 }{ - {"single year", 1, float64(GridSize)*CellSize + 2*CellSize, 7*CellSize + 2*CellSize}, - {"multiple years", 3, float64(GridSize)*CellSize + 2*CellSize, 21*CellSize + 2*CellSize}, - {"zero years", 0, float64(GridSize)*CellSize + 2*CellSize, 2 * CellSize}, + {"single year", 1, float64(GridSize)*CellSize + 4*CellSize, 7*CellSize + 4*CellSize}, + {"multiple years", 3, float64(GridSize)*CellSize + 4*CellSize, 21*CellSize + 4*CellSize}, + {"zero years", 0, float64(GridSize)*CellSize + 4*CellSize, 4 * CellSize}, } for _, tt := range tests { From ffd55494c0ed630c689b34888171dfe1033625ce Mon Sep 17 00:00:00 2001 From: Chris Reddington <791642+chrisreddington@users.noreply.github.com> Date: Sun, 1 Dec 2024 13:35:41 +0000 Subject: [PATCH 5/6] Refactor dimension calculation to use multi-year method for single year case --- stl/generator.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stl/generator.go b/stl/generator.go index 44d7ab9..8a7466b 100644 --- a/stl/generator.go +++ b/stl/generator.go @@ -98,9 +98,7 @@ func calculateDimensions(yearCount int) (modelDimensions, error) { var width, depth float64 if yearCount <= 1 { - // Single year case: add padding to both width and depth - width = float64(geometry.GridSize)*geometry.CellSize + 4*geometry.CellSize - depth = float64(7)*geometry.CellSize + 4*geometry.CellSize + width, depth = geometry.CalculateMultiYearDimensions(1) } else { // Multi-year case: use the multi-year calculation width, depth = geometry.CalculateMultiYearDimensions(yearCount) From 58d8920ca59ebf68828ab3b1b0d7cb3096b0720d Mon Sep 17 00:00:00 2001 From: Chris Reddington <791642+chrisreddington@users.noreply.github.com> Date: Sun, 1 Dec 2024 13:37:01 +0000 Subject: [PATCH 6/6] Simplify by removing conditional, always use CalculateMultiYear --- stl/generator.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/stl/generator.go b/stl/generator.go index 8a7466b..98cde8b 100644 --- a/stl/generator.go +++ b/stl/generator.go @@ -96,13 +96,7 @@ func calculateDimensions(yearCount int) (modelDimensions, error) { } var width, depth float64 - - if yearCount <= 1 { - width, depth = geometry.CalculateMultiYearDimensions(1) - } else { - // Multi-year case: use the multi-year calculation - width, depth = geometry.CalculateMultiYearDimensions(yearCount) - } + width, depth = geometry.CalculateMultiYearDimensions(yearCount) dims := modelDimensions{ innerWidth: width,