feat: add power scaling factor to plot generation in plot.py

The plot.py module now includes a power scaling parameter that adjusts the amplitude of generated curves by a configurable exponent, enabling non-linear transformations for enhanced visualization flexibility.
This commit is contained in:
2025-12-04 05:14:22 +00:00
parent e768ed066c
commit ed69521892
18 changed files with 930 additions and 236 deletions
+7 -1
View File
@@ -1,5 +1,6 @@
#define _POSIX_C_SOURCE 200809L
#include "lexer.h"
#include "../utils/safe_alloc.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
@@ -73,7 +74,12 @@ RavaToken_t* rava_lexer_parse_string(RavaLexer_t *lexer) {
if (length + 1 >= capacity) {
capacity *= 2;
str = realloc(str, capacity);
char *new_str = rava_safe_realloc(str, capacity);
if (!new_str) {
lexer->error_message = strdup("Out of memory");
return _rava_lexer_create_token(lexer, RAVA_TOKEN_ERROR);
}
str = new_str;
}
str[length++] = c;
}
+11 -2
View File
@@ -1,4 +1,5 @@
#include "lexer.h"
#include "../utils/safe_alloc.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
@@ -11,6 +12,7 @@ extern RavaToken_t* rava_lexer_parse_number(RavaLexer_t *lexer);
RavaLexer_t* rava_lexer_create(const char *source) {
RavaLexer_t *lexer = malloc(sizeof(RavaLexer_t));
if (!lexer) return NULL;
lexer->source = source;
lexer->source_length = strlen(source);
lexer->current = 0;
@@ -116,9 +118,14 @@ void _rava_lexer_skip_whitespace(RavaLexer_t *lexer) {
RavaToken_t* _rava_lexer_create_token(RavaLexer_t *lexer, RavaTokenType_e type) {
RavaToken_t *token = malloc(sizeof(RavaToken_t));
if (!token) return NULL;
token->type = type;
size_t length = lexer->current - lexer->start;
token->lexeme = malloc(length + 1);
if (!token->lexeme) {
free(token);
return NULL;
}
memcpy(token->lexeme, lexer->source + lexer->start, length);
token->lexeme[length] = '\0';
token->line = lexer->line;
@@ -312,8 +319,10 @@ RavaToken_t* rava_lexer_next_token(RavaLexer_t *lexer) {
return rava_lexer_parse_character(lexer);
default:
lexer->error_message = malloc(100);
snprintf(lexer->error_message, 100, "Unexpected character '%c'", c);
lexer->error_message = malloc(RAVA_ERROR_BUFFER_SIZE);
if (lexer->error_message) {
snprintf(lexer->error_message, RAVA_ERROR_BUFFER_SIZE, "Unexpected character '%c'", c);
}
return _rava_lexer_create_token(lexer, RAVA_TOKEN_ERROR);
}
}