Source code for shapes
"""
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
"""
I don't have the time right now to give examples
for this very large module(or at least in comparison
to the others). Please bear with me.
"""
[docs]class square:
def __init__(self):
self._length = 0
self._perimeter = 0
self._area = 0
[docs] def setLength(self, length):
self._length = float(length)
self._perimeter = 0
self._area = 0
[docs] def getLength(self):
return self._length
[docs] def getPerimeter(self):
if self._perimeter == 0:
self._perimeter = float(self._length * 4)
return self._perimeter
[docs] def getArea(self):
if self._area == 0:
self._area = float(self._length * self._length)
return self._area
[docs]class rectangle:
def __init__(self):
self._length = 0
self._width = 0
self._perimeter = 0
self._area = 0
[docs] def setLength(self, length):
self._length = float(length)
self._perimeter = 0
self._area = 0
[docs] def getLength(self):
return self._length
[docs] def setWidth(self, width):
self._width = float(width)
self._perimeter = 0
self._area = 0
[docs] def getWidth(self):
return self._width
[docs] def getPerimeter(self):
if self._perimeter == 0:
perim1 = float(self._length * 2)
perim2 = float(self._width * 2)
self._perimeter = float(perim1 + perim2)
return self._perimeter
[docs] def getArea(self):
if self._area == 0:
self._area = float(self._length * self._width)
return self._area
[docs]class circle:
def __init__(self):
try:
import math
self._pi = math.pi
except:
self._pi = 3.14159265
self._radius = 0
self._diameter = 0
self._circumference = 0
self._area = 0
[docs] def setRadius(self, radius):
self._radius = float(radius)
self._diameter = float(self._radius * 2)
self._circumference = 0
self._area = 0
[docs] def setDiameter(self, diameter):
self._diameter = float(diameter)
self._radius = float(self._diameter / 2)
self._circumference = 0
self._area = 0
[docs] def getRadius(self):
return self._radius
[docs] def getDiameter(self):
return self._diameter
[docs] def getPi(self):
return self._pi
[docs] def getCircumference(self):
if self._circumference == 0:
self._circumference = float(self._diameter * self._pi)
return self._circumference
[docs] def getArea(self):
if self._area == 0:
self._area = float(self._pi * (self._radius * self._radius))
class triangle:
# The triangle is by far the most complex shape here.
def __init__(self):
self._side = [0, 0, 0]
self._angle = [0, 0, 0]
self._perimeter = 0
self._area = 0
self._base = 0
self._height = 0
def setSide(self, side, length):
self._side[side] = float(length)
def getBase(self):
return self._base
def getHeight(self):
return self._height
def setBase(self, value):
self._base = float(value)
def setHeight(self, value):
self._height = float(value)
def getSide(self, side):
return self._side[side]
def getPerimeter(self):
if self._perimeter == 0:
self._perimeter = self._side[0] + self._side[1] + self._side[2]
def getArea(self):
if self._area == 0:
self._area = float(self._height * self._base) / 2
return self._area
def setAngle(self, angle, measure):
self._angle[angle - 1] = float(measure)
def getAngle(self, angle):
if self._angle[angle - 1] == 0:
if angle == 1:
angle1 = self._angle[1]
angle2 = self._angle[2]
elif angle == 2:
angle1 = self._angle[0]
angle2 = self._angle[2]
elif angle == 3:
angle1 = self._angle[0]
angle2 = self._angle[1]
anglet = angle1 + angle2
angler = float(180) - anglet
self._angle[angle - 1] = angler
return self._angle[angle - 1]