From patchwork Thu Sep 22 15:37:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Barker X-Patchwork-Id: 4275 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 0994A23EF6 for ; Thu, 22 Sep 2011 15:37:16 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id F23AEA18BAC for ; Thu, 22 Sep 2011 15:37:15 +0000 (UTC) Received: by mail-fx0-f52.google.com with SMTP id 23so4022065fxe.11 for ; Thu, 22 Sep 2011 08:37:15 -0700 (PDT) Received: by 10.223.33.19 with SMTP id f19mr3157458fad.122.1316705835350; Thu, 22 Sep 2011 08:37:15 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.18.198 with SMTP id y6cs173010lad; Thu, 22 Sep 2011 08:37:15 -0700 (PDT) Received: by 10.216.169.75 with SMTP id m53mr2387013wel.55.1316705833727; Thu, 22 Sep 2011 08:37:13 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id w73si7431710weq.3.2011.09.22.08.37.13 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 22 Sep 2011 08:37:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1R6lKr-0002QJ-5N for ; Thu, 22 Sep 2011 15:37:13 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 1D8C5E0043 for ; Thu, 22 Sep 2011 15:37:13 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: libmatrix X-Launchpad-Branch: ~jesse-barker/libmatrix/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 26 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~jesse-barker/libmatrix/trunk] Rev 26: Add global "operator*" to handle the case where the scalar is the left-hand Message-Id: <20110922153713.11480.57949.launchpad@ackee.canonical.com> Date: Thu, 22 Sep 2011 15:37:13 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13996"; Instance="initZopeless config overlay" X-Launchpad-Hash: 74e2cd09625d1225ab1a4711638b79aeba721e43 ------------------------------------------------------------ revno: 26 committer: Jesse Barker branch nick: trunk timestamp: Tue 2011-09-20 13:43:03 -0700 message: Add global "operator*" to handle the case where the scalar is the left-hand value when multiplying a scalar by a vector. modified: test/const_vec_test.cc vec.h --- lp:libmatrix https://code.launchpad.net/~jesse-barker/libmatrix/trunk You are subscribed to branch lp:libmatrix. To unsubscribe from this branch go to https://code.launchpad.net/~jesse-barker/libmatrix/trunk/+edit-subscription === modified file 'test/const_vec_test.cc' --- test/const_vec_test.cc 2011-09-13 18:04:53 +0000 +++ test/const_vec_test.cc 2011-09-20 20:43:03 +0000 @@ -29,6 +29,8 @@ vec2 aminusb(a - b); vec2 atimesb(a * b); vec2 adivb(a / b); + const float s(2.5); + vec2 stimesb(s * b); } void @@ -40,6 +42,8 @@ vec3 aminusb(a - b); vec3 atimesb(a * b); vec3 adivb(a / b); + const float s(2.5); + vec3 stimesb(s * b); } void @@ -51,4 +55,6 @@ vec4 aminusb(a - b); vec4 atimesb(a * b); vec4 adivb(a / b); + const float s(2.5); + vec4 stimesb(s * b); } === modified file 'vec.h' --- vec.h 2011-09-13 18:04:53 +0000 +++ vec.h 2011-09-20 20:43:03 +0000 @@ -24,10 +24,10 @@ tvec2() : x_(0), y_(0) {} - tvec2(T t) : + tvec2(const T t) : x_(t), y_(t) {} - tvec2(T x, T y) : + tvec2(const T x, const T y) : x_(x), y_(y) {} tvec2(const tvec2& v) : @@ -183,11 +183,11 @@ x_(0), y_(0), z_(0) {} - tvec3(T t) : + tvec3(const T t) : x_(t), y_(t), z_(t) {} - tvec3(T x, T y, T z) : + tvec3(const T x, const T y, const T z) : x_(x), y_(y), z_(z) {} @@ -366,12 +366,12 @@ y_(0), z_(0), w_(0) {} - tvec4(T t) : + tvec4(const T t) : x_(t), y_(t), z_(t), w_(t) {} - tvec4(T x, T y, T z, T w) : + tvec4(const T x, const T y, const T z, const T w) : x_(x), y_(y), z_(z), @@ -575,4 +575,24 @@ } // namespace LibMatrix +// Global operators to allow for things like defining a new vector in terms of +// a product of a scalar and a vector +template +const LibMatrix::tvec2 operator*(const T t, const LibMatrix::tvec2& v) +{ + return v * t; +} + +template +const LibMatrix::tvec3 operator*(const T t, const LibMatrix::tvec3& v) +{ + return v * t; +} + +template +const LibMatrix::tvec4 operator*(const T t, const LibMatrix::tvec4& v) +{ + return v * t; +} + #endif // VEC_H_