- Project Overview
- Domain Exploration
- DSL Design Decisions
- Usage Examples
- Project Structure
- Build and Run Instructions
- Testing
- Future Enhancements
- Contributors
This project demonstrates the creation of a Domain Specific Language (DSL) using Scala 3. The DSL is designed to define 3D shapes and generate STL (Stereolithography) files. STL files are a common format for representing 3D models in computer-aided design and 3D printing. The project leverages the power of Scala's functional programming paradigm and its advanced type system to create an expressive and intuitive way to describe geometric forms.
The domain of this project is 3D geometric modeling. The core concepts include:
- Shapes: We define basic 3D shapes such as cubes, spheres, cylinders, and rectangles.
- Points: 3D coordinates represented as
Point(x, y, z)
. - Dimensions: Linear dimensions represented as
Centimeter(value)
- Tesselation: Triangulation of the shape.
- Triangle : Represent a triangle using three points.
- Functional Approach: Scala's support for functional programming allows for a declarative style, making the DSL expressive and composable.
- Type Safety: The type system ensures correctness and prevents common errors, enhancing the robustness of the DSL.
- Extensibility: New shapes and operations can be added easily, making it adaptable to future requirements.
- Immutability: Data is immutable, which helps avoid side effects and promotes pure functions.
- Case Classes The case class design pattern is used to represent data.
Here are some examples of how to use the DSL to create various 3D shapes:
Creating a Cube:
scala val cube = new Cube(Point(0, 0, 0), Centimeter(10))
Creating a Sphere:
scala val sphere = new Sphere(Point(5, 5, 5), Centimeter(5))
Creating a Cylinder:
scala val cylinder = new Cylinder(Point(10, 10, 0), Centimeter(10), Centimeter(3))
- generate your objects
- download objects
- Go to https://3dviewer.net/
- upload objects
The project directory is organized as follows:
cadman/ src/main/scala/geometry/ Point.scala Centimeter.scala Shape.scala Cube.scala Sphere.scala Cylinder.scala Rectangle.scala project/
src/main/scala/geometry/
: This directory contains the core code for the DSL, including classes representing shapes and data structures.Point.scala
: Defines thePoint
class representing 3D coordinates.Centimeter.scala
: Defines theCentimeter
class for representing lengths.Shape.scala
: Defines theShape
trait, which all shapes extend.Cube.scala
: Implements theCube
shape.Sphere.scala
: Implements theSphere
shape.Cylinder.scala
: Implements theCylinder
shape.Rectangle.scala
: Implements theRectangle
shape.
project/
: Contains SBT project configuration files.
- Prerequisites: Ensure you have Java 8+ and Scala 3 installed, along with sbt. See the official Scala and sbt websites for installation instructions.
- Navigate to the project directory:
bash cd cadman
- Run the project:
sbt run
This project could use a testing strategy based on ScalaTest or Specs2, a popular testing framework in the Scala ecosystem.
You could create test cases that assert the tessellate
method returns the expected triangulation for a variety of shapes and parameters.
Example:
scala //Test file in a new tests folder import org.scalatest.funsuite.AnyFunSuite import geometry._
class CubeTests extends AnyFunSuite {
test("Cube Tesselation") { val cube = new Cube(Point(0, 0, 0), Centimeter(10)) // ... asserts on cube.tessellate() results } }
- Support for more shapes: Add support for additional 3D shapes (e.g., cones, pyramids).
- Material properties: Allow users to specify materials for 3D models (e.g., plastic, metal).
- Export to other formats: Enable export to other 3D file formats (e.g., OBJ, 3DS).
- Boolean operations: Implement operations such as union, intersection, and difference between shapes.
- Advanced tessellation: Offer finer cont
- Oscra BYRNE
- Maël AUBERT
- Amine NACHIT
- Baptiste NEVEJANS
- Anis DALI-AHMED