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/. */
7 #ifndef MOZILLA_GFX_TRIANGLE_H
8 #define MOZILLA_GFX_TRIANGLE_H
20 * A simple triangle data structure.
22 template <class Units
, class F
= Float
>
23 struct TriangleTyped
{
24 PointTyped
<Units
, F
> p1
, p2
, p3
;
26 TriangleTyped() : p1(), p2(), p3() {}
28 TriangleTyped(PointTyped
<Units
, F
> aP1
, PointTyped
<Units
, F
> aP2
,
29 PointTyped
<Units
, F
> aP3
)
30 : p1(aP1
), p2(aP2
), p3(aP3
) {}
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
);
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
);
39 return RectTyped
<Units
, F
>(minX
, minY
, maxX
- minX
, maxY
- minY
);
43 typedef TriangleTyped
<UnknownUnits
, Float
> Triangle
;
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
) {}
50 explicit TexturedTriangleTyped(TriangleTyped
<Units
, F
>&& aTriangle
)
51 : TriangleTyped
<Units
, F
>(std::move(aTriangle
)) {}
53 TriangleTyped
<Units
, F
> textureCoords
;
56 typedef TexturedTriangleTyped
<UnknownUnits
, Float
> TexturedTriangle
;
59 } // namespace mozilla
61 #endif /* MOZILLA_GFX_TRIANGLE_H */