# Integral of a function inside non-rectangular domain

**URL:** https://discourse.julialang.org/t/integral-of-a-function-inside-non-rectangular-domain/72132
**Category:** Numerics
**Created:** [November 26, 2021, 9:10pm UTC](https://discourse.julialang.org/t/integral-of-a-function-inside-non-rectangular-domain/72132 "2021-11-26T21:10:22Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [November 27, 2021, 4:16pm UTC](https://discourse.julialang.org/t/integral-of-a-function-inside-non-rectangular-domain/72132/9 "2021-11-27T16:16:00Z")

</div>

> [@rafael.guerra](#):
>
> It is amazing how easy it can be to compose different packages in Julia: `PolygonOps.jl` could be used for more general polygons together with `HCubature.jl` by setting for example:

Given a function to [decompose a polygon into a collection of triangles](https://en.wikipedia.org/wiki/Polygon_triangulation), you could implement a much more efficient and accurate cubature (e.g. via HCubature) without introducing artificial discontinuities.

One option is [EarCut.jl](https://github.com/JuliaGeometry/EarCut.jl), although it would be nicer to have a Julia-native library. (The C++ library was apparently ported from [~600 lines of JavaScript](https://github.com/mapbox/earcut), so why not port the JavaScript to Julia?)

PS. In fact, HCubature could easily be modified to support “globally adaptive quadrature” over a collection of triangles (mapped into squares), so that it would look at all the subregions simultaneously when deciding where to refine; this is really the right way to attack such problems. It would be pretty easy to write a PolygonQuadrature.jl package on top of HCubature and EarCut (or similar).

---

_[View the full topic](https://discourse.julialang.org/t/integral-of-a-function-inside-non-rectangular-domain/72132)._
