Skip to content

Commit

Permalink
Merge pull request #479 from lepsa/fixing-exports
Browse files Browse the repository at this point in the history
Fixing export issues where unsupported primitives were being generated.
  • Loading branch information
sorki committed Jan 8, 2024
2 parents 01d3e9b + a1afe98 commit 6651529
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Fixing an issue with bounding boxes for infinite functions. [#412](https://github.com/Haskell-Things/ImplicitCAD/issues/412)
* Making `torus` and `ellipsoid` primitive objects, rather than being defined implicitly. [#450](https://github.com/Haskell-Things/ImplicitCAD/issues/450)
* Improved formatting of ExtOpenSCAD code [#472](https://github.com/Haskell-Things/ImplicitCAD/pull/472)
* Fixing an issue where ImplicitCAD extended primitive objects were being exported to OpenSCAD where they aren't supported.

# Version [0.4.1.0](https://github.com/Haskell-Things/ImplicitCAD/compare/v0.4.0.0...v0.4.1.0) (2023-12-18)

Expand Down
10 changes: 6 additions & 4 deletions Graphics/Implicit/Definitions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ data SymbolicObj3 =
Cube ℝ3 -- rounding, size.
| Sphere -- radius
| Cylinder --
| Torus
| Ellipsoid
| BoxFrame ℝ3 -- b e from https://iquilezles.org/articles/distfunctions/
| Link -- le r1 r2 from https://iquilezles.org/articles/distfunctions/
-- Simple transforms
| Rotate3 (Quaternion ) SymbolicObj3
| Transform3 (M44 ) SymbolicObj3
Expand All @@ -353,6 +349,12 @@ data SymbolicObj3 =
SymbolicObj2 -- object to extrude
| ExtrudeOnEdgeOf SymbolicObj2 SymbolicObj2
| Shared3 (SharedObj SymbolicObj3 V3 )
-- Extended useful primitives.
-- These aren't supported by escad.
| Torus
| Ellipsoid
| BoxFrame ℝ3 -- b e from https://iquilezles.org/articles/distfunctions/
| Link -- le r1 r2 from https://iquilezles.org/articles/distfunctions/
deriving (Generic)

instance Show SymbolicObj3 where
Expand Down
17 changes: 5 additions & 12 deletions Graphics/Implicit/Export/SymbolicFormats.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,6 @@ buildS3 _ (Cube (V3 w d h)) = call "cube" [pretty $ bf w, pretty $ bf d, pretty

buildS3 _ (Sphere r) = callNaked "sphere" ["r = " <> pretty (bf r)] []

buildS3 _ (Torus r1 r2) = callNaked "torus" ["r1 = " <> pretty (bf r1), "r2 = " <> pretty (bf r2)] []

buildS3 _ (Ellipsoid a b c) = callNaked "ellipsoid" ["a = " <> pretty (bf a), "b = " <> pretty (bf b), "c = " <> pretty (bf c)] []

buildS3 _ (BoxFrame (V3 w d h) e) = callNaked "boxFrame"
["w = " <> pretty (bf w), "d = " <> pretty (bf d), "h = " <> pretty (bf h), "e = " <> pretty (bf e)]
[]

buildS3 _ (Link le r1 r2) = callNaked "link"
["le = " <> pretty (bf le), "r1 = " <> pretty (bf r1), "r2 = " <> pretty (bf r2)]
[]

buildS3 _ (Cylinder h r1 r2) = callNaked "cylinder" [
"r1 = " <> pretty (bf r1)
,"r2 = " <> pretty (bf r2)
Expand Down Expand Up @@ -178,6 +166,11 @@ buildS3 res (ExtrudeM twist scale (Left translate) obj (Left height)) |isScaleID
buildS3 _ ExtrudeM{} = error "cannot provide roundness when exporting openscad; unsupported in target format."
buildS3 _ RotateExtrude{} = error "cannot provide roundness when exporting openscad; unsupported in target format."
buildS3 _ (ExtrudeOnEdgeOf _ _) = error "cannot provide roundness when exporting openscad; unsupported in target format."
-- Extended primitives that aren't supported in openscad
buildS3 _ Torus{} = error "cannot use torus objects when exporting openscad; unsupported in target format."
buildS3 _ Ellipsoid{} = error "cannot use ellipsoid objects when exporting openscad; unsupported in target format."
buildS3 _ BoxFrame{} = error "cannot use boxFrame objects when exporting openscad; unsupported in target format."
buildS3 _ Link{} = error "cannot use link objects when exporting openscad; unsupported in target format."

-- Now the 2D objects/transforms.

Expand Down
4 changes: 2 additions & 2 deletions tests/GoldenSpec/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ spec = describe "golden tests" $ do

goldenAllFormats "pretty-printing" 2 $
union
[ torus 40 15
, ellipsoid 10 15 20
[ sphere 15
, cube False (V3 10 15 20)
, translate (V3 0 0 25) $ union
[ cone 20 20
, cube False 10
Expand Down
4 changes: 2 additions & 2 deletions tests/golden/pretty-printing.scad
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
union() {
torus(r1 = 4.0e1, r2 = 1.5e1);
ellipsoid(a = 1.0e1, b = 1.5e1, c = 2.0e1);
sphere(r = 1.5e1);
cube([1.0e1, 1.5e1, 2.0e1]);
translate([0.0e0, 0.0e0, 2.5e1]) union() {
cylinder(r1 = 0.0e0, r2 = 2.0e1, 2.0e1);
cube([1.0e1, 1.0e1, 1.0e1]);
Expand Down
Binary file modified tests/golden/pretty-printing.stl
Binary file not shown.

0 comments on commit 6651529

Please sign in to comment.