Triangle.h (1771B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MOZILLA_GFX_TRIANGLE_H 8 #define MOZILLA_GFX_TRIANGLE_H 9 10 #include <algorithm> 11 #include <utility> 12 13 #include "Point.h" 14 #include "Rect.h" 15 16 namespace mozilla { 17 namespace gfx { 18 19 /** 20 * A simple triangle data structure. 21 */ 22 template <class Units, class F = Float> 23 struct TriangleTyped { 24 PointTyped<Units, F> p1, p2, p3; 25 26 TriangleTyped() : p1(), p2(), p3() {} 27 28 TriangleTyped(PointTyped<Units, F> aP1, PointTyped<Units, F> aP2, 29 PointTyped<Units, F> aP3) 30 : p1(aP1), p2(aP2), p3(aP3) {} 31 32 RectTyped<Units, F> BoundingBox() const { 33 F minX = std::min(std::min(p1.x, p2.x), p3.x); 34 F maxX = std::max(std::max(p1.x, p2.x), p3.x); 35 36 F minY = std::min(std::min(p1.y, p2.y), p3.y); 37 F maxY = std::max(std::max(p1.y, p2.y), p3.y); 38 39 return RectTyped<Units, F>(minX, minY, maxX - minX, maxY - minY); 40 } 41 }; 42 43 typedef TriangleTyped<UnknownUnits, Float> Triangle; 44 45 template <class Units, class F = Float> 46 struct TexturedTriangleTyped : public TriangleTyped<Units, F> { 47 explicit TexturedTriangleTyped(const TriangleTyped<Units, F>& aTriangle) 48 : TriangleTyped<Units, F>(aTriangle) {} 49 50 explicit TexturedTriangleTyped(TriangleTyped<Units, F>&& aTriangle) 51 : TriangleTyped<Units, F>(std::move(aTriangle)) {} 52 53 TriangleTyped<Units, F> textureCoords; 54 }; 55 56 typedef TexturedTriangleTyped<UnknownUnits, Float> TexturedTriangle; 57 58 } // namespace gfx 59 } // namespace mozilla 60 61 #endif /* MOZILLA_GFX_TRIANGLE_H */