45 namespace Gecode {
namespace Gist {
201 if (
getShape()->getExtentAtDepth(depth, theExtent)) {
202 return (theExtent.
l <= x && x <= theExtent.
r);
213 while (depth > 0 && cur != NULL) {
247 template<
class S1,
class S2>
248 static int getAlpha(
const S1& shape1,
int depth1,
249 const S2& shape2,
int depth2);
251 template<
class S1,
class S2>
253 const S1& shape1,
int depth1,
254 const S2& shape2,
int depth2,
int alpha);
257 template<
class S1,
class S2>
260 const S2& shape2,
int depth2) {
264 for (
int i=0;
i<depth1 &&
i<depth2;
i++) {
265 extentR += shape1[
i].r;
266 extentL += shape2[
i].l;
272 template<
class S1,
class S2>
275 const S1& shape1,
int depth1,
276 const S2& shape2,
int depth2,
int alpha) {
278 for (
int i=depth2;
i--;)
279 result[
i] = shape2[
i];
280 }
else if (depth2 == 0) {
281 for (
int i=depth1;
i--;)
282 result[
i] = shape1[
i];
286 int topmostL = shape1[0].
l;
287 int topmostR = shape2[0].r;
289 shape1[0].r - alpha - shape2[0].r;
291 shape2[0].l + alpha - shape1[0].l;
293 result[0] =
Extent(topmostL, topmostR+alpha);
301 for (; i<depth1 && i<depth2; i++) {
302 Extent currentExtent1 = shape1[
i];
303 Extent currentExtent2 = shape2[
i];
304 int newExtentL = currentExtent1.
l;
305 int newExtentR = currentExtent2.
r;
306 result[
i] =
Extent(newExtentL, newExtentR);
307 backoffTo1 += currentExtent1.
r - currentExtent2.
r;
308 backoffTo2 += currentExtent2.
l - currentExtent1.
l;
314 Extent currentExtent1 = shape1[
i];
315 int newExtentL = currentExtent1.
l;
316 int newExtentR = currentExtent1.
r;
317 result[
i] =
Extent(newExtentL, newExtentR+backoffTo1);
319 for (; i<depth1; i++) {
320 result[
i] = shape1[
i];
327 Extent currentExtent2 = shape2[
i];
328 int newExtentL = currentExtent2.
l;
329 int newExtentR = currentExtent2.
r;
330 result[
i] =
Extent(newExtentL+backoffTo2, newExtentR);
332 for (; i<depth2; i++) {
333 result[
i] = shape2[
i];
353 for (
int i = numberOfShapes;
i--;)
363 if (numberOfShapes == 1) {
366 for (
int i=childShape->
depth();
i--;)
367 (*mergedShape)[
i+1] = (*childShape)[
i];
368 (*mergedShape)[1].extend(- extent.
l, - extent.
r);
377 assert(root->
copy != NULL);
379 std::pair<int,int>* alpha =
380 r.
alloc<std::pair<int,int> >(numberOfShapes);
386 int ldepth =
getChild(na,0)->getShape()->depth();
387 for (
int i=ldepth;
i--;)
393 int rdepth = rShape->
depth();
394 for (
int i=rdepth;
i--;)
395 (*mergedShape)[
i+1] = (*rShape)[
i];
396 Extent* currentShapeR = &(*mergedShape)[1];
398 for (
int i = 1;
i < numberOfShapes;
i++) {
408 Layouter::getAlpha<Extent*,Shape>(¤tShapeL[0], ldepth,
409 *nextShapeL, nextShapeL->
depth());
410 Layouter::merge<Extent*,Shape>(¤tShapeL[0],
411 ¤tShapeL[0], ldepth,
412 *nextShapeL, nextShapeL->depth(),
414 ldepth =
std::max(ldepth,nextShapeL->depth());
415 alpha[
i].first = nextAlphaL - width;
422 Layouter::getAlpha<Shape,Extent*>(*nextShapeR, nextShapeR->
depth(),
423 ¤tShapeR[0], rdepth);
424 Layouter::merge<Shape,Extent*>(¤tShapeR[0],
425 *nextShapeR, nextShapeR->depth(),
426 ¤tShapeR[0], rdepth,
428 rdepth =
std::max(rdepth,nextShapeR->depth());
429 alpha[numberOfShapes -
i].second = nextAlphaR;
433 (*mergedShape)[1].extend(- extent.
l, - extent.
r);
439 int halfWidth =
false ? 0 : width / 2;
440 (*mergedShape)[1].move(- halfWidth);
450 for (
int i = 1;
i < numberOfShapes;
i++) {
451 offset += (alpha[
i].first + alpha[
i].second) / 2;
460 size_t s =
sizeof(*this);