SVGDocument
Parses an SVG file (Use the program Inkscape to edit SVG files) This is a Union2d of all shapes within the SVG file.
However, more often you want to access specific shapes within the SVG file.
Within Inkscape, you change an object's ID using the "Object Properties" dialog (shortcut Shift+Ctrl+O on my computer).
You can then get a single Shape2d using :
val svgDoc = SVGDocument( "drawing.svg" )
val heart = svgDoc["heart"]
The currently supported shapes are :
path
rect
circle
ellipse
polygon
group
Current unsupported :
polyline - Currently treated exactly like a polygon (i.e. the ends are closed)
text - ignored
Currently supported transformations : https://www.w3.org/TR/SVG11/coords.html#TransformAttribute These are parsed from the following tags : g, path, rect, circle, ellipse, polygon, polyline
translate(x), translate(x,y)
scale(x), scale(x,y)
rotate( angle ), rotate( angle, x, y )
matrix( a, b, c, d, e, f )
Currently unsupported transformations :
skewX( angle )
skewY( angle )
Also the top-level svg
tag is parsed for its viewBox
attribute. We transform all SVG coordinates, which have the origin at the top left (with the Y axis pointing downwards) to FooCAD's system, with the origin at the bottom left (with the Y axis pointing upwards). Note, you can change the viewBox within Inkscape using the Document Properties
dialog (Shortcut Shift+Control+D
on my system).
SVGParser supports complex polygons with holes (and even polygons with holes with islands with holes...). Each sub-path is tested to see which other sub-paths it is within. If the number is odd, it is a hole, and if it is even, it is not a hole. SVGParser ensures that the points of holes are ordered clockwise, and non-holes anticlockwise. (regardless of the order within the SVG file).
FooCAD does NOT support polygons with crossed paths, but SVG does. So make sure not to create such a shape, otherwise weirdness will occur!
Constructors
Properties
Imagine travelling in a straight line cutting through the shape. The convexity is the maximum number of times your will enter the shape. For square and circle, this is 1. For a convex shape with a hole, it is 2. For a shape with a single concave part, such as a banana, it is also 2.
The 2D points which define the lines around the shape. This is a list of Path2d because a shape can have holes (so there's one path for the exterior, and one path for each hole). Also, a shape can be a compound of more than one exterior shape. e.g. If we have 2 circles (like a 'colon' symbol) we can define it using a single Shape2d with two paths.
Functions
Moves the center of this shape to xy.
If this Shape is a Shape2dDependent
An operator which is the same as intersection.
Checks that this shape's paths are ordered correctly. All paths are tests to see how many of the other paths contain it. If the answer is odd, it is assumed to be a hole, and the order of the points is made clockwise. If the answer is even, then the order of the points is made anticlockwise.
Extrude a 2D shape upwards (in the Z direction) to form a 3D shape (an extrusion).
Extrude this 2D shape along a 3D path.
Extrude this 2D shape around the edge of another Shape2d (aroundShape).
Mirror along the line X=Y. i.e. the X and Y values are switched over.
Combines this shape and the other shape, such that only the places that the two shapes overlap are present in the result.
Labels a shape, so that we can collect all the important labelled shapes, and ignore the others.
An operator which is the same as difference.
Uses OpedSCAD's built-in offset module to grow/shrink this 2d shape.
Shows as transparent in OpenSCAD's preview mode, but is NOT included in the final rendered version, and therefore will NOT be printed.
Create a solid of revolution. Take this object, stand it up, so that it is on the plane Y=0, and then spin it around the Z axis.
Create a solid of revolution. Take this object, stand it up, so that it is on the plane Y=0, and then spin it angle degrees around the Z axis.
Similar to roundCorner, but rounds all corners.
Creates a new shape, rounding a single corner. This assumes paths is defined, and contains a single list (i.e. is a simple polygon, with no holes).
Similar to roundCorner, but rounds any number of corners.
Convert a FooCAD Shape2d into jts Geometry.
This is here only for completeness, at time of writing, this wasn't being used.
Uses corner to move the object to the origin.
Uses corner to move the object so that it's X value is 0 (i.e. it is touching the Y axis).
Uses corner to move the object so that it's Y value is 0 (i.e. it is touching the X axis). This is the same as frontToOrigin unless this shape has been scaled by a negative amount! See also backToOrigin.
Some operations, such as transform require the paths data. This isn't available for Union2d, Difference2d and Intersection2d, so it may seem impossible to transform a union, difference or intersection. We can though. If we pull the component parts out of the union/difference/intersection, apply the transformation to those shapes, and then recombine the results, everything works out fine.