The Geom module contains 2D geometry and graphics. These can currently be output to JavaFx canvas, Html canvas and Svg. It also contains other geometries including 3D with associated graphics. Development of targets for 3d graphics is still rudimentary. The 2D and 3D can also be defined in length units such as metres, miles and picometres. There is also 2D geometry and graphics that can be defined in latitudes and longitudes.
Let us start with 2D. At is base we have "2D points and Vectors. Points can be combined to create line segments and can be use to to define curves . Line segments and curves can be combined to create line paths, curve paths and shapes. Line segments, line paths, curves and curve paths can be drawn. Shapes can be drawn, filled and activated, meaning that the user can interact with them using a mouse, track pad or gestures. Shapes includes polygons, mathematically simple shapes such as circles, more complex shape such as stadiums and user created shapes that consist of a sequence of curves, including line segments arcs and cubic beziers.
Currently there are 2 ShapeGen classes, an old one that uses an Array of Doubles and a new one that uses an Array of curveTails.
Polygons are used a lot in this module and in modules that use this module. So it is important to establish conventions or defaults. The vertices of an N sided polygon are numbered from 0 to n - 1. With the vertex 0 appearing at 12 o'clock or 00 hundred hours as in the dodecahedron below. Vertex 1 appears at the 1 o'clock position, vertex 2 at the 2 o'clock position etc. The middle of side 0 is at 12.30 or 00.30 hours, the middle of side 1 is at 01.30 hours etc.
I've included the Scala code below both for the above diagram. If you check the html source code for this web page you will see that it is pretty succinct compared with the generated SVG code. The code is in small font and is not type annotated so it is not intended as a tutorial, but just to give an idea of possibilities. It is only the last line that creates the SVG. The rest of the code could be used in an HTML or a JavaFx canvas.
val width: Int = 250
val polyColour: Colour = DarkGreen
val dodec1: DoDeclign = DoDeclign(width)
val dodec2 = dodec1.draw(polyColour)
val circ = Circle(width * 2).draw()
val verts = dodec1.vertsIFlatMap{ (pt, i) => pt.textArrowToward(Pt2Z, "V" + i.str) }
val sides = dodec1.sidesIFlatMap{ (sd, i) => sd.midPt.textArrowAwayFrom(Pt2Z, "Sd" + i.str, colour = polyColour) }
val cen = Pt2Z.textAt("Centre")
val clock = RArr(dodec2, circ, cen) ++ verts ++ sides
val svg1 = HtmlSvg(dodec1.boundingRect.addMargin(svgMargin), clock, RArr(CentreBlockAtt))
If there is no vertex at the 12 o'clock / 00 hundred hours postion as in the rectangle below vertex 0 is the first vertex clockwise of 12 o'clock. The other vertices then follow clockwise. The last vertex being immediately anti clockwise of 12 o'clock.
The positions of the vertices have been shown above. Note that the positions are speciified relative .
Operator naming conventions for sequences and line paths.