Skip to content

Commit

Permalink
basic functionality completed, going to refactor for better usability…
Browse files Browse the repository at this point in the history
…/functionality
  • Loading branch information
varphi-online committed Jul 23, 2024
1 parent 32c169e commit de107b3
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 79 deletions.
30 changes: 20 additions & 10 deletions graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ let canvas = {
canvas.object.style.width = canvas.width + "px";
canvas.object.height = canvas.height;
canvas.object.width = canvas.width;
cnv.font = "15px serif";
cnv.strokeStyle = "white";
cnv.lineWidth = 3;
cnv.textAlign = "center";
}
}
canvas.init();
Expand All @@ -47,7 +51,7 @@ const cnv = canvas.object.getContext("2d");
canvas.resetBitmap();
cnv.font = "15px serif";
cnv.strokeStyle = "white";
cnv.lineWidth = 4;
cnv.lineWidth = 3;
cnv.textAlign = "center";
let click = false;

Expand All @@ -72,6 +76,10 @@ let graph = {
this.zoom = 0;
this.screenTarget = [0, 0];
this.zoomLog = 1;
cnv.font = "15px serif";
cnv.strokeStyle = "white";
cnv.lineWidth = 3;
cnv.textAlign = "center";
},
updateBounds: function () {
let inverseZL = 1 / this.zoomLog;
Expand Down Expand Up @@ -125,7 +133,8 @@ CanvasRenderingContext2D.prototype.curve = function (h, r, f, c) { r = (typeof r
export async function render() {
let frameTime = new Date;
cnv.clearRect(0, 0, canvas.width, canvas.height);
let values = await wasm.squaredvals(graph.bounds, canvas.width, canvas.height, horizontal,vertical);
grid();
let values = await wasm.squaredvals(graph.bounds, canvas.width, canvas.height, horizontal,vertical,true);

//drawCurve(cnv,pts);
let points = [];
Expand All @@ -135,18 +144,17 @@ export async function render() {
cnv.fillRect(points[i] - 1, points[i + 1] - 1, 3, 3);
}
}

if (contCheck) {
console.log(points);
cnv.strokeStyle = "black";
cnv.strokeStyle = "red";
cnv.beginPath();
//cnv.moveTo(points[0], points[1]);
cnv.curve(points);
//cnv.lineTo(points.at(-2), points.at(-1));
cnv.stroke()
cnv.strokeStyle = "white";
}
ft.innerText = ("Render time: " + (new Date - frameTime) + "ms\n Dots to render:" + Math.round(Math.sqrt(values.length * 1.8)) + "\nZoom: " + 0.5 / graph.zoomLog + "\nScale Factor x: " + graph.scaleFactor[0] + "\nScale Factor y: " + graph.scaleFactor[1] + "\nCanvas width: " + canvas.width + "\nCanvas height: " + canvas.height + "\nBounds: " + graph.bounds.map(val => Math.round(1000 * val) / 1000));
grid();

}

function gridline(int) {
Expand Down Expand Up @@ -181,6 +189,8 @@ function grid() {
// so we make a different amount of lines for each to eliminiate draw calls

let text;
let xAdd = horizontal.endsWith("i")? "i": "";
let yAdd = vertical.endsWith("i")? "i": "";

//Major X lines
for (let i = -7; i < 8; i++) {
Expand All @@ -195,13 +205,13 @@ function grid() {
text = xScale * i + superFloor(xScale, graph.screenTarget[0]);
text = precision(text) == 0 ? Math.round(text) : text;
cnv.strokeText(
text,
text+xAdd,
xpos[0],
Math.min(Math.max(xpos[1] + 18, 14), canvas.height - 8),
150,
);
cnv.fillText(
text,
text+xAdd,
xpos[0],
Math.min(Math.max(xpos[1] + 18, 14), canvas.height - 8),
150,
Expand Down Expand Up @@ -237,13 +247,13 @@ function grid() {
cnv.textAlign = "right";
}
cnv.strokeText(
text,
text+yAdd,
Math.min(Math.max(ypos[0] - 15, 10), canvas.width - 10),
ypos[1] + 4,
150,
);
cnv.fillText(
text,
text+yAdd,
Math.min(Math.max(ypos[0] - 15, 10), canvas.width - 10),
ypos[1] + 4,
150,
Expand Down
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ <h1>Graphing Calculator</h1>
<br>
<label for="vaxis">Vertical Axis:</label>
<select name="vaxis" id="vaxis">

<option value="o_r">Real Output</option>

<option value="i_r">Real Input</option>
<option value="o_i">Imaginary Output</option>
<option value="i_i">Imaginary Input</option>
</select>
<br>
<label for="cont"> Continuous Approximation</label>
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export async function scanner(input) {



export async function squaredvals(bounds,cw,ch,haxis,vaxis){
export async function squaredvals(bounds,cw,ch,haxis,vaxis,ssc){
await ensureWasmInit();
faster_call(...bounds,cw,ch,haxis,vaxis);
faster_call(...bounds,cw,ch,haxis,vaxis,ssc,0);
let a = new Float64Array(rustWasm.memory.buffer).slice(bufferPointer,bufferPointer+(2*(Number(get_resolution())**2)))
//console.log(a);
return(a);
Expand Down
26 changes: 17 additions & 9 deletions pkg/wgraphcal.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {string} input
* @returns {string}
*/
export function return_string(input: string): string;
/**
* @param {number} x1
* @param {number} x2
* @param {number} y1
Expand All @@ -14,8 +9,10 @@ export function return_string(input: string): string;
* @param {number} canvas_pixel_height
* @param {string} x_axis
* @param {string} y_axis
* @param {boolean} calculate_screensapce
* @param {number} slice
*/
export function faster_call(x1: number, x2: number, y1: number, y2: number, canvas_pixel_width: number, canvas_pixel_height: number, x_axis: string, y_axis: string): void;
export function faster_call(x1: number, x2: number, y1: number, y2: number, canvas_pixel_width: number, canvas_pixel_height: number, x_axis: string, y_axis: string, calculate_screensapce: boolean, slice: number): void;
/**
* @returns {number}
*/
Expand All @@ -24,18 +21,29 @@ export function get_buf_as_ptr(): number;
* @returns {bigint}
*/
export function get_resolution(): bigint;
/**
* @param {string} input
* @returns {string}
*/
export function str_to_lexemes(input: string): string;
/**
* @param {string} input
* @returns {string}
*/
export function return_string(input: string): string;

export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;

export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly return_string: (a: number, b: number, c: number) => void;
readonly faster_call: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
readonly faster_call: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
readonly get_buf_as_ptr: () => number;
readonly get_resolution: () => number;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly str_to_lexemes: (a: number, b: number, c: number) => void;
readonly return_string: (a: number, b: number, c: number) => void;
readonly __wbindgen_malloc: (a: number, b: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
}

Expand Down
88 changes: 56 additions & 32 deletions pkg/wgraphcal.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,41 @@ function passStringToWasm0(arg, malloc, realloc) {
WASM_VECTOR_LEN = offset;
return ptr;
}
/**
* @param {number} x1
* @param {number} x2
* @param {number} y1
* @param {number} y2
* @param {number} canvas_pixel_width
* @param {number} canvas_pixel_height
* @param {string} x_axis
* @param {string} y_axis
* @param {boolean} calculate_screensapce
* @param {number} slice
*/
export function faster_call(x1, x2, y1, y2, canvas_pixel_width, canvas_pixel_height, x_axis, y_axis, calculate_screensapce, slice) {
const ptr0 = passStringToWasm0(x_axis, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
const ptr1 = passStringToWasm0(y_axis, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
wasm.faster_call(x1, x2, y1, y2, canvas_pixel_width, canvas_pixel_height, ptr0, len0, ptr1, len1, calculate_screensapce, slice);
}

/**
* @returns {number}
*/
export function get_buf_as_ptr() {
const ret = wasm.get_buf_as_ptr();
return ret >>> 0;
}

/**
* @returns {bigint}
*/
export function get_resolution() {
const ret = wasm.get_resolution();
return ret;
}

let cachedInt32Memory0 = null;

Expand All @@ -86,14 +121,14 @@ function getStringFromWasm0(ptr, len) {
* @param {string} input
* @returns {string}
*/
export function return_string(input) {
export function str_to_lexemes(input) {
let deferred2_0;
let deferred2_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.return_string(retptr, ptr0, len0);
wasm.str_to_lexemes(retptr, ptr0, len0);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
deferred2_0 = r0;
Expand All @@ -106,37 +141,26 @@ export function return_string(input) {
}

/**
* @param {number} x1
* @param {number} x2
* @param {number} y1
* @param {number} y2
* @param {number} canvas_pixel_width
* @param {number} canvas_pixel_height
* @param {string} x_axis
* @param {string} y_axis
*/
export function faster_call(x1, x2, y1, y2, canvas_pixel_width, canvas_pixel_height, x_axis, y_axis) {
const ptr0 = passStringToWasm0(x_axis, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
const ptr1 = passStringToWasm0(y_axis, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
wasm.faster_call(x1, x2, y1, y2, canvas_pixel_width, canvas_pixel_height, ptr0, len0, ptr1, len1);
}

/**
* @returns {number}
*/
export function get_buf_as_ptr() {
const ret = wasm.get_buf_as_ptr();
return ret >>> 0;
}

/**
* @returns {bigint}
* @param {string} input
* @returns {string}
*/
export function get_resolution() {
const ret = wasm.get_resolution();
return ret;
export function return_string(input) {
let deferred2_0;
let deferred2_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.return_string(retptr, ptr0, len0);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
deferred2_0 = r0;
deferred2_1 = r1;
return getStringFromWasm0(r0, r1);
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
}
}

async function __wbg_load(module, imports) {
Expand Down
Binary file modified pkg/wgraphcal_bg.wasm
Binary file not shown.
7 changes: 4 additions & 3 deletions pkg/wgraphcal_bg.wasm.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function return_string(a: number, b: number, c: number): void;
export function faster_call(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void;
export function faster_call(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number): void;
export function get_buf_as_ptr(): number;
export function get_resolution(): number;
export function __wbindgen_add_to_stack_pointer(a: number): number;
export function str_to_lexemes(a: number, b: number, c: number): void;
export function return_string(a: number, b: number, c: number): void;
export function __wbindgen_malloc(a: number, b: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
export function __wbindgen_add_to_stack_pointer(a: number): number;
export function __wbindgen_free(a: number, b: number, c: number): void;
Loading

0 comments on commit de107b3

Please sign in to comment.