VPTissue Reference Manual
TriangularTile.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "TriangularTile.h"
21 
22 #include <cmath>
23 
24 namespace SimPT_Editor {
25 
26 const double TriangularTile::g_side_length = 10.0;
27 const double TriangularTile::g_height = std::sqrt(3.0) / 2 * g_side_length;
28 const QPolygonF TriangularTile::g_start_polygon(QPolygonF() << QPointF(0, 0) << QPointF(g_side_length / 2, g_height) << QPointF(g_side_length, 0));
29 
30 namespace {
31 
32 QPainterPath PolygonToPath(const QPolygonF &polygon, bool odd)
33 {
34  QPainterPath path;
35  if (!odd) {
36  path.moveTo(polygon.last());
37  path.lineTo(polygon.at(0));
38  path.lineTo(polygon.at(1));
39  } else {
40  path.moveTo(polygon.first());
41  path.lineTo(polygon.at(1));
42  }
43  return path;
44 }
45 
46 }
47 
49  : Tile(g_start_polygon, PolygonToPath(g_start_polygon, false)), m_odd(false)
50 {
51  setParentItem(nullptr);
52 }
53 
54 TriangularTile::TriangularTile(const QPolygonF& polygon, bool odd, QGraphicsItem* parentItem)
55  : Tile(polygon, PolygonToPath(polygon, odd)), m_odd(odd)
56 {
57  setParentItem(parentItem);
58 }
59 
61 {
62 }
63 
65 {
66  QPolygonF polygon(m_polygon);
67  polygon.pop_back();
68  polygon.push_front(polygon.back() - QPointF(g_side_length, 0));
69  return new TriangularTile(polygon, !m_odd, parentItem());
70 }
71 
73 {
74  QPolygonF polygon(m_polygon);
75  polygon.pop_front();
76  polygon.push_back(polygon.front() + QPointF(g_side_length, 0));
77  return new TriangularTile(polygon, !m_odd, parentItem());
78 }
79 
81 {
82  QPolygonF polygon(m_polygon);
83  if (!m_odd) {
84  polygon[1] = polygon[1] - QPointF(0, 2 * g_height);
85  } else {
86  polygon[0] = polygon[0] - QPointF(0, 2 * g_height);
87  polygon[2] = polygon[2] - QPointF(0, 2 * g_height);
88  }
89  return new TriangularTile(polygon, !m_odd, parentItem());
90 }
91 
93 {
94  QPolygonF polygon(m_polygon);
95  if (!m_odd) {
96  polygon[0] = polygon[0] + QPointF(0, 2 * g_height);
97  polygon[2] = polygon[2] + QPointF(0, 2 * g_height);
98  } else {
99  polygon[1] = polygon[1] + QPointF(0, 2 * g_height);
100  }
101  return new TriangularTile(polygon, !m_odd, parentItem());
102 }
103 
104 } // namespace
virtual TriangularTile * Left() const
Creates a new tile to the left of this tile (should normally be the opposite of Tile::Right()) Parent...
virtual TriangularTile * Up() const
Creates a new tile on the row under this tile (should normally be the opposite of Tile::Down()) Paren...
Namespace for SimPT tissue editor package.
Definition: Cell.h:32
Interface for TriangularTile.
virtual ~TriangularTile()
Destructor.
virtual TriangularTile * Down() const
Creates a new tile on the row under this tile (should normally be the opposite of Tile::Up()) Parent ...
Abstract base class for cell pattern tiles.
Definition: Tile.h:29
virtual TriangularTile * Right() const
Creates a new tile to the right of this tile (should normally be the opposite of Tile::Left()) Parent...
see the online Qt documentation