diff --git a/docs/benchmarks.md b/docs/benchmarks.md index c0894514..581304dc 100644 --- a/docs/benchmarks.md +++ b/docs/benchmarks.md @@ -1,6 +1,6 @@ -See the live benchmakrs: +See the live benchmarks: - + - [Cuboid](benchmarks/cuboid) - [Line](benchmarks/line) - [Point](benchmarks/point) diff --git a/docs/developers/polygons.md b/docs/developers/polygons.md index 31f2c53e..d63ba146 100644 --- a/docs/developers/polygons.md +++ b/docs/developers/polygons.md @@ -59,9 +59,9 @@ for (let i = 0; i < coords.length; i++) { } ``` -To test the coplanarity of the polygon we create a +To test whether a polygon is coplanar we create a [plane](https://en.wikipedia.org/wiki/Plane_(geometry)) using the 1st, 2nd -and last coordinates of the polygon (these coordinates are choosen +and last coordinates of the polygon (these coordinates are chosen because the vectors 1st->2nd and last->2nd have different directions, what is necessary to build the [plane](https://en.wikipedia.org/wiki/Plane_(geometry))). diff --git a/docs/documentation.md b/docs/documentation.md index 9731120b..f16b40e8 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -1,7 +1,7 @@ Welcome to the mathics-threejs-backend documentation! You can use mathics-threejs-backend in 2 ways: -- **production** — a stable release. To use either use the content-development network (CDN) or host the files in your own webserver: +- **production** — a stable release. To use either use the content-development network (CDN) or host the files in your own web-server: - to use the CDN: ```html @@ -36,7 +36,7 @@ The main function of mathics-threejs-backend is `drawGraphics3d`, takes the foll - `ticks` (type: [number[], number[], string[]][3]) — array containing the ticks' information for, respectively, x, y and z axes. The ticks' information is an array of three elements: big ticks' 0-1 coordinates, small ticks' 0-1 coordinates, big ticks' labels. Default: `[]` - `ticks_style` (type: [color[3]](/mathics-threejs-backend/types/color)) — array containing the ticks' colors for, respectively, x, y and z axes. Default: `[[0, 0, 0], [0, 0, 0], [0, 0, 0]]` (all ticks are black) - `elements` (type: [element[]](/mathics-threejs-backend/types/color) — array of primitives, default: `[]` - - `extent` (type: object) — the size of the bounding box. This is optional, only use this if you don't want the default behaviour. This is an object with the following properties: + - `extent` (type: object) — the size of the bounding box. This is optional, only use this if you don't want the default behavior. This is an object with the following properties: - `xmin` (type: number) - `ymin` (type: number) - `zmin` (type: number) diff --git a/docs/examples.md b/docs/examples.md index 0488b967..a77e385e 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -1,7 +1,7 @@ See our gallery: - + - [☆ 2 connected cones with edges](examples/cones-with-edges) - [☆ 2 connected cylinders](examples/connected-cylinders) - [● Black point](examples/black-point) @@ -24,7 +24,7 @@ See our gallery: - [☆ Simple tube](examples/simple-tube) - [● Sine points](examples/sine-points) - [○ Sphere with yellow spotlight](examples/yellow-spotlight) -- [○ Spheres with center pointlight](examples/spheres-with-center-pointlight) +- [○ Spheres with center point light](examples/spheres-with-center-pointlight) - [⬠ Tetrahedron](examples/tetrahedron) - [△ Triangle with edges](examples/triangle-with-edges) - [☆ Tube, dodecahedrons and spheres](examples/tube-dodecahedrons-and-spheres) diff --git a/docs/index.md b/docs/index.md index 40d99e39..32247a36 100644 --- a/docs/index.md +++ b/docs/index.md @@ -2,7 +2,7 @@ Welcome to the mathics-threejs-backend documentation and examples! mathics-threejs-backend is a JavaScript library for rendering [Mathics](https://mathics.org) (and eventually Wolfram Language) [Graphics3D](https://reference.wolfram.com/language/ref/Graphics3D.html) objects. -This can be used in Mathics front ends like [Mathics-Django](https://pypi.org/project/Mathics-Django/) and [Symja](https://github.com/axkr/symja_android_library) to handle 3D graphics. The code may also be useful as a guide for other kinds of Mathics/WL frontends to other kinds of JavaScript graphics engines. +This can be used in Mathics front ends like [Mathics-Django](https://pypi.org/project/Mathics-Django/) and [Symja](https://github.com/axkr/symja_android_library) to handle 3D graphics. The code may also be useful as a guide for other kinds of Mathics/WL front-ends to other kinds of JavaScript graphics engines. See [our gallery](examples). diff --git a/docs/primitives/cone.md b/docs/primitives/cone.md index 161aa357..804eba75 100644 --- a/docs/primitives/cone.md +++ b/docs/primitives/cone.md @@ -1,8 +1,8 @@ Properties: -- `color` (type: [color/mathics-threejs-backend/types/color)) — default: white -- `coords` (type: [coord[]/mathics-threejs-backend/types/coord)) — array of cylinders' centers +- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: white +- `coords` (type: [coord[]](/mathics-threejs-backend/types/coord)) — array of cylinders' centers - `edgeForm` (type: object) — default: `{}`, object with the following properties: - - `color` (type: [color/mathics-threejs-backend/types/color)) — edges' color, default: black + - `color` (type: [color](/mathics-threejs-backend/types/color)) — edges' color, default: black - `showEdges` (type: bool) — default: `true` - `radius` (type: number) — default: `1` - `opacity` (type: number) — default: `1` diff --git a/docs/primitives/cuboid.md b/docs/primitives/cuboid.md index 21b51b94..5dde9e45 100644 --- a/docs/primitives/cuboid.md +++ b/docs/primitives/cuboid.md @@ -1,8 +1,8 @@ Properties: -- `color` (type: [color](documentation/types/color)) — default: white -- `coords` (type: [coord[]](documentation/types/coord)) — array of the cuboids' begins and ends +- `color` (type: [color](/mathics-threejs-backend/types/color)) — default: white +- `coords` (type: [coord[]](/mathics-threejs-backend/types/coord)) — array of the cuboids' begins and ends - `edgeForm` (type: object) — default: `{}`, object with the following properties: - - `color` (type: [color](documentation/types/color)) — edges' color, default: black + - `color` (type: [color](/mathics-threejs-backend/types/color)) — edges' color, default: black - `showEdges` (type: bool) — default: `true` - `opacity` (type: number) — default: `1` diff --git a/docs/primitives/line.md b/docs/primitives/line.md index 65dfa886..d4e214d2 100644 --- a/docs/primitives/line.md +++ b/docs/primitives/line.md @@ -70,4 +70,4 @@ Draw a line from the first coordinate to the last one. ## Notes -- Our behavor is different from Wolframs Language's Line; our lines aren't affected by the lighting and therefore don't have VertexNormals. +- Our behavior is different from Wolframs Language's Line; our lines aren't affected by the lighting and therefore don't have VertexNormals. diff --git a/docs/primitives/point.md b/docs/primitives/point.md index b73cb602..a1fffcb0 100644 --- a/docs/primitives/point.md +++ b/docs/primitives/point.md @@ -96,4 +96,4 @@ Draw points with the point size being canvas' size times `pointSize`. ![1000 points](https://user-images.githubusercontent.com/62714153/124356523-ce9b9680-dbec-11eb-87e0-d200ea93f4c0.png) ## Notes -- Our behavor is different from Wolframs Language's Point, our points aren't affected by lighting and therefore don't have VertexNormals. +- Our behavior is different from Wolframs Language's Point, our points aren't affected by lighting and therefore don't have VertexNormals. diff --git a/docs/types/container.md b/docs/types/container.md index be43d584..e39df591 100644 --- a/docs/types/container.md +++ b/docs/types/container.md @@ -1,4 +1,4 @@ -A HTML element obtained with `document.getElementById` or similars. +A HTML element obtained with `document.getElementById` or similar. The canvas will occupy the whole container. diff --git a/src/bufferUtils.js b/src/bufferUtils.js index 7db933f1..7b9a1cb2 100644 --- a/src/bufferUtils.js +++ b/src/bufferUtils.js @@ -70,7 +70,7 @@ export function getPopulatedCoordinateBuffer(coords, extent) { /** * Create 2 coordinate buffers and copy the even-numbered coordinates from * coords to the 1st coordinate buffer and the odd-numbered ones to the 2nd. - * This is usuful when the primitive have a begin and a end coordinate. + * This is useful when the primitive have a begin and a end coordinate. * Both can't be in the same BufferAttribute. * @param {Array<[Coordinate, null] | [null, Coordinate]>} coords * @param {import('./extent.js').Extent} extent diff --git a/src/extent.js b/src/extent.js index c8012ce5..81a4ddfc 100644 --- a/src/extent.js +++ b/src/extent.js @@ -112,7 +112,7 @@ export default function extent(elements) { }); if (needs2ndPass) { - // 2nd pass, necesary for primitives with scaled coordinates and + // 2nd pass, necessary for primitives with scaled coordinates and // radius > extent. elements.forEach((element) => { if ( diff --git a/src/graphics3d.js b/src/graphics3d.js index cb3db491..e5bdef87 100644 --- a/src/graphics3d.js +++ b/src/graphics3d.js @@ -137,7 +137,7 @@ export default function ( camera.lookAt(focus); } - // Without this the initial axes postion is wrong. + // Without this the initial axes position is wrong. updateCameraPosition(); camera.up.set(0, 0, 1); diff --git a/src/primitives/cone.js b/src/primitives/cone.js index 224768cd..d22b525b 100644 --- a/src/primitives/cone.js +++ b/src/primitives/cone.js @@ -200,11 +200,17 @@ export default function ({ color = [1, 1, 1], coords, edgeForm = {}, opacity = 1 group.add(cones); - // Differently from cuboid's edges, the cones' ones are in a different object. It is very hard or maybe impossible to draw edges with complex shapes in the fragment shader. + // Differently from cuboid's edges, the cones' ones are in a + // different object. It is very hard or maybe impossible to draw + // edges with complex shapes in the fragment shader. // The lines below are the cone base edges' vertices' positions. - // The magic numbers below are modified from the position attribute of a three.js EdgesGeometry of the cone. - // Differently from cylinders' edges, the cones' ones are drawed through Line, now LineSegments, so before putting them in the code we need to remove the repeated numbers. This saves RAM and increases the performance. + // The magic numbers below are modified from the position attribute + // of a three.js EdgesGeometry of the cone. + // Differently from cylinders' edges, the cones' ones are drawn + // through Line, now LineSegments, so before putting them in the + // code we need to remove the repeated numbers. This saves RAM and + // increases the performance. // To get them: console.log(new EdgesGeometry(coneGeometry).attributes.position.array) const edgesGeometry = new InstancedBufferGeometry() diff --git a/src/primitives/index.js b/src/primitives/index.js index f8b72fc4..a628f5f4 100644 --- a/src/primitives/index.js +++ b/src/primitives/index.js @@ -1,6 +1,6 @@ // @ts-check -// This file exports implmentations using three.js of Mathematica and +// This file exports implementations using three.js of Mathematica and // Mathics Graphics3D primitives like "Sphere", or "Cuboid, etc. // A full list of primitives that this might grow to can be found at: @@ -68,7 +68,7 @@ // Also note that in contrast to he Mathematica/Mathics name, we // downcase the first letter of the corresponding name. For example, // we use the function name "sphere" and "uniformPolyhedron", not -// "Sphere" and "UnformPolyhedron". +// "Sphere" and "UniformPolyhedron". // Usually the vertices are stored in the attribute "position". diff --git a/src/primitives/polygon.js b/src/primitives/polygon.js index 9a25201a..633d6138 100644 --- a/src/primitives/polygon.js +++ b/src/primitives/polygon.js @@ -23,8 +23,9 @@ import { scaleCoordinate } from '../coordinateUtils.js'; /** * Get the unit normal vector from the 1st, 2nd and last coordinate - * (these numbers were choosen because the vectors 1st->2nd and last->2nd - * have different directions, what is necessary for some calculations) + * (these numbers were chosen because the vectors 1st->2nd and + * last->2nd have different directions, what is necessary for some + * calculations) * Note: a "better" way to do this is compute an approximation plane * by taking linear least squares, but that would be way slower and * there would be only difference for very specific polygons. @@ -314,7 +315,7 @@ export default function ({ color = [1, 1, 1], coords, edgeForm = {}, opacity = 1 edgeForm.color ??= [0, 0, 0]; // Differently from polyhedrons, polygons use a Mesh and a material - // with "wirefram: true". This is slower than LineSegments, but + // with "wireframe: true". This is slower than LineSegments, but // creating a new BufferGeometry is also slow and uses more RAM // (LineSegments don't support indexed BufferGeometries). group.add(new Mesh( diff --git a/src/primitives/uniformPolyhedron.js b/src/primitives/uniformPolyhedron.js index f8db92df..64f1cd04 100644 --- a/src/primitives/uniformPolyhedron.js +++ b/src/primitives/uniformPolyhedron.js @@ -483,7 +483,7 @@ export default function ({ color = [1, 1, 1], coords, edgeForm = {}, edgeLength group.add(polyhedrons); - // The polyhedrons' edges are basicaly the same as the cylinders' ones. + // The polyhedrons' edges are basically the same as the cylinders' ones. const edgesGeometry = new InstancedBufferGeometry(); diff --git a/vendors/earcut.js b/vendors/earcut.js index c92a57b8..095424b6 100644 --- a/vendors/earcut.js +++ b/vendors/earcut.js @@ -175,7 +175,7 @@ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) { // check if a diagonal between two polygon nodes is valid (lies in polygon interior) function isValidDiagonal(a, b) { - return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && // dones't intersect other edges + return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && // doesn't intersect other edges (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && // locally visible (area(a.prev, a, b.prev) || area(a, b.prev, b)) || // does not create opposite-facing sectors equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0); // special zero-length case