geomprocs.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * @file
  3. * @ingroup common_utils
  4. * @brief geometric functions (e.g. on points and boxes)
  5. *
  6. * with application to, but no specific dependence on graphs
  7. */
  8. /*************************************************************************
  9. * Copyright (c) 2011 AT&T Intellectual Property
  10. * All rights reserved. This program and the accompanying materials
  11. * are made available under the terms of the Eclipse Public License v1.0
  12. * which accompanies this distribution, and is available at
  13. * https://www.eclipse.org/legal/epl-v10.html
  14. *
  15. * Contributors: Details at https://graphviz.org
  16. *************************************************************************/
  17. #pragma once
  18. #include <stdbool.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #include "geom.h"
  23. #ifdef GVDLL
  24. #ifdef GVC_EXPORTS
  25. #define GEOMPROCS_API __declspec(dllexport)
  26. #else
  27. #define GEOMPROCS_API __declspec(dllimport)
  28. #endif
  29. #endif
  30. #ifndef GEOMPROCS_API
  31. #define GEOMPROCS_API /* nothing */
  32. #endif
  33. GEOMPROCS_API boxf flip_rec_boxf(boxf b, pointf p);
  34. GEOMPROCS_API double ptToLine2 (pointf l1, pointf l2, pointf p);
  35. GEOMPROCS_API int lineToBox(pointf p1, pointf p2, boxf b);
  36. GEOMPROCS_API pointf ccwrotatepf(pointf p, int ccwrot);
  37. GEOMPROCS_API pointf cwrotatepf(pointf p, int cwrot);
  38. GEOMPROCS_API void rect2poly(pointf *p);
  39. GEOMPROCS_API int line_intersect (pointf a, pointf b, pointf c, pointf d, pointf* p);
  40. static inline point add_point(point p, point q)
  41. {
  42. point r;
  43. r.x = p.x + q.x;
  44. r.y = p.y + q.y;
  45. return r;
  46. }
  47. static inline pointf add_pointf(pointf p, pointf q)
  48. {
  49. pointf r;
  50. r.x = p.x + q.x;
  51. r.y = p.y + q.y;
  52. return r;
  53. }
  54. static inline pointf sub_pointf(pointf p, pointf q)
  55. {
  56. pointf r;
  57. r.x = p.x - q.x;
  58. r.y = p.y - q.y;
  59. return r;
  60. }
  61. static inline pointf mid_pointf(pointf p, pointf q)
  62. {
  63. pointf r;
  64. r.x = (p.x + q.x) / 2.;
  65. r.y = (p.y + q.y) / 2.;
  66. return r;
  67. }
  68. static inline pointf interpolate_pointf(double t, pointf p, pointf q)
  69. {
  70. pointf r;
  71. r.x = p.x + t * (q.x - p.x);
  72. r.y = p.y + t * (q.y - p.y);
  73. return r;
  74. }
  75. static inline point exch_xy(point p)
  76. {
  77. point r;
  78. r.x = p.y;
  79. r.y = p.x;
  80. return r;
  81. }
  82. static inline pointf exch_xyf(pointf p)
  83. {
  84. pointf r;
  85. r.x = p.y;
  86. r.y = p.x;
  87. return r;
  88. }
  89. static inline bool boxf_overlap(boxf b0, boxf b1) {
  90. return OVERLAP(b0, b1);
  91. }
  92. static inline pointf perp (pointf p)
  93. {
  94. pointf r;
  95. r.x = -p.y;
  96. r.y = p.x;
  97. return r;
  98. }
  99. static inline pointf scale (double c, pointf p)
  100. {
  101. pointf r;
  102. r.x = c * p.x;
  103. r.y = c * p.y;
  104. return r;
  105. }
  106. #undef GEOMPROCS_API
  107. #ifdef __cplusplus
  108. }
  109. #endif