this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Guido Tack <tack@gecode.org> 5 * 6 * Copyright: 7 * Guido Tack, 2006 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34namespace Gecode { namespace Gist { 35 36 forceinline 37 Extent::Extent(void) : l(-1), r(-1) {} 38 39 forceinline 40 Extent::Extent(int l0, int r0) : l(l0), r(r0) {} 41 42 inline 43 Extent::Extent(int width) { 44 int halfWidth = width / 2; 45 l = 0 - halfWidth; 46 r = 0 + halfWidth; 47 } 48 49 inline void 50 Extent::extend(int deltaL, int deltaR) { 51 l += deltaL; r += deltaR; 52 } 53 54 inline void 55 Extent::move(int delta) { 56 l += delta; r += delta; 57 } 58 59 forceinline int 60 Shape::depth(void) const { return _depth; } 61 62 forceinline void 63 Shape::setDepth(int d) { 64 assert(d <= _depth); 65 _depth = d; 66 } 67 68 forceinline const Extent& 69 Shape::operator [](int i) const { 70 assert(i < _depth); 71 return shape[i]; 72 } 73 74 forceinline Extent& 75 Shape::operator [](int i) { 76 assert(i < _depth); 77 return shape[i]; 78 } 79 80 inline Shape* 81 Shape::allocate(int d) { 82 assert(d >= 1); 83 Shape* ret; 84 ret = 85 static_cast<Shape*>(heap.ralloc(sizeof(Shape)+(d-1)*sizeof(Extent))); 86 ret->_depth = d; 87 return ret; 88 } 89 90 forceinline void 91 Shape::deallocate(Shape* shape) { 92 if (shape != hidden && shape != leaf) 93 heap.rfree(shape); 94 } 95 96 forceinline bool 97 Shape::getExtentAtDepth(int d, Extent& extent) { 98 if (d > depth()) 99 return false; 100 extent = Extent(0,0); 101 for (int i=0; i <= d; i++) { 102 Extent currentExtent = (*this)[i]; 103 extent.l += currentExtent.l; 104 extent.r += currentExtent.r; 105 } 106 return true; 107 } 108 109 forceinline void 110 Shape::computeBoundingBox(void) { 111 int lastLeft = 0; 112 int lastRight = 0; 113 bb.left = 0; 114 bb.right = 0; 115 for (int i=0; i<depth(); i++) { 116 lastLeft = lastLeft + (*this)[i].l; 117 lastRight = lastRight + (*this)[i].r; 118 bb.left = std::min(bb.left,lastLeft); 119 bb.right = std::max(bb.right,lastRight); 120 } 121 } 122 123 forceinline const BoundingBox& 124 Shape::getBoundingBox(void) const { 125 return bb; 126 } 127 128 forceinline bool 129 VisualNode::isHidden(void) { 130 return getFlag(HIDDEN); 131 } 132 133 forceinline void 134 VisualNode::setHidden(bool h) { 135 setFlag(HIDDEN, h); 136 } 137 138 forceinline void 139 VisualNode::setStop(bool h) { 140 if (getStatus() == BRANCH && h) 141 setStatus(STOP); 142 else if (getStatus() == STOP && !h) 143 setStatus(UNSTOP); 144 } 145 146 forceinline int 147 VisualNode::getOffset(void) { return offset; } 148 149 forceinline void 150 VisualNode::setOffset(int n) { offset = n; } 151 152 forceinline bool 153 VisualNode::isDirty(void) { 154 return getFlag(DIRTY); 155 } 156 157 forceinline void 158 VisualNode::setDirty(bool d) { 159 setFlag(DIRTY, d); 160 } 161 162 forceinline bool 163 VisualNode::childrenLayoutIsDone(void) { 164 return getFlag(CHILDRENLAYOUTDONE); 165 } 166 167 forceinline void 168 VisualNode::setChildrenLayoutDone(bool d) { 169 setFlag(CHILDRENLAYOUTDONE, d); 170 } 171 172 forceinline bool 173 VisualNode::isMarked(void) { 174 return getFlag(MARKED); 175 } 176 177 forceinline void 178 VisualNode::setMarked(bool m) { 179 setFlag(MARKED, m); 180 } 181 182 forceinline bool 183 VisualNode::isBookmarked(void) { 184 return getFlag(BOOKMARKED); 185 } 186 187 forceinline void 188 VisualNode::setBookmarked(bool m) { 189 setFlag(BOOKMARKED, m); 190 } 191 192 forceinline bool 193 VisualNode::isOnPath(void) { 194 return getFlag(ONPATH); 195 } 196 197 forceinline void 198 VisualNode::setOnPath(bool b) { 199 setFlag(ONPATH, b); 200 } 201 202 forceinline Shape* 203 VisualNode::getShape(void) { 204 return isHidden() ? Shape::hidden : shape; 205 } 206 207 forceinline BoundingBox 208 VisualNode::getBoundingBox(void) { return getShape()->getBoundingBox(); } 209 210}} 211 212// STATISTICS: gist-any