imstb_rectpack.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. // [DEAR IMGUI]
  2. // This is a slightly modified version of stb_rect_pack.h 0.99.
  3. // Those changes would need to be pushed into nothings/stb:
  4. // - Added STBRP__CDECL
  5. // Grep for [DEAR IMGUI] to find the changes.
  6. // stb_rect_pack.h - v0.99 - public domain - rectangle packing
  7. // Sean Barrett 2014
  8. //
  9. // Useful for e.g. packing rectangular textures into an atlas.
  10. // Does not do rotation.
  11. //
  12. // Not necessarily the awesomest packing method, but better than
  13. // the totally naive one in stb_truetype (which is primarily what
  14. // this is meant to replace).
  15. //
  16. // Has only had a few tests run, may have issues.
  17. //
  18. // More docs to come.
  19. //
  20. // No memory allocations; uses qsort() and assert() from stdlib.
  21. // Can override those by defining STBRP_SORT and STBRP_ASSERT.
  22. //
  23. // This library currently uses the Skyline Bottom-Left algorithm.
  24. //
  25. // Please note: better rectangle packers are welcome! Please
  26. // implement them to the same API, but with a different init
  27. // function.
  28. //
  29. // Credits
  30. //
  31. // Library
  32. // Sean Barrett
  33. // Minor features
  34. // Martins Mozeiko
  35. // github:IntellectualKitty
  36. //
  37. // Bugfixes / warning fixes
  38. // Jeremy Jaussaud
  39. //
  40. // Version history:
  41. //
  42. // 0.99 (2019-02-07) warning fixes
  43. // 0.11 (2017-03-03) return packing success/fail result
  44. // 0.10 (2016-10-25) remove cast-away-const to avoid warnings
  45. // 0.09 (2016-08-27) fix compiler warnings
  46. // 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
  47. // 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
  48. // 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
  49. // 0.05: added STBRP_ASSERT to allow replacing assert
  50. // 0.04: fixed minor bug in STBRP_LARGE_RECTS support
  51. // 0.01: initial release
  52. //
  53. // LICENSE
  54. //
  55. // See end of file for license information.
  56. //////////////////////////////////////////////////////////////////////////////
  57. //
  58. // INCLUDE SECTION
  59. //
  60. #ifndef STB_INCLUDE_STB_RECT_PACK_H
  61. #define STB_INCLUDE_STB_RECT_PACK_H
  62. #define STB_RECT_PACK_VERSION 1
  63. #ifdef STBRP_STATIC
  64. #define STBRP_DEF static
  65. #else
  66. #define STBRP_DEF extern
  67. #endif
  68. #ifdef __cplusplus
  69. extern "C" {
  70. #endif
  71. typedef struct stbrp_context stbrp_context;
  72. typedef struct stbrp_node stbrp_node;
  73. typedef struct stbrp_rect stbrp_rect;
  74. #ifdef STBRP_LARGE_RECTS
  75. typedef int stbrp_coord;
  76. #else
  77. typedef unsigned short stbrp_coord;
  78. #endif
  79. STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
  80. // Assign packed locations to rectangles. The rectangles are of type
  81. // 'stbrp_rect' defined below, stored in the array 'rects', and there
  82. // are 'num_rects' many of them.
  83. //
  84. // Rectangles which are successfully packed have the 'was_packed' flag
  85. // set to a non-zero value and 'x' and 'y' store the minimum location
  86. // on each axis (i.e. bottom-left in cartesian coordinates, top-left
  87. // if you imagine y increasing downwards). Rectangles which do not fit
  88. // have the 'was_packed' flag set to 0.
  89. //
  90. // You should not try to access the 'rects' array from another thread
  91. // while this function is running, as the function temporarily reorders
  92. // the array while it executes.
  93. //
  94. // To pack into another rectangle, you need to call stbrp_init_target
  95. // again. To continue packing into the same rectangle, you can call
  96. // this function again. Calling this multiple times with multiple rect
  97. // arrays will probably produce worse packing results than calling it
  98. // a single time with the full rectangle array, but the option is
  99. // available.
  100. //
  101. // The function returns 1 if all of the rectangles were successfully
  102. // packed and 0 otherwise.
  103. struct stbrp_rect
  104. {
  105. // reserved for your use:
  106. int id;
  107. // input:
  108. stbrp_coord w, h;
  109. // output:
  110. stbrp_coord x, y;
  111. int was_packed; // non-zero if valid packing
  112. }; // 16 bytes, nominally
  113. STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
  114. // Initialize a rectangle packer to:
  115. // pack a rectangle that is 'width' by 'height' in dimensions
  116. // using temporary storage provided by the array 'nodes', which is 'num_nodes' long
  117. //
  118. // You must call this function every time you start packing into a new target.
  119. //
  120. // There is no "shutdown" function. The 'nodes' memory must stay valid for
  121. // the following stbrp_pack_rects() call (or calls), but can be freed after
  122. // the call (or calls) finish.
  123. //
  124. // Note: to guarantee best results, either:
  125. // 1. make sure 'num_nodes' >= 'width'
  126. // or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
  127. //
  128. // If you don't do either of the above things, widths will be quantized to multiples
  129. // of small integers to guarantee the algorithm doesn't run out of temporary storage.
  130. //
  131. // If you do #2, then the non-quantized algorithm will be used, but the algorithm
  132. // may run out of temporary storage and be unable to pack some rectangles.
  133. STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
  134. // Optionally call this function after init but before doing any packing to
  135. // change the handling of the out-of-temp-memory scenario, described above.
  136. // If you call init again, this will be reset to the default (false).
  137. STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
  138. // Optionally select which packing heuristic the library should use. Different
  139. // heuristics will produce better/worse results for different data sets.
  140. // If you call init again, this will be reset to the default.
  141. enum
  142. {
  143. STBRP_HEURISTIC_Skyline_default=0,
  144. STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
  145. STBRP_HEURISTIC_Skyline_BF_sortHeight
  146. };
  147. //////////////////////////////////////////////////////////////////////////////
  148. //
  149. // the details of the following structures don't matter to you, but they must
  150. // be visible so you can handle the memory allocations for them
  151. struct stbrp_node
  152. {
  153. stbrp_coord x,y;
  154. stbrp_node *next;
  155. };
  156. struct stbrp_context
  157. {
  158. int width;
  159. int height;
  160. int align;
  161. int init_mode;
  162. int heuristic;
  163. int num_nodes;
  164. stbrp_node *active_head;
  165. stbrp_node *free_head;
  166. stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
  167. };
  168. #ifdef __cplusplus
  169. }
  170. #endif
  171. #endif
  172. //////////////////////////////////////////////////////////////////////////////
  173. //
  174. // IMPLEMENTATION SECTION
  175. //
  176. #ifdef STB_RECT_PACK_IMPLEMENTATION
  177. #ifndef STBRP_SORT
  178. #include <stdlib.h>
  179. #define STBRP_SORT qsort
  180. #endif
  181. #ifndef STBRP_ASSERT
  182. #include <assert.h>
  183. #define STBRP_ASSERT assert
  184. #endif
  185. // [DEAR IMGUI] Added STBRP__CDECL
  186. #ifdef _MSC_VER
  187. #define STBRP__NOTUSED(v) (void)(v)
  188. #define STBRP__CDECL __cdecl
  189. #else
  190. #define STBRP__NOTUSED(v) (void)sizeof(v)
  191. #define STBRP__CDECL
  192. #endif
  193. enum
  194. {
  195. STBRP__INIT_skyline = 1
  196. };
  197. STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
  198. {
  199. switch (context->init_mode) {
  200. case STBRP__INIT_skyline:
  201. STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
  202. context->heuristic = heuristic;
  203. break;
  204. default:
  205. STBRP_ASSERT(0);
  206. }
  207. }
  208. STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
  209. {
  210. if (allow_out_of_mem)
  211. // if it's ok to run out of memory, then don't bother aligning them;
  212. // this gives better packing, but may fail due to OOM (even though
  213. // the rectangles easily fit). @TODO a smarter approach would be to only
  214. // quantize once we've hit OOM, then we could get rid of this parameter.
  215. context->align = 1;
  216. else {
  217. // if it's not ok to run out of memory, then quantize the widths
  218. // so that num_nodes is always enough nodes.
  219. //
  220. // I.e. num_nodes * align >= width
  221. // align >= width / num_nodes
  222. // align = ceil(width/num_nodes)
  223. context->align = (context->width + context->num_nodes-1) / context->num_nodes;
  224. }
  225. }
  226. STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
  227. {
  228. int i;
  229. #ifndef STBRP_LARGE_RECTS
  230. STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
  231. #endif
  232. for (i=0; i < num_nodes-1; ++i)
  233. nodes[i].next = &nodes[i+1];
  234. nodes[i].next = NULL;
  235. context->init_mode = STBRP__INIT_skyline;
  236. context->heuristic = STBRP_HEURISTIC_Skyline_default;
  237. context->free_head = &nodes[0];
  238. context->active_head = &context->extra[0];
  239. context->width = width;
  240. context->height = height;
  241. context->num_nodes = num_nodes;
  242. stbrp_setup_allow_out_of_mem(context, 0);
  243. // node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
  244. context->extra[0].x = 0;
  245. context->extra[0].y = 0;
  246. context->extra[0].next = &context->extra[1];
  247. context->extra[1].x = (stbrp_coord) width;
  248. #ifdef STBRP_LARGE_RECTS
  249. context->extra[1].y = (1<<30);
  250. #else
  251. context->extra[1].y = 65535;
  252. #endif
  253. context->extra[1].next = NULL;
  254. }
  255. // find minimum y position if it starts at x1
  256. static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
  257. {
  258. stbrp_node *node = first;
  259. int x1 = x0 + width;
  260. int min_y, visited_width, waste_area;
  261. STBRP__NOTUSED(c);
  262. STBRP_ASSERT(first->x <= x0);
  263. #if 0
  264. // skip in case we're past the node
  265. while (node->next->x <= x0)
  266. ++node;
  267. #else
  268. STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
  269. #endif
  270. STBRP_ASSERT(node->x <= x0);
  271. min_y = 0;
  272. waste_area = 0;
  273. visited_width = 0;
  274. while (node->x < x1) {
  275. if (node->y > min_y) {
  276. // raise min_y higher.
  277. // we've accounted for all waste up to min_y,
  278. // but we'll now add more waste for everything we've visted
  279. waste_area += visited_width * (node->y - min_y);
  280. min_y = node->y;
  281. // the first time through, visited_width might be reduced
  282. if (node->x < x0)
  283. visited_width += node->next->x - x0;
  284. else
  285. visited_width += node->next->x - node->x;
  286. } else {
  287. // add waste area
  288. int under_width = node->next->x - node->x;
  289. if (under_width + visited_width > width)
  290. under_width = width - visited_width;
  291. waste_area += under_width * (min_y - node->y);
  292. visited_width += under_width;
  293. }
  294. node = node->next;
  295. }
  296. *pwaste = waste_area;
  297. return min_y;
  298. }
  299. typedef struct
  300. {
  301. int x,y;
  302. stbrp_node **prev_link;
  303. } stbrp__findresult;
  304. static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
  305. {
  306. int best_waste = (1<<30), best_x, best_y = (1 << 30);
  307. stbrp__findresult fr;
  308. stbrp_node **prev, *node, *tail, **best = NULL;
  309. // align to multiple of c->align
  310. width = (width + c->align - 1);
  311. width -= width % c->align;
  312. STBRP_ASSERT(width % c->align == 0);
  313. node = c->active_head;
  314. prev = &c->active_head;
  315. while (node->x + width <= c->width) {
  316. int y,waste;
  317. y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
  318. if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
  319. // bottom left
  320. if (y < best_y) {
  321. best_y = y;
  322. best = prev;
  323. }
  324. } else {
  325. // best-fit
  326. if (y + height <= c->height) {
  327. // can only use it if it first vertically
  328. if (y < best_y || (y == best_y && waste < best_waste)) {
  329. best_y = y;
  330. best_waste = waste;
  331. best = prev;
  332. }
  333. }
  334. }
  335. prev = &node->next;
  336. node = node->next;
  337. }
  338. best_x = (best == NULL) ? 0 : (*best)->x;
  339. // if doing best-fit (BF), we also have to try aligning right edge to each node position
  340. //
  341. // e.g, if fitting
  342. //
  343. // ____________________
  344. // |____________________|
  345. //
  346. // into
  347. //
  348. // | |
  349. // | ____________|
  350. // |____________|
  351. //
  352. // then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
  353. //
  354. // This makes BF take about 2x the time
  355. if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
  356. tail = c->active_head;
  357. node = c->active_head;
  358. prev = &c->active_head;
  359. // find first node that's admissible
  360. while (tail->x < width)
  361. tail = tail->next;
  362. while (tail) {
  363. int xpos = tail->x - width;
  364. int y,waste;
  365. STBRP_ASSERT(xpos >= 0);
  366. // find the left position that matches this
  367. while (node->next->x <= xpos) {
  368. prev = &node->next;
  369. node = node->next;
  370. }
  371. STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
  372. y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
  373. if (y + height < c->height) {
  374. if (y <= best_y) {
  375. if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
  376. best_x = xpos;
  377. STBRP_ASSERT(y <= best_y);
  378. best_y = y;
  379. best_waste = waste;
  380. best = prev;
  381. }
  382. }
  383. }
  384. tail = tail->next;
  385. }
  386. }
  387. fr.prev_link = best;
  388. fr.x = best_x;
  389. fr.y = best_y;
  390. return fr;
  391. }
  392. static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
  393. {
  394. // find best position according to heuristic
  395. stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
  396. stbrp_node *node, *cur;
  397. // bail if:
  398. // 1. it failed
  399. // 2. the best node doesn't fit (we don't always check this)
  400. // 3. we're out of memory
  401. if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
  402. res.prev_link = NULL;
  403. return res;
  404. }
  405. // on success, create new node
  406. node = context->free_head;
  407. node->x = (stbrp_coord) res.x;
  408. node->y = (stbrp_coord) (res.y + height);
  409. context->free_head = node->next;
  410. // insert the new node into the right starting point, and
  411. // let 'cur' point to the remaining nodes needing to be
  412. // stiched back in
  413. cur = *res.prev_link;
  414. if (cur->x < res.x) {
  415. // preserve the existing one, so start testing with the next one
  416. stbrp_node *next = cur->next;
  417. cur->next = node;
  418. cur = next;
  419. } else {
  420. *res.prev_link = node;
  421. }
  422. // from here, traverse cur and free the nodes, until we get to one
  423. // that shouldn't be freed
  424. while (cur->next && cur->next->x <= res.x + width) {
  425. stbrp_node *next = cur->next;
  426. // move the current node to the free list
  427. cur->next = context->free_head;
  428. context->free_head = cur;
  429. cur = next;
  430. }
  431. // stitch the list back in
  432. node->next = cur;
  433. if (cur->x < res.x + width)
  434. cur->x = (stbrp_coord) (res.x + width);
  435. #ifdef _DEBUG
  436. cur = context->active_head;
  437. while (cur->x < context->width) {
  438. STBRP_ASSERT(cur->x < cur->next->x);
  439. cur = cur->next;
  440. }
  441. STBRP_ASSERT(cur->next == NULL);
  442. {
  443. int count=0;
  444. cur = context->active_head;
  445. while (cur) {
  446. cur = cur->next;
  447. ++count;
  448. }
  449. cur = context->free_head;
  450. while (cur) {
  451. cur = cur->next;
  452. ++count;
  453. }
  454. STBRP_ASSERT(count == context->num_nodes+2);
  455. }
  456. #endif
  457. return res;
  458. }
  459. // [DEAR IMGUI] Added STBRP__CDECL
  460. static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
  461. {
  462. const stbrp_rect *p = (const stbrp_rect *) a;
  463. const stbrp_rect *q = (const stbrp_rect *) b;
  464. if (p->h > q->h)
  465. return -1;
  466. if (p->h < q->h)
  467. return 1;
  468. return (p->w > q->w) ? -1 : (p->w < q->w);
  469. }
  470. // [DEAR IMGUI] Added STBRP__CDECL
  471. static int STBRP__CDECL rect_original_order(const void *a, const void *b)
  472. {
  473. const stbrp_rect *p = (const stbrp_rect *) a;
  474. const stbrp_rect *q = (const stbrp_rect *) b;
  475. return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
  476. }
  477. #ifdef STBRP_LARGE_RECTS
  478. #define STBRP__MAXVAL 0xffffffff
  479. #else
  480. #define STBRP__MAXVAL 0xffff
  481. #endif
  482. STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
  483. {
  484. int i, all_rects_packed = 1;
  485. // we use the 'was_packed' field internally to allow sorting/unsorting
  486. for (i=0; i < num_rects; ++i) {
  487. rects[i].was_packed = i;
  488. }
  489. // sort according to heuristic
  490. STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
  491. for (i=0; i < num_rects; ++i) {
  492. if (rects[i].w == 0 || rects[i].h == 0) {
  493. rects[i].x = rects[i].y = 0; // empty rect needs no space
  494. } else {
  495. stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
  496. if (fr.prev_link) {
  497. rects[i].x = (stbrp_coord) fr.x;
  498. rects[i].y = (stbrp_coord) fr.y;
  499. } else {
  500. rects[i].x = rects[i].y = STBRP__MAXVAL;
  501. }
  502. }
  503. }
  504. // unsort
  505. STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
  506. // set was_packed flags and all_rects_packed status
  507. for (i=0; i < num_rects; ++i) {
  508. rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
  509. if (!rects[i].was_packed)
  510. all_rects_packed = 0;
  511. }
  512. // return the all_rects_packed status
  513. return all_rects_packed;
  514. }
  515. #endif
  516. /*
  517. ------------------------------------------------------------------------------
  518. This software is available under 2 licenses -- choose whichever you prefer.
  519. ------------------------------------------------------------------------------
  520. ALTERNATIVE A - MIT License
  521. Copyright (c) 2017 Sean Barrett
  522. Permission is hereby granted, free of charge, to any person obtaining a copy of
  523. this software and associated documentation files (the "Software"), to deal in
  524. the Software without restriction, including without limitation the rights to
  525. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  526. of the Software, and to permit persons to whom the Software is furnished to do
  527. so, subject to the following conditions:
  528. The above copyright notice and this permission notice shall be included in all
  529. copies or substantial portions of the Software.
  530. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  531. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  532. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  533. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  534. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  535. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  536. SOFTWARE.
  537. ------------------------------------------------------------------------------
  538. ALTERNATIVE B - Public Domain (www.unlicense.org)
  539. This is free and unencumbered software released into the public domain.
  540. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
  541. software, either in source code form or as a compiled binary, for any purpose,
  542. commercial or non-commercial, and by any means.
  543. In jurisdictions that recognize copyright laws, the author or authors of this
  544. software dedicate any and all copyright interest in the software to the public
  545. domain. We make this dedication for the benefit of the public at large and to
  546. the detriment of our heirs and successors. We intend this dedication to be an
  547. overt act of relinquishment in perpetuity of all present and future rights to
  548. this software under copyright law.
  549. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  550. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  551. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  552. AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  553. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  554. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  555. ------------------------------------------------------------------------------
  556. */