shapes

package module
v0.0.0-...-67325df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 1 Imported by: 0

README

shapes

This is an example Go package for implementing geometric shapes.

Quick Start

package main

import (
    "fmt"

    "git.mills.io/prologic/shapes"
)

var _ shapes.Shape = Triangle{}

type Triangle struct {
    Sides []float64
}

// TODO: Implement me
func (t Triangle) Area() float64 { return 0.0 }

// TODO: Implement me
func (t Triangle) Perimeter() float64 { return 0.0 }

func main() {
    t := Triangle{Sides: []float64{2, 2, 2}}
    fmt.Println(t.Area())
}

License

shapes is licensed under the terms of the MIT License.

Documentation

Overview

Package shapes implements basic geometric shapes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Circle

type Circle struct {
	Radius float64
}

Circle is a circular shape with a radius.

func (Circle) Area

func (c Circle) Area() float64

Area implements Shape and returns ths area of the circle.

func (Circle) Perimeter

func (c Circle) Perimeter() float64

Perimeter implements Shape and returns the perimeter of the circle.

type Rectangle

type Rectangle struct {
	Width  float64
	Height float64
}

Rectangle ia a shape with four sides with a width and height.

func (Rectangle) Area

func (r Rectangle) Area() float64

Area implements Shape and returns the area of the rectangle.

func (Rectangle) Perimeter

func (r Rectangle) Perimeter() float64

Perimeter implements Shape and returns the perimeter of the rectangle.

type Shape

type Shape interface {
	Area() float64
	Perimeter() float64
}

Shape represents a geometry with an area and perimeter.

Directories

Path Synopsis
cmd
shapes
Package main implements an example of Go interfaces by implementing geometric shapes.
Package main implements an example of Go interfaces by implementing geometric shapes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL