From b511bb6d3defbab9e7e6ea9757a5844c3cdec368 Mon Sep 17 00:00:00 2001 From: David Vierra Date: Thu, 3 Jan 2013 20:58:41 -1000 Subject: [PATCH] Add method Vector.length --- box.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/box.py b/box.py index 1406766..40a2dd7 100644 --- a/box.py +++ b/box.py @@ -1,5 +1,6 @@ from collections import namedtuple import itertools +import math _Vector = namedtuple("_Vector", ("x", "y", "z")) @@ -27,6 +28,9 @@ class Vector(_Vector): __div__ = __truediv__ + def length(self): + return math.sqrt(self[0] * self[0] + self[1] * self[1] + self[2] * self[2]) + class BoundingBox (object): type = int