simple.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 <stddef.h>
  11. #define MAXINTS 10000 /* modify this line to reflect the max no. of
  12. intersections you want reported -- 50000 seems to break the program */
  13. #define SLOPE(p,q) ( ( ( p.y ) - ( q.y ) ) / ( ( p.x ) - ( q.x ) ) )
  14. #define MAX(a,b) ( ( a ) > ( b ) ? ( a ) : ( b ) )
  15. #define after(v) (((v)==((v)->poly->finish))?((v)->poly->start):((v)+1))
  16. #define prior(v) (((v)==((v)->poly->start))?((v)->poly->finish):((v)-1))
  17. struct position {
  18. float x, y;
  19. };
  20. struct vertex {
  21. struct position pos;
  22. struct polygon *poly;
  23. struct active_edge *active;
  24. };
  25. struct polygon {
  26. struct vertex *start, *finish;
  27. };
  28. struct intersection {
  29. struct vertex *firstv, *secondv;
  30. struct polygon *firstp, *secondp;
  31. float x, y;
  32. };
  33. struct active_edge {
  34. struct vertex *name;
  35. struct active_edge *next, *last;
  36. };
  37. struct active_edge_list {
  38. struct active_edge *first, *final;
  39. int number;
  40. };
  41. struct data {
  42. size_t nvertices;
  43. int ninters;
  44. };
  45. void find_ints(struct vertex vertex_list[], struct data *input,
  46. struct intersection ilist[]);
  47. /// detect whether lines `l` and `m` intersect
  48. void find_intersection(struct vertex *l, struct vertex *m,
  49. struct intersection ilist[], struct data *input);