#! /usr/bin/gawk -f # Last edited on 2023-09-17 19:55:22 by stolfi # Tries to guess the formula used by ImageMagick to compute the width of a rotated square image. # To be run with itself as the input. BEGIN { separate = 0 } /^[#][ ]*[0-9]/ { dgang = $2; wdim = $3; ang = dgang/180*3.141592654; rd = 75; if (separate) { # Assume ImageMagick rounds the {cos} and {sin} separately: eps = 0.95 rdofc = rd*cos(ang); carfc = 1 - (rdofc - int(rdofc)); rdofs = rd*sin(ang); carfs = 1 - (rdofs - int(rdofs)); rdoc = int(rdofc + eps) rdos = int(rdofs + eps) rdo = rdoc + rdos } else { # Assume that it rouns the sum: eps = 1.57 rdof = rd*(cos(ang) + sin(ang)) carf = 1 - (rdof - int(rdof)); rdo = int(rdof + eps) } wdo = 2*rdo + 1; if (wdim != wdo) { printf "%5.1f %3d %3d %+3d", dgang, wdim, wdo, wdim-wdo; if (separate) { printf " %12.8f %10.8f %3d %12.8f %10.8f %3d", rdofc, carfc, rdoc, rdofs, carfs, rdos; } else { printf " %12.8f %10.8f %3d", rdof, carf, rdo; } printf "\n" } } # 000.5 155 # 001.0 155 # 001.5 157 # 002.0 159 # 002.5 159 # 003.0 161 # 003.5 161 # 004.0 163 # 004.5 165 # 005.0 165 # 005.5 167 # 006.0 167 # 006.5 169 # 007.0 171 # 007.5 171 # 008.0 173 # 008.5 173 # 009.0 175 # 009.5 175 # 010.0 177 # 010.5 177 # 011.0 179 # 011.5 181 # 012.0 181 # 012.5 183 # 013.0 183 # 013.5 185 # 014.0 185 # 014.5 185 # 015.0 187 # 015.5 187 # 016.0 189 # 016.5 189 # 017.0 191 # 017.5 191 # 018.0 193 # 018.5 193 # 019.0 193 # 019.5 195 # 020.0 195 # 020.5 197 # 021.0 197 # 021.5 197 # 022.0 199 # 022.5 199 # 023.0 199 # 023.5 201 # 024.0 201 # 024.5 203 # 025.0 203 # 025.5 203 # 026.0 203 # 026.5 205 # 027.0 205 # 027.5 205 # 028.0 207 # 028.5 207 # 029.0 207 # 029.5 207 # 030.0 209 # 030.5 209 # 031.0 209 # 031.5 209 # 032.0 211 # 032.5 211 # 033.0 211 # 033.5 211 # 034.0 211 # 034.5 211 # 035.0 213 # 035.5 213 # 036.0 213 # 036.5 213 # 037.0 213 # 037.5 213 # 038.0 213 # 038.5 215 # 039.0 215 # 039.5 215 # 040.0 215 # 040.5 215 # 041.0 215 # 041.5 215 # 042.0 215 # 042.5 215 # 043.0 215 # 043.5 215 # 044.0 215 # 044.5 215 # 045.0 215 # 045.5 215 # 046.0 215 # 046.5 215 # 047.0 215 # 047.5 215 # 048.0 215 # 048.5 215 # 049.0 215 # 049.5 215 # 050.0 215