Skip to content

Commit

Permalink
Merge pull request #11 from github/martin-updates
Browse files Browse the repository at this point in the history
Model tweaks
  • Loading branch information
chrisreddington authored Dec 1, 2024
2 parents 9fdfe3f + 58d8920 commit e0b1344
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
14 changes: 3 additions & 11 deletions stl/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,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 + 2*geometry.CellSize
depth = float64(7)*geometry.CellSize + 2*geometry.CellSize
} else {
// Multi-year case: use the multi-year calculation
width, depth = geometry.CalculateMultiYearDimensions(yearCount)
}
width, depth = geometry.CalculateMultiYearDimensions(yearCount)

dims := modelDimensions{
innerWidth: width,
Expand Down Expand Up @@ -216,8 +208,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)
Expand Down
8 changes: 4 additions & 4 deletions stl/geometry/geometry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
6 changes: 3 additions & 3 deletions stl/geometry/geometry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions stl/geometry/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type imageRenderConfig struct {
const (
imagePosition = 0.025
usernameOffset = -0.01
yearPosition = 0.79
yearPosition = 0.77

defaultContextWidth = 800
defaultContextHeight = 200
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e0b1344

Please sign in to comment.