wrapper.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. #include <pathplan/pathgeom.h>
  11. #include "Plegal_arrangement.h"
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include "simple.h"
  15. #include <util/alloc.h>
  16. int Plegal_arrangement(Ppoly_t **polys, size_t n_polys) {
  17. int rv;
  18. struct data input;
  19. struct intersection ilist[10000];
  20. struct polygon *polygon_list = gv_calloc(n_polys, sizeof(struct polygon));
  21. size_t nverts = 0;
  22. for (size_t i = 0; i < n_polys; i++)
  23. nverts += polys[i]->pn;
  24. struct vertex *vertex_list = gv_calloc(nverts, sizeof(struct vertex));
  25. for (size_t i = 0, vno = 0; i < n_polys; i++) {
  26. polygon_list[i].start = &vertex_list[vno];
  27. for (size_t j = 0; j < polys[i]->pn; j++) {
  28. vertex_list[vno].pos.x = polys[i]->ps[j].x;
  29. vertex_list[vno].pos.y = polys[i]->ps[j].y;
  30. vertex_list[vno].poly = &polygon_list[i];
  31. vno++;
  32. }
  33. polygon_list[i].finish = &vertex_list[vno - 1];
  34. }
  35. input.nvertices = nverts;
  36. find_ints(vertex_list, &input, ilist);
  37. #define EQ_PT(v,w) (((v).x == (w).x) && ((v).y == (w).y))
  38. rv = 1;
  39. {
  40. struct position vft, vsd, avft, avsd;
  41. for (int i = 0; i < input.ninters; i++) {
  42. vft = ilist[i].firstv->pos;
  43. avft = after(ilist[i].firstv)->pos;
  44. vsd = ilist[i].secondv->pos;
  45. avsd = after(ilist[i].secondv)->pos;
  46. if ((vft.x != avft.x && vsd.x != avsd.x) ||
  47. (vft.x == avft.x && !EQ_PT(vft, ilist[i]) && !EQ_PT(avft, ilist[i])) ||
  48. (vsd.x == avsd.x && !EQ_PT(vsd, ilist[i]) && !EQ_PT(avsd, ilist[i]))) {
  49. rv = 0;
  50. fprintf(stderr, "\nintersection %d at %.3f %.3f\n",
  51. i, ilist[i].x, ilist[i].y);
  52. fprintf(stderr, "seg#1 : (%.3f, %.3f) (%.3f, %.3f)\n",
  53. ilist[i].firstv->pos.x
  54. , ilist[i].firstv->pos.y
  55. , after(ilist[i].firstv)->pos.x
  56. , after(ilist[i].firstv)->pos.y);
  57. fprintf(stderr, "seg#2 : (%.3f, %.3f) (%.3f, %.3f)\n",
  58. ilist[i].secondv->pos.x
  59. , ilist[i].secondv->pos.y
  60. , after(ilist[i].secondv)->pos.x
  61. , after(ilist[i].secondv)->pos.y);
  62. }
  63. }
  64. }
  65. free(polygon_list);
  66. free(vertex_list);
  67. return rv;
  68. }