Skip to content

Instantly share code, notes, and snippets.

@briansorahan
Last active August 29, 2015 14:27
Show Gist options
  • Save briansorahan/023ad87a968d7bb0f9a8 to your computer and use it in GitHub Desktop.
Save briansorahan/023ad87a968d7bb0f9a8 to your computer and use it in GitHub Desktop.
golang geometry package
package geometry
import "math"
type Geom interface {
Area() float64
}
type circle float64
func (self circle) Area() float64 {
v := float64(self)
return math.Pi * v * v
}
func NewCircle(r float64) Geom {
return circle(r)
}
type rectangle struct {
W, H float64
}
func (self *rectangle) Area() float64 {
return self.W * self.H
}
func NewRectangle(w, h float64) Geom {
return &rectangle{w, h}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment