code: convert geometry code to Scala