remove cell doc
This commit is contained in:
51
cbuf.h
Normal file
51
cbuf.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef CIRCBUF_H
|
||||
#define CIRCBUF_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static inline unsigned int powof2(unsigned int x)
|
||||
{
|
||||
x = x-1;
|
||||
x |= (x >> 1);
|
||||
x |= (x >> 2);
|
||||
x |= (x >> 4);
|
||||
x |= (x >> 8);
|
||||
x |= (x >> 16);
|
||||
return x+1;
|
||||
}
|
||||
|
||||
struct rheader
|
||||
{
|
||||
unsigned int read;
|
||||
unsigned int write;
|
||||
int len;
|
||||
};
|
||||
|
||||
#define ringheader(r) ((struct rheader *)r-1)
|
||||
|
||||
static inline void *ringmake(void *ring, size_t elemsize, unsigned int n)
|
||||
{
|
||||
n = powof2(n);
|
||||
if (ring) {
|
||||
struct rheader *h = ringheader(ring);
|
||||
if (n <= h->len) return h+1;
|
||||
h = realloc(h, elemsize*n+sizeof(struct rheader));
|
||||
return h+1;
|
||||
}
|
||||
|
||||
struct rheader *h = malloc(elemsize*n+sizeof(struct rheader));
|
||||
h->len = n; h->read = 0; h->write = 0;
|
||||
return h+1;
|
||||
}
|
||||
|
||||
#define ringnew(r,n) (r = ringmake(r, sizeof(*r),n))
|
||||
#define ringfree(r) ((r) ? free(ringheader(r)) : 0)
|
||||
#define ringmask(r,v) (v & (ringheader(r)->len-1))
|
||||
#define ringpush(r,v) (r[ringmask(r,ringheader(r)->write++)] = v)
|
||||
#define ringshift(r) (r[ringmask(r,ringheader(r)->read++)])
|
||||
#define ringsize(r) ((r) ? ringheader(r)->write - ringheader(r)->read : 0)
|
||||
#define ringfull(r) ((r) ? ringsize(r) == ringheader(r)->len : 0)
|
||||
#define ringempty(r) ((r) ? ringheader(r)->read == ringheader(r)->write : 0)
|
||||
|
||||
#endif
|
||||
248
geometry.cm
248
geometry.cm
@@ -1,248 +0,0 @@
|
||||
var geometry = this
|
||||
geometry[cell.DOC] = `
|
||||
A collection of geometry-related functions for circles, spheres, boxes, polygons,
|
||||
and rectangle utilities. Some functionality is implemented in C and exposed here.
|
||||
`
|
||||
|
||||
var math = use('math')
|
||||
|
||||
geometry.box = {}
|
||||
geometry.box[cell.DOC] = `
|
||||
An object for box-related operations. Overridden later by a function definition, so
|
||||
its direct usage is overshadowed. Contains:
|
||||
- points(ll, ur): Return an array of four 2D points for a box from ll (lower-left) to ur (upper-right).
|
||||
`
|
||||
|
||||
geometry.box.points = function (ll, ur) {
|
||||
return [ll, ll.add([ur.x - ll.x, 0]), ur, ll.add([0, ur.y - ll.y])]
|
||||
}
|
||||
geometry.box.points[cell.DOC] = `
|
||||
:param ll: Lower-left coordinate as a 2D vector (x,y).
|
||||
:param ur: Upper-right coordinate as a 2D vector (x,y).
|
||||
:return: An array of four points forming the corners of the box in order [ll, lower-right, ur, upper-left].
|
||||
Compute the four corners of a box given lower-left and upper-right corners.
|
||||
`
|
||||
|
||||
geometry.sphere = {}
|
||||
geometry.sphere[cell.DOC] = `
|
||||
Sphere-related geometry functions:
|
||||
- volume(r): Return the volume of a sphere with radius r.
|
||||
- random(r, theta, phi): Return a random point on or inside a sphere.
|
||||
`
|
||||
|
||||
geometry.circle = {}
|
||||
geometry.circle[cell.DOC] = `
|
||||
Circle-related geometry functions:
|
||||
- area(r): Return the area of a circle with radius r.
|
||||
- random(r, theta): Return a random 2D point on a circle; uses sphere.random internally and extracts x,z.
|
||||
`
|
||||
|
||||
geometry.sphere.volume = function (r) {
|
||||
return (Math.pi * r * r * r * 4) / 3
|
||||
}
|
||||
geometry.sphere.volume[cell.DOC] = `
|
||||
:param r: The sphere radius.
|
||||
:return: The volume of the sphere, calculated as (4/3) * pi * r^3.
|
||||
`
|
||||
|
||||
geometry.sphere.random = function (r, theta = [0, 1], phi = [-0.5, 0.5]) {
|
||||
if (typeof r == "number") r = [r, r]
|
||||
if (typeof theta == "number") theta = [theta, theta]
|
||||
if (typeof phi == "number") phi = [phi, phi]
|
||||
|
||||
var ra = Math.random_range(r[0], r[1])
|
||||
var ta = Math.turn2rad(Math.random_range(theta[0], theta[1]))
|
||||
var pa = Math.turn2rad(Math.random_range(phi[0], phi[1]))
|
||||
return [ra * Math.sin(ta) * Math.cos(pa), ra * Math.sin(ta) * Math.sin(pa), ra * Math.cos(ta)]
|
||||
}
|
||||
geometry.sphere.random[cell.DOC] = `
|
||||
:param r: A single number (radius) or a 2-element array [minRadius, maxRadius].
|
||||
:param theta: A single number or 2-element array defining the range in turns for the theta angle, default [0,1].
|
||||
:param phi: A single number or 2-element array defining the range in turns for the phi angle, default [-0.5,0.5].
|
||||
:return: A 3D point (x,y,z) randomly placed within a sphere.
|
||||
Generate a random point inside a sphere of variable radius, distributing angles in the specified ranges.
|
||||
`
|
||||
|
||||
geometry.circle.area = function (r) {
|
||||
return Math.pi * r * r
|
||||
}
|
||||
geometry.circle.area[cell.DOC] = `
|
||||
:param r: Radius of the circle.
|
||||
:return: The area, pi * r^2.
|
||||
`
|
||||
|
||||
geometry.circle.random = function (r, theta) {
|
||||
return geometry.sphere.random(r, theta).xz
|
||||
}
|
||||
geometry.circle.random[cell.DOC] = `
|
||||
:param r: A radius or [minRadius, maxRadius].
|
||||
:param theta: Angle range in turns (single number or [min,max]).
|
||||
:return: A 2D point (x,z) in the circle, using the sphere random generator and ignoring y.
|
||||
`
|
||||
|
||||
geometry.box = function (w, h) {
|
||||
w /= 2
|
||||
h /= 2
|
||||
var points = [
|
||||
[w, h],
|
||||
[-w, h],
|
||||
[-w, -h],
|
||||
[w, -h],
|
||||
]
|
||||
return points
|
||||
}
|
||||
geometry.box[cell.DOC] = `
|
||||
:param w: The width of the box.
|
||||
:param h: The height of the box.
|
||||
:return: An array of four 2D points representing the corners of a rectangle centered at [0,0].
|
||||
Construct a box centered at the origin with the given width and height. This overrides the box object above.
|
||||
`
|
||||
|
||||
geometry.ngon = function (radius, n) {
|
||||
return geometry.arc(radius, 360, n)
|
||||
}
|
||||
geometry.ngon[cell.DOC] = `
|
||||
:param radius: The radius of the n-gon from center to each vertex.
|
||||
:param n: Number of sides/vertices.
|
||||
:return: An array of 2D points forming a regular n-gon.
|
||||
Generates a regular n-gon by calling geometry.arc with full 360 degrees.
|
||||
`
|
||||
|
||||
geometry.arc = function (radius, angle, n, start = 0) {
|
||||
start = Math.deg2rad(start)
|
||||
if (angle >= 360) angle = 360
|
||||
if (n <= 1) return []
|
||||
var points = []
|
||||
angle = Math.deg2rad(angle)
|
||||
var arclen = angle / n
|
||||
for (var i = 0; i < n; i++) points.push(math.rotate([radius, 0], start + arclen * i))
|
||||
return points
|
||||
}
|
||||
geometry.arc[cell.DOC] = `
|
||||
:param radius: The distance from center to the arc points.
|
||||
:param angle: The total angle (in degrees) over which points are generated, capped at 360.
|
||||
:param n: Number of segments (if <=1, empty array is returned).
|
||||
:param start: Starting angle (in degrees), default 0.
|
||||
:return: An array of 2D points along the arc.
|
||||
Generate an arc (or partial circle) of n points, each angle spread equally over 'angle' degrees from 'start'.
|
||||
`
|
||||
|
||||
geometry.circle.points = function (radius, n) {
|
||||
if (n <= 1) return []
|
||||
return geometry.arc(radius, 360, n)
|
||||
}
|
||||
geometry.circle.points[cell.DOC] = `
|
||||
:param radius: The circle's radius.
|
||||
:param n: Number of points around the circle.
|
||||
:return: An array of 2D points equally spaced around a full 360-degree circle.
|
||||
Shortcut for geometry.arc(radius, 360, n).
|
||||
`
|
||||
|
||||
geometry.corners2points = function (ll, ur) {
|
||||
return [ll, ll.add([ur.x, 0]), ur, ll.add([0, ur.y])]
|
||||
}
|
||||
geometry.corners2points[cell.DOC] = `
|
||||
:param ll: Lower-left 2D coordinate.
|
||||
:param ur: Upper-right 2D coordinate (relative offset in x,y).
|
||||
:return: A four-point array of corners [ll, lower-right, upper-right, upper-left].
|
||||
Similar to box.points, but calculates differently.
|
||||
`
|
||||
|
||||
geometry.sortpointsccw = function (points) {
|
||||
var cm = points2cm(points)
|
||||
var cmpoints = points.map(function (x) { return x.sub(cm) })
|
||||
var ccw = cmpoints.sort(function (a, b) {
|
||||
var aatan = Math.atan2(a.y, a.x)
|
||||
var batan = Math.atan2(b.y, b.x)
|
||||
return aatan - batan
|
||||
})
|
||||
return ccw.map(function (x) { return x.add(cm) })
|
||||
}
|
||||
geometry.sortpointsccw[cell.DOC] = `
|
||||
:param points: An array of 2D points.
|
||||
:return: A new array of the same points, sorted counterclockwise around their centroid.
|
||||
Sort an array of points in CCW order based on their angles from the centroid.
|
||||
`
|
||||
|
||||
function points2cm(pts) {
|
||||
var x = 0
|
||||
var y = 0
|
||||
var n = pts.length
|
||||
pts.forEach(function (p) {
|
||||
x += p[0]
|
||||
y += p[1]
|
||||
})
|
||||
return [x / n, y / n]
|
||||
}
|
||||
|
||||
geometry.points2cm = function(points) {
|
||||
var x = 0
|
||||
var y = 0
|
||||
var n = points.length
|
||||
points.forEach(function (p) {
|
||||
x += p[0]
|
||||
y += p[1]
|
||||
})
|
||||
return [x / n, y / n]
|
||||
}
|
||||
geometry.points2cm[cell.DOC] = `
|
||||
:param points: An array of 2D points.
|
||||
:return: The centroid (average x,y) of the given points.
|
||||
`
|
||||
|
||||
geometry.rect_intersection[cell.DOC] = `
|
||||
:param a: The first rectangle as {x, y, w, h}.
|
||||
:param b: The second rectangle as {x, y, w, h}.
|
||||
:return: A rectangle that is the intersection of the two. May have zero width/height if no overlap.
|
||||
Return the intersection of two rectangles. The result may be empty if no intersection.
|
||||
`
|
||||
|
||||
geometry.rect_intersects[cell.DOC] = `
|
||||
:param a: Rectangle {x,y,w,h}.
|
||||
:param b: Rectangle {x,y,w,h}.
|
||||
:return: A boolean indicating whether the two rectangles overlap.
|
||||
`
|
||||
|
||||
geometry.rect_expand[cell.DOC] = `
|
||||
:param a: Rectangle {x,y,w,h}.
|
||||
:param b: Rectangle {x,y,w,h}.
|
||||
:return: A new rectangle that covers the bounds of both input rectangles.
|
||||
Merge or combine two rectangles, returning their bounding rectangle.
|
||||
`
|
||||
|
||||
geometry.rect_inside[cell.DOC] = `
|
||||
:param inner: A rectangle to test.
|
||||
:param outer: A rectangle that may contain 'inner'.
|
||||
:return: True if 'inner' is completely inside 'outer', otherwise false.
|
||||
`
|
||||
|
||||
geometry.rect_random[cell.DOC] = `
|
||||
:param rect: A rectangle {x,y,w,h}.
|
||||
:return: A random point within the rectangle (uniform distribution).
|
||||
`
|
||||
|
||||
geometry.cwh2rect[cell.DOC] = `
|
||||
:param center: A 2D point [cx, cy].
|
||||
:param wh: A 2D size [width, height].
|
||||
:return: A rectangle {x, y, w, h} with x,y set to center and w,h set to the given size.
|
||||
Helper: convert a center point and width/height vector to a rect object.
|
||||
`
|
||||
|
||||
geometry.rect_point_inside[cell.DOC] = `
|
||||
:param rect: A rectangle {x,y,w,h}.
|
||||
:param point: A 2D point [px, py].
|
||||
:return: True if the point lies inside the rectangle, otherwise false.
|
||||
`
|
||||
|
||||
geometry.rect_pos[cell.DOC] = `
|
||||
:param rect: A rectangle {x,y,w,h}.
|
||||
:return: A 2D vector [x,y] giving the rectangle's position.
|
||||
`
|
||||
|
||||
geometry.rect_move[cell.DOC] = `
|
||||
:param rect: A rectangle {x,y,w,h}.
|
||||
:param offset: A 2D vector to add to the rectangle's position.
|
||||
:return: A new rectangle with updated x,y offset.
|
||||
`
|
||||
|
||||
return geometry
|
||||
12
mersenne.c
12
mersenne.c
@@ -93,9 +93,8 @@ static const JSCFunctionListEntry js_mersenne_funcs[] = {
|
||||
JS_CFUNC_DEF("get", 0, js_mersenne_get),
|
||||
};
|
||||
|
||||
/* Factory Function */
|
||||
static JSValue js_mersenne_use_call(JSContext *js, JSValueConst func_obj,
|
||||
JSValueConst this_val, int argc, JSValueConst *argv)
|
||||
/* Factory Function (constructor-style, see js_blob_constructor in qjs_blob.c) */
|
||||
static JSValue js_mersenne_use_call(JSContext *js, JSValueConst new_target, int argc, JSValueConst *argv)
|
||||
{
|
||||
uint64_t seed;
|
||||
|
||||
@@ -134,8 +133,7 @@ static JSValue js_mersenne_use_call(JSContext *js, JSValueConst func_obj,
|
||||
return obj;
|
||||
}
|
||||
|
||||
JSValue js_mersenne_use(JSContext *js)
|
||||
{
|
||||
CELL_USE_INIT(
|
||||
JS_NewClassID(&js_mersenne_class_id);
|
||||
JS_NewClass(JS_GetRuntime(js), js_mersenne_class_id, &js_mersenne_class);
|
||||
|
||||
@@ -144,5 +142,5 @@ JSValue js_mersenne_use(JSContext *js)
|
||||
JS_SetClassProto(js, js_mersenne_class_id, proto);
|
||||
|
||||
// Return the factory function
|
||||
return JS_NewCFunction2(js, js_mersenne_use_call, "mersenne", 1, JS_CFUNC_generic, 0);
|
||||
}
|
||||
return JS_NewCFunction2(js, js_mersenne_use_call, "mersenne", 1, JS_CFUNC_constructor, 0);
|
||||
)
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
#include "cell.h"
|
||||
#include "stb_ds.h"
|
||||
#include "qjs_actor.h"
|
||||
#include "qjs_wota.h"
|
||||
#include "qjs_imgui.h"
|
||||
#include "wota.h"
|
||||
#include "qjs_wota.h"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
|
||||
15
resources.cm
15
resources.cm
@@ -119,14 +119,6 @@ Resources.getAllFiles = function(dir = "") {
|
||||
}
|
||||
return results
|
||||
}
|
||||
Resources.getAllFiles[cell.DOC] = `
|
||||
Return a list of recognized files in the given directory that are not matched by
|
||||
.prosperonignore, skipping directories. Recognized extensions include scripts,
|
||||
images, sounds, fonts, and libs.
|
||||
|
||||
:param dir: The directory to search.
|
||||
:return: An array of recognized file paths.
|
||||
`
|
||||
|
||||
// Categorize files by resource type
|
||||
Resources.gatherStats = function(filePaths) {
|
||||
@@ -155,12 +147,5 @@ Resources.gatherStats = function(filePaths) {
|
||||
}
|
||||
return stats
|
||||
}
|
||||
Resources.gatherStats[cell.DOC] = `
|
||||
Analyze a list of recognized files and categorize them by scripts, images, sounds,
|
||||
fonts, libs, or other. Return a stats object with these counts and the total.
|
||||
|
||||
:param filePaths: An array of file paths to analyze.
|
||||
:return: { scripts, images, sounds, fonts, lib, other, total }
|
||||
`
|
||||
|
||||
return Resources
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
var spline = this
|
||||
|
||||
spline.catmull[cell.DOC] = "Perform Catmull-Rom spline sampling on an array of 2D points, returning an array of samples."
|
||||
spline.bezier[cell.DOC] = "Perform a Bezier spline (or catmull) sampling on 2D points, returning an array of sampled points."
|
||||
|
||||
return spline
|
||||
Reference in New Issue
Block a user