Hello,
I have tried my best to drink the kool-aid of generic API type design, but I have been struggling while working on trying to figure out what a Julian API set up would look like for calculating the volume of logs. I decided I have spent enough nights and weekends talking to myself, so I wanted to reach out and try to get some feedback on what I have so far.
Currently, I have types defined for the base geometric shapes (cone, cylinder, paraboloid, and their frustrum versions, etc…) and a volume
function that dispatches on those e.g.
abstract type Shape end
# Equation 6.1
#V=AₗL where Aₗ is the area of the base (large end).
type Cylinder
length
large_end_diam
end
function volume(solid::Cylinder)
V = area(solid.large_end_diam)*solid.length
return V
end
Addtionally, I added some kwarg flags to some of the volume functions to account for other formulas
function volume(solid::ParaboloidFrustrum; huber=false, newton = false)
if huber == true
V = area(solid.mid_point_diam) * solid.length
elseif newton == true
V = (solid.length/6) * (area(solid.large_end_diam) + 4*area(solid.mid_point_diam) + area(solid.small_end_diam))
else
V = area(solid.large_end_diam) + area(solid.small_end_diam) * (solid.length/2)
end
return V
end
I then define a macro to create a shape type from log measurements to allow for dispatch (which I think also has the benefit of bridging it back to the concept of logs rather than abstract shapes).
macro LogSegment(a,b,c,d,shape)
return :($shape($a,$b,$c,$d))
end
a= @LogSegment(24,12,nothing,8,ParaboloidFrustrum)
My end syntax I am picturing would be something like:
merchandize(trees, t::SomeTaperEquation, m::SomeMerchSpecs)
Where t::SomeTaperEquation
is used to find the various upper,mid, lower stem diameters that get passed to the macro and volume functions.
In addition, I am trying to wrap my head around is how to create this in such a way that I can figure out how to determine which shape is appropriate for that segment. My thoughts thus far would be to use something like using some form of gradient(dib from lower to upper)
to figure out a cylinder vs say a paraboloid?
One question I have is: are there any existing julia geometry packages that calculate volumes of shapes? I did not come across anything from searching.
Second, are there any downsides to the adding kwargs to the volume functions? I don’t know if that is super hack-y or not. If so, what would be the better way to accommodate those alternate formulas?
I have many more questions, but I wanted to start at the very basics to see if I am on a reasonable track or way off base.
Thank you.