# Looking for feedback on package type design - tree log volumes

**URL:** <https://discourse.julialang.org/t/looking-for-feedback-on-package-type-design-tree-log-volumes/8078>\
**Category:** General Usage\
**Created:** [December 30, 2017, 11:23pm UTC](https://discourse.julialang.org/t/looking-for-feedback-on-package-type-design-tree-log-volumes/8078 "2017-12-30T23:23:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crghilardi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crghilardi/32/3738_2.png) [@Crghilardi](https://discourse.julialang.org/u/Crghilardi)\
**Post date:** [December 30, 2017, 11:23pm UTC](https://discourse.julialang.org/t/looking-for-feedback-on-package-type-design-tree-log-volumes/8078/1 "2017-12-30T23:23:11Z")

</div>

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.

```julia
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

```

```julia
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).

```julia
 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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 31, 2017, 7:36am UTC](https://discourse.julialang.org/t/looking-for-feedback-on-package-type-design-tree-log-volumes/8078/2 "2017-12-31T07:36:16Z")

</div>

First, [please quote your code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530).

It is unclear what your question is. Do you want an set of functions that calculates volumes for various objects? Multiple dispatch should be straightforward.

I don’t know what `huber` and `newton` are, but if they result in different volumes, then it is not particularly good design to have them in the same method, and if they don’t, I am not sure why you need them.

It is unclear why you need `LogSegment` to be a macro. A function should be able to provide the same interface.
