@@ -83,22 +83,33 @@ public function addShape(AbstractShape $shape): AbstractShape
83
83
*/
84
84
public function getOffsetX (): int
85
85
{
86
- if (empty ($ this ->offsetX )) {
87
- $ offsets = GeometryCalculator::calculateOffsets ($ this );
88
- $ this ->offsetX = $ offsets [GeometryCalculator::X];
89
- $ this ->offsetY = $ offsets [GeometryCalculator::Y];
86
+ $ offsetX = null ;
87
+
88
+ foreach ($ this ->getShapeCollection () as $ shape ) {
89
+ if ($ offsetX === null ) {
90
+ $ offsetX = $ shape ->getOffsetX ();
91
+ } else {
92
+ $ offsetX = \min ($ offsetX , $ shape ->getOffsetX ());
93
+ }
90
94
}
91
95
92
- return $ this -> offsetX ;
96
+ return $ offsetX ?? 0 ;
93
97
}
94
98
95
99
/**
96
- * Ignores setting the X Offset, preserving the default behavior.
100
+ * Change the X offset by moving all contained shapes
97
101
*
98
102
* @return $this
99
103
*/
100
- public function setOffsetX (int $ pValue = 0 )
104
+ public function setOffsetX (int $ pValue = 0 ): self
101
105
{
106
+ $ offsetX = $ this ->getOffsetX ();
107
+ $ diff = $ pValue - $ offsetX ;
108
+
109
+ foreach ($ this ->getShapeCollection () as $ shape ) {
110
+ $ shape ->setOffsetX ($ shape ->getOffsetX () + $ diff );
111
+ }
112
+
102
113
return $ this ;
103
114
}
104
115
@@ -107,22 +118,33 @@ public function setOffsetX(int $pValue = 0)
107
118
*/
108
119
public function getOffsetY (): int
109
120
{
110
- if (empty ($ this ->offsetY )) {
111
- $ offsets = GeometryCalculator::calculateOffsets ($ this );
112
- $ this ->offsetX = $ offsets [GeometryCalculator::X];
113
- $ this ->offsetY = $ offsets [GeometryCalculator::Y];
121
+ $ offsetY = null ;
122
+
123
+ foreach ($ this ->getShapeCollection () as $ shape ) {
124
+ if ($ offsetY === null ) {
125
+ $ offsetY = $ shape ->getOffsetY ();
126
+ } else {
127
+ $ offsetY = \min ($ offsetY , $ shape ->getOffsetY ());
128
+ }
114
129
}
115
130
116
- return $ this -> offsetY ;
131
+ return $ offsetY ?? 0 ;
117
132
}
118
133
119
134
/**
120
- * Ignores setting the Y Offset, preserving the default behavior.
135
+ * Change the Y offset by moving all contained shapes
121
136
*
122
137
* @return $this
123
138
*/
124
- public function setOffsetY (int $ pValue = 0 )
139
+ public function setOffsetY (int $ pValue = 0 ): self
125
140
{
141
+ $ offsetY = $ this ->getOffsetY ();
142
+ $ diff = $ pValue - $ offsetY ;
143
+
144
+ foreach ($ this ->getShapeCollection () as $ shape ) {
145
+ $ shape ->setOffsetY ($ shape ->getOffsetY () + $ diff );
146
+ }
147
+
126
148
return $ this ;
127
149
}
128
150
@@ -131,35 +153,55 @@ public function setOffsetY(int $pValue = 0)
131
153
*/
132
154
public function getExtentX (): int
133
155
{
134
- if ( null === $ this -> extentX ) {
135
- $ extents = GeometryCalculator:: calculateExtents ( $ this );
136
- $ this ->extentX = $ extents [GeometryCalculator::X] - $ this -> getOffsetX ();
137
- $ this -> extentY = $ extents [GeometryCalculator::Y] - $ this -> getOffsetY ( );
156
+ $ extentX = 0 ;
157
+
158
+ foreach ( $ this ->getShapeCollection () as $ shape ) {
159
+ $ extentX = \max ( $ extentX , $ shape -> getOffsetX () + $ shape -> getWidth () );
138
160
}
139
161
140
- return $ this -> extentX ;
162
+ return $ extentX ;
141
163
}
142
164
143
165
/**
144
166
* Get Y Extent.
145
167
*/
146
168
public function getExtentY (): int
147
169
{
148
- if ( null === $ this -> extentY ) {
149
- $ extents = GeometryCalculator:: calculateExtents ( $ this );
150
- $ this ->extentX = $ extents [GeometryCalculator::X] - $ this -> getOffsetX ();
151
- $ this -> extentY = $ extents [GeometryCalculator::Y] - $ this -> getOffsetY ( );
170
+ $ extentY = 0 ;
171
+
172
+ foreach ( $ this ->getShapeCollection () as $ shape ) {
173
+ $ extentY = \max ( $ extentY , $ shape -> getOffsetY () + $ shape -> getHeight () );
152
174
}
153
175
154
- return $ this ->extentY ;
176
+ return $ extentY ;
177
+ }
178
+
179
+ /**
180
+ * Calculate the width based on the size/position of the contained shapes
181
+ *
182
+ * @return int
183
+ */
184
+ public function getWidth (): int
185
+ {
186
+ return $ this ->getExtentX () - $ this ->getOffsetX ();
155
187
}
156
188
189
+ /**
190
+ * Calculate the height based on the size/position of the contained shapes
191
+ *
192
+ * @return int
193
+ */
194
+ public function getHeight (): int
195
+ {
196
+ return $ this ->getExtentY () - $ this ->getOffsetY ();
197
+ }
198
+
157
199
/**
158
200
* Ignores setting the width, preserving the default behavior.
159
201
*
160
- * @return self
202
+ * @return $this
161
203
*/
162
- public function setWidth (int $ pValue = 0 )
204
+ public function setWidth (int $ pValue = 0 ): self
163
205
{
164
206
return $ this ;
165
207
}
@@ -169,7 +211,7 @@ public function setWidth(int $pValue = 0)
169
211
*
170
212
* @return $this
171
213
*/
172
- public function setHeight (int $ pValue = 0 )
214
+ public function setHeight (int $ pValue = 0 ): self
173
215
{
174
216
return $ this ;
175
217
}
0 commit comments