Not specific about OPENRNDR or Kotlin, but I was only happy to discover this jvm library which can be useful for generative designs: https://jgrapht.org/
After putting the following into build.gradle.kts
implementation("org.jgrapht", "jgrapht-core", "1.5.0")
I could write this simple program:
// https://jgrapht.org/
val g = SimpleGraph<Int, DefaultEdge>(DefaultEdge::class.java)
for (i in 0..5) {
g.addVertex(i)
}
for (i in 0..5) {
g.addEdge(i, (i + 1) % g.vertexSet().size)
}
g.addEdge(0, 3)
println("vertices and edges")
println(g)
println("loops")
val cycles = PatonCycleBase(g)
cycles.cycleBasis.cycles.forEach(::println)
Which outputs
vertices and edges
([0, 1, 2, 3, 4, 5], [{0,1}, {1,2}, {2,3}, {3,4}, {4,5}, {5,0}, {0,3}])
loops
[(4 : 5), (3 : 4), (0 : 3), (5 : 0)]
[(1 : 2), (2 : 3), (0 : 3), (0 : 1)]
I will use it to find closed loops in a design like this (after splitting everything on the intersections):

The code above uses integers for demo purposes, but any type should be ok (including Vector2).
Nice guide and tons of methods to query the graph.


I’m glad you like it. It’s black calligraphy ink diluted with water, but I have in mind trying watercolors too.