nicky-nym / city3d

3D architectural building models made using the three.js Javascript API
The Unlicense
9 stars 4 forks source link

6'8" door: what should the code look like? #27

Open nicky-nym opened 4 years ago

nicky-nym commented 4 years ago

Unfortunately, the U.S. never completely adopted the metric system, so architectural drawings here still specify lengths in feet and inches.

Currently in our code, we use a mix of conventions for representing lengths. For example, for a door that is 6'8" tall, our code might have any of these five lines:

door1 = UNIT.feet(6.667)

door2 = 6.667

door3 = 6.667 // feet

door4 = UNIT.feet(6 + 8 / 12)

door5 = 6 + (8 / 12)

If the goal is readable code, is one of those better than the others? Should we adopt one approach as the norm throughout the code?

Alternatively, should we consider other representations instead, such as one of these:

door6 = UNIT.inches(80)

door7 = UNIT.feet(6, 8)

door8 = UNIT.feet(6) + UNIT.inches(8)

door9 = UNIT.feet(6).inches(8)

door10 = UNIT(6, 8).feet().inches()

door11 = UNIT(6, 'feet', 8, 'inches')

door12 = x.feet(6.667)

door13 = x.feet(6).inches(8)

door14 = x(6, feet) + x(8, inches)

door15 = x({ ft: 6, in: 8 })

x.setUnit(UNIT.inches)
door16 = x(80)

door17 = x(` 6' 8" `)
// etc.

Bonus question: Should we bother trying to specify units for xy() and xyz() coordinates? For instance, is one of these better than the others, or is there some other syntax that would be cleaner:

doorA = xy(3, 6.667)

doorB = xy(3, 6.667) // feet

doorC = xy(3, 6.667).feet()

doorD = xy(3, 6.667, 'feet')

doorE = xy(UNIT.feet(3), UNIT.feet(6.667))

doorF = UNIT.feet(xy(3, 6.667))

doorG = xy.feet(3, 6.667)

doorH = xy(3, 6.667, feet)

xy.setUnit(UNIT.feet)
doorI = xy(3, 6.667)

doorJ = xy(` 3' x 6' 8" `)