Skip to content

Commit fce18cb

Browse files
signup button added to docs, link to discord on homepage, new docs on base categories - math, vectors, points
1 parent ce85eee commit fce18cb

File tree

14 files changed

+465
-4
lines changed

14 files changed

+465
-4
lines changed

docs/docusaurus.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ const config: Config = {
113113
className: "navbar__button--support", // Custom class for styling
114114
"aria-label": "Support the Project Mission", // For accessibility
115115
},
116+
{
117+
href: "https://bitbybit.dev/auth/sign-up",
118+
label: "Sign Up",
119+
position: "right",
120+
className: "navbar__button--support",
121+
"aria-label": "Sign Up to Bitbybit.dev",
122+
},
116123
{
117124
href: "https://github.com/bitbybit-dev/bitbybit",
118125
label: "GitHub",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"label": "Base",
3+
"position": 1,
4+
"link": {
5+
"type": "generated-index",
6+
"title": "Base Algorithms in Bitbybit",
7+
"description": "Base algorithms in Bitbybit provide foundational algorithms & object types, such as vectors, matrixes, points, lines, polylines, triangles and meshes. Learn how to use these algorithms to create complex shapes, grids and designs.",
8+
"slug": "/code/common/base"
9+
}
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
sidebar_position: 1
3+
title: Intro
4+
sidebar_label: Base Intro
5+
---
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"label": "Math",
3+
"position": 1,
4+
"link": {
5+
"type": "generated-index",
6+
"title": "Math Algorithms in Bitbybit",
7+
"description": "Introduction to math algorithms in Bitbybit.",
8+
"slug": "/code/common/base/math"
9+
}
10+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
sidebar_position: 2
3+
title: Math in Bitbybit
4+
sidebar_label: Math in Bitbybit
5+
description: An overview of the Math class in Bitbybit, providing tools for common mathematical operations, number generation, and easing functions.
6+
tags: [code, math]
7+
---
8+
9+
<img
10+
src="https://s.bitbybit.dev/assets/icons/white/math-icon.svg"
11+
alt="Vector category icon"
12+
title="Vector category icon"
13+
width="100" />
14+
15+
[View Full Source & Details on GitHub](https://github.com/bitbybit-dev/bitbybit/blob/master/packages/dev/base/lib/api/services/math.ts)
16+
17+
The `MathBitByBit` class (often referred to as `Math` in examples) is your go-to utility for a variety of numerical operations, from basic arithmetic to more specialized functions like easing and number generation.
18+
19+
Many of its functions are convenient wrappers around standard JavaScript `Math` object methods, making them readily available within the Bitbybit ecosystem.
20+
21+
## Core Capabilities of the Math Class
22+
23+
Here's a breakdown of what the `Math` class offers. For precise input parameters, specific operator names (for `twoNrOperation` and `oneNrOperation`), and detailed behavior, please consult the [full Math API documentation](https://docs.bitbybit.dev/classes/Bit.MathBitByBit.html) or the GitHub source linked above.
24+
25+
### 1. Basic Arithmetic & Number Operations
26+
27+
These are the everyday math functions:
28+
* **Fundamental Operations:** Add (`add`), subtract (`subtract`), multiply (`multiply`), divide (`divide`), and raise to a power (`power`). There's also a general `twoNrOperation()` that can perform these based on an operator type.
29+
* **Single Number Functions:**
30+
* Get the square root (`sqrt`), absolute value (`abs`), or negate a number (`negate`).
31+
* Rounding: Round to the nearest integer (`round`), round down (`floor`), or round up (`ceil`). You can also round to a specific number of decimal places (`roundToDecimals()`).
32+
* Logarithms: Natural log (`ln`), base-10 log (`log10`).
33+
* Exponentials: `e` to the power of x (`exp`), 10 to the power of x (`tenPow`).
34+
* Modulus: Find the remainder of a division (`modulus()`).
35+
* **Trigonometry:** Standard trigonometric functions like `sin()`, `cos()`, `tan()`, and their inverses (`asin()`, `acos()`, `atan()`).
36+
* **Angle Conversion:** Convert between degrees and radians (`degToRad()`, `radToDeg()`).
37+
* A general `oneNrOperation()` method can perform many of these single-number operations by specifying an operator type.
38+
39+
### 2. Number Generation & Constants
40+
41+
Creating numbers:
42+
* **Specific Number:** Simply return a provided number (`number()`). This can be useful in visual programming environments.
43+
* **Random Numbers:**
44+
* Generate a random number between 0 (inclusive) and 1 (exclusive) (`random()`).
45+
* Generate a random number within a specified range (low to high) (`randomNumber()`).
46+
* Generate a list of random numbers within a range (`randomNumbers()`).
47+
* **Constants:** Get the value of Pi (`pi()`).
48+
49+
### 3. Number Manipulation & Easing
50+
51+
More advanced ways to work with numbers:
52+
* **Remapping (`remap()`):** Take a number from one range and scale it proportionally to fit into a new range. For example, mapping a value from `0-100` to `0-1`.
53+
* **Easing Functions (`ease()`):** This is a powerful feature for creating smooth transitions or non-linear progressions.
54+
* You provide an input value `x` (typically from 0 to 1), a target output range (`min` and `max`), and an `ease` type (e.g., `easeInSine`, `easeOutQuad`, `easeInOutElastic`).
55+
* The function transforms `x` according to the chosen easing curve and then maps it to your desired `min`-`max` range.
56+
* This is extremely useful for animations, procedural modeling where you want non-uniform distributions, and controlling behavior over time. The class includes a comprehensive set of standard easing functions (like Sine, Quad, Cubic, Expo, Bounce, etc., with In, Out, and InOut variations).
57+
* **Fixed Decimal Representation (`toFixed()`):** Convert a number to a string, rounded to a specified number of decimal places.
58+
59+
## How to Use
60+
61+
Most methods in the `Math` class take an "inputs" object containing the number(s) and any necessary parameters.
62+
63+
```typescript
64+
// Conceptual TypeScript example for adding two numbers
65+
const num1 = 10;
66+
const num2 = 5.5;
67+
68+
const sum = bitbybit.math.add({ first: num1, second: num2 });
69+
// sum would be 15.5
70+
71+
// Conceptual example for easing
72+
const easedValue = bitbybit.math.ease({
73+
x: 0.5, // Halfway through the normalized input
74+
min: 0,
75+
max: 100,
76+
ease: Bit.Inputs.Math.easeEnum.easeOutQuad // Example ease type
77+
});
78+
// easedValue would be 75, because easeOutQuad at 0.5 is 0.75,
79+
// and 0.75 remapped from 0-1 to 0-100 is 75.
80+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"label": "Point",
3+
"position": 4,
4+
"link": {
5+
"type": "generated-index",
6+
"title": "Point Algorithms in Bitbybit",
7+
"description": "Introduction to point algorithms in Bitbybit, including point creation, manipulation and analysis. Learn how to use these algorithms to work with points in 2D and 3D space.",
8+
"slug": "/code/common/base/point"
9+
}
10+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
sidebar_position: 1
3+
title: Points in Bitbybit
4+
sidebar_label: Points in Bitbybit
5+
description: Learn about the Point class in Bitbybit. Understand how to create, transform, and analyze points in your 3D projects.
6+
tags: [code, point]
7+
---
8+
9+
[View Full Source & Details on GitHub](https://github.com/bitbybit-dev/bitbybit/blob/master/packages/dev/base/lib/api/services/point.ts)
10+
11+
<img
12+
src="https://s.bitbybit.dev/assets/icons/white/point-icon.svg"
13+
alt="Vector category icon"
14+
title="Vector category icon"
15+
width="100" />
16+
17+
The `Point` class in Bitbybit provides essential tools for working with points in 3D space.
18+
19+
**What is a Point in Bitbybit?**
20+
21+
Just like a `Vector`, a `Point` in Bitbybit is fundamentally a simple **array of three numbers: `[x, y, z]`**.
22+
* This means you can often use a `Point` where a `Vector` is expected, and vice-versa, as they share the same underlying structure.
23+
* When working in 2D, the Z-coordinate is typically just set to `0`, so a 2D point looks like `[x, y, 0]`.
24+
25+
This simplicity makes it easy to define locations and work with geometric data.
26+
27+
## Core Capabilities of the Point Class
28+
29+
The `Point` class is all about defining locations and manipulating them. Here's an overview of what it helps you do. For the nitty-gritty details of each function, including specific input parameters, please check the [full Point API documentation](https://docs.bitbybit.dev/classes/Bit.Point-1.html) or the GitHub source linked above.
30+
31+
### 1. Creating Points & Point Patterns
32+
33+
Need to define a point or a collection of points?
34+
* **Basic Points:** Create individual 3D points from X, Y, and Z coordinates (`pointXYZ()`) or 2D points from X and Y (`pointXY()`, which creates `[x, y, 0]`).
35+
* **Pattern Generation:**
36+
* `spiral()`: Generate points arranged in a spiral pattern.
37+
* `hexGrid()`: Create points that form the centers of a hexagonal grid.
38+
* `hexGridScaledToFit()`: A more advanced hexagonal grid generator that can scale the grid to fit specific dimensions and provides both center points and hexagon vertices.
39+
* **Duplication:**
40+
* `multiplyPoint()`: Create multiple copies of the same point.
41+
42+
### 2. Transforming Points (Moving, Rotating, Scaling)
43+
44+
This is a major strength of the `Point` class. You can easily change the position, orientation, or size of points:
45+
* **General Transformations:** Apply complex transformations (like those created by the `Transforms` class) to a single point (`transformPoint()`) or multiple points (`transformPoints()`). You can even apply a unique transformation to each point in a list (`transformsForPoints()`).
46+
* **Translation (Moving):**
47+
* Move points by a single vector (`translatePoints()`, `translateXYZPoints()`).
48+
* Move each point in a list by its own unique translation vector (`translatePointsWithVectors()`).
49+
* **Scaling (Resizing):**
50+
* Scale points around a center point using X, Y, Z scale factors (`scalePointsCenterXYZ()`).
51+
* **Stretching:**
52+
* Stretch points along a specific direction from a center point (`stretchPointsDirFromCenter()`).
53+
* **Rotation:**
54+
* Rotate points around an axis that passes through a center point (`rotatePointsCenterAxis()`).
55+
56+
### 3. Analyzing and Measuring Points
57+
58+
Get information about your points and their relationships:
59+
* **Coordinates:** Get the individual X, Y, or Z coordinate of a point (`getX()`, `getY()`, `getZ()`).
60+
* **Distance:**
61+
* Calculate the distance between two specific points (`distance()`).
62+
* Find the distances from one point to many other points (`distancesToPoints()`).
63+
* **Closest Point:**
64+
* From a reference point, find the closest point in a list of other points (`closestPointFromPoints()`).
65+
* You can also get the *distance* to this closest point (`closestPointFromPointsDistance()`) or its *index* in the list (`closestPointFromPointsIndex()`).
66+
* **Bounding Box:** Find the smallest box that encloses a set of points (`boundingBoxOfPoints()`). This gives you the minimum and maximum extent, center, and dimensions.
67+
* **Average Point:** Calculate the average position of a group of points (`averagePoint()`).
68+
* **Equality Check:** Determine if two points are in (almost) the same location, within a small tolerance (`twoPointsAlmostEqual()`).
69+
70+
### 4. Calculating Normals and Fillets (More Advanced Geometry)
71+
72+
* **Normal Vector:** Calculate a normal vector (a vector perpendicular to a surface) from three points that define a plane (`normalFromThreePoints()`).
73+
* **Fillet Radius Calculation:** Functions to help determine the maximum possible radius for a smooth, rounded corner (fillet) given points that define the corner (`maxFilletRadius()`, `maxFilletRadiusHalfLine()`, `maxFilletsHalfLine()`, `safestPointsMaxFilletHalfLine()`). These are useful for advanced modeling tasks like creating smooth transitions between edges.
74+
75+
### 5. Utility and Cleaning
76+
77+
* **Removing Duplicates:** Clean up lists of points by removing consecutive identical points, considering a tolerance (`removeConsecutiveDuplicates()`).
78+
* **Sorting:** Sort a list of points, primarily by X, then Y, then Z coordinates (`sortPoints()`).
79+
80+
## How to Use
81+
82+
Interacting with `Point` class methods typically involves providing an "inputs" object that contains the necessary data, like the point(s) themselves and any parameters for the operation.
83+
84+
```typescript
85+
// Conceptual TypeScript example for translating a point
86+
const myPoint = [10, 20, 0];
87+
const translationVector = [5, 0, 5];
88+
89+
const movedPoint = bitbybit.point.translatePoints({
90+
points: [myPoint],
91+
translation: translationVector
92+
});
93+
// movedPoint would be [[15, 20, 5]]
94+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"label": "Vector",
3+
"position": 3,
4+
"link": {
5+
"type": "generated-index",
6+
"title": "Vector Algorithms in Bitbybit",
7+
"description": "Introduction to vector algorithms in Bitbybit, including vector addition, subtraction and other operations. Learn how to use these algorithms to manipulate and analyze vector data.",
8+
"slug": "/code/common/base/vector"
9+
}
10+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
sidebar_position: 1
3+
title: Vectors in Bitbybit
4+
sidebar_label: Vectors in Bitbybit
5+
description: An overview of the Vector class in Bitbybit, explaining its core functionalities for vector math in simple terms.
6+
tags: [code, vector]
7+
---
8+
9+
import Tabs from '@theme/Tabs';
10+
import TabItem from '@theme/TabItem';
11+
12+
<img
13+
src="https://s.bitbybit.dev/assets/icons/white/vector-icon.svg"
14+
alt="Vector category icon"
15+
title="Vector category icon"
16+
width="100" />
17+
18+
The `Vector` class in Bitbybit provides a comprehensive suite of tools for performing vector mathematics. In Bitbybit, a **vector is fundamentally represented as an array of numbers**. For 3D operations, this typically takes the form `[x, y, z]`, where `y` is considered the 'up' direction by convention in many Bitbybit contexts. This simple array representation means that vectors can often be used interchangeably with points, which also follow the `[x, y, z]` structure.
19+
20+
[Full Source on GitHub](https://github.com/bitbybit-dev/bitbybit/blob/master/packages/dev/base/lib/api/services/vector.ts)
21+
22+
23+
The `Vector` class in Bitbybit is your toolkit for working with vectors and points in your 3D designs.
24+
25+
**What is a Vector in Bitbybit?**
26+
27+
At its heart, a vector (or a point) in Bitbybit is just a simple **array of numbers**.
28+
* For 2D, it might look like `[x, y]`.
29+
* For 3D, it's typically `[x, y, z]`. In many Bitbybit contexts, `y` represents the "up" direction.
30+
31+
This straightforward representation makes it easy to pass vector data around and use it in various calculations.
32+
33+
## What Can You Do With the Vector Class?
34+
35+
The `Vector` class helps you perform a wide range of operations. Here's a look at the main categories of features it supports. For the exact input parameters, default values, and more advanced functions, please consult the detailed [Vector API Documentation](https://docs.bitbybit.dev/classes/Bit.Vector-1.html) (or the GitHub source linked above).
36+
37+
### 1. Creating Vectors and Number Sequences
38+
39+
Need to make a new vector or a list of numbers?
40+
* **Specific Vectors:** Create 2D (`[x,y]`) or 3D (`[x,y,z]`) vectors directly from their components (e.g., `vectorXYZ()`, `vectorXY()`).
41+
* **Number Ranges:** Generate sequences of numbers.
42+
* `range()`: Get a simple list of integers (e.g., `[0, 1, 2, 3, 4]`).
43+
* `span()`: Create evenly spaced numbers between a minimum and maximum (e.g., `[0, 0.5, 1.0, 1.5, 2.0]`).
44+
* `spanLinearItems()`: Like `span()`, but you specify the total number of items you want.
45+
* `spanEaseItems()`: Create a sequence where the spacing follows an "easing" curve (e.g., numbers bunch up at the start and spread out at the end). This is great for animations or non-uniform distributions.
46+
47+
### 2. Basic Vector Math (The Essentials)
48+
49+
These are the bread-and-butter operations:
50+
* **Addition & Subtraction:** Add two vectors (`add()`) or subtract one from another (`sub()`). You can also sum up a whole list of vectors (`addAll()`).
51+
* **Scaling (Multiplication/Division):** Make a vector longer or shorter by multiplying (`mul()`) or dividing (`div()`) its components by a single number (a scalar).
52+
* **Dot Product (`dot()`):** A fundamental operation that tells you about the relationship between two vectors' directions.
53+
* **Cross Product (`cross()`):** For 3D vectors, this gives you a new vector that's perpendicular to the two original vectors. Essential for finding normals or rotational axes.
54+
* **Negation (`neg()`):** Flip the direction of a vector.
55+
56+
### 3. Measuring and Analyzing Vectors
57+
58+
Understand your vectors' properties:
59+
* **Length (Magnitude/Norm):** Find out how long a vector is (`length()`, `norm()`). There are also versions for squared length (`lengthSq()`, `normSquared()`), which can be faster if you only need to compare lengths.
60+
* **Normalization (`normalized()`):** Create a "unit vector" – a vector with a length of 1 that points in the same direction as the original. Very useful for representing directions.
61+
* **Distance:** Calculate the distance between two points (which are just vectors) (`dist()`, `distSquared()`).
62+
* **Angles:**
63+
* Measure the angle between two vectors (`angleBetween()`).
64+
* Get signed angles or positive angles relative to a reference direction (`signedAngleBetween()`, `positiveAngleBetween()`, `angleBetweenNormalized2d()`). This helps determine orientation (e.g., clockwise vs. counter-clockwise).
65+
* **Interpolation (`lerp()`):** Find a point (vector) that's part-way between two other points, based on a fraction.
66+
67+
### 4. Validating and Checking Vectors
68+
69+
Perform checks on your vector data:
70+
* **Are Vectors the Same? (`vectorsTheSame()`):** Check if two vectors are equal, within a small tolerance (important for floating-point numbers).
71+
* **Is it Zero? (`isZero()`):** See if a vector has zero length.
72+
* **Is it Finite? (`finite()`):** Check if all numbers in a vector are valid (not Infinity or NaN).
73+
74+
### 5. Working with Lists of Vectors
75+
76+
Manage collections of vectors:
77+
* **Removing Duplicates:** Clean up lists by removing identical vectors, either all duplicates (`removeAllDuplicateVectors()`) or only those that are next to each other (`removeConsecutiveDuplicateVectors()`).
78+
* **Finding Min/Max Values (`min()`, `max()`):** Get the smallest or largest number within a vector's components.
79+
* **Domain (`domain()`):** For an ordered list of numbers, find the difference between the last and first values.
80+
81+
### 6. Utility Functions
82+
83+
* **Point on Ray (`onRay()`):** Given a starting point, a direction vector, and a distance, find the coordinates of the point along that ray.
84+
* **Boolean List Check (`all()`):** Check if a list of boolean values are all `true`.
85+
86+
## How to Use
87+
88+
Typically, you'll interact with these methods by providing an "inputs" object. For example, to add two vectors:
89+
90+
```typescript
91+
// In TypeScript (conceptual)
92+
const vec1 = [1, 2, 3];
93+
const vec2 = [4, 5, 6];
94+
95+
const sumVector = bitbybit.vector.add({ first: vec1, second: vec2 });
96+
// sumVector will be [5, 7, 9]
97+
```

0 commit comments

Comments
 (0)