Refactor, separate docs from headers, add ru docs

Doxygen kind'a sucks and I need multilanguage documentation, so I did
that. Also, separated massive Math.h file into smaller files.
This commit is contained in:
2025-06-21 20:12:15 +03:00
parent 7ee69fc397
commit fc774fd0ff
116 changed files with 10693 additions and 3521 deletions

162
doc/Manual/en/BH_Algo.pod Normal file
View File

@@ -0,0 +1,162 @@
=encoding UTF-8
=head1 NAME
BH_Algo - General algorithms
=head1 SYNTAX
#include <BH/Algo.h>
int data[4] = {5, 2, 3, 1};
int value, i;
value = 4;
BH_Partition(&value, data, 4, sizeof(int), intEqual);
BH_Sort(data, 4, sizeof(int), intEqual);
BH_HeapMake(data, 4, sizeof(int), intEqual);
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Algo library provides a set of algorithms for working with data:
=over
=item *
Value swapping (L</BH_Swap>)
=item *
Array partitioning (L</BH_Partition>)
=item *
Sorting (L</BH_Sort>)
=item *
Heap operations (L</BH_HeapMake>, L</BH_HeapRemove>, L</BH_HeapInsert>,
L</BH_HeapReplace>)
=back
These algorithms allow you to efficiently perform various operations on arrays
and other data structures.
=head1 API CALLS
=head2 BH_Swap
void BH_Swap(void *dest,
void *src,
size_t size);
Swaps the values between the variables I<dest> and I<src> of the specified size
I<size>.
=head2 BH_Partition
void *BH_Partition(void *pivot,
void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
Partitions the array of elements I<array> (with the number of elements I<size>
and the size of the element I<element>) into two groups relative to the pivot
element I<pivot>.
The I<equal> parameter takes a pointer to a function that compares two elements.
The I<pivot> parameter can refer to an element of the array being partitioned.
The function returns a pointer to the first element of the array that belongs to
the second group.
=head2 BH_Sort
void BH_Sort(void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
Sorts the array of elements I<array> (with the number of elements I<size> and
the size of the element I<element>).
The I<equal> parameter takes a pointer to a function that compares two elements.
=head2 BH_HeapMake
void BH_HeapMake(void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
Creates a heap in the array I<array> (with the number of elements I<size> and
the size of the element I<element>).
The I<equal> parameter takes a pointer to a function that compares two elements.
=head2 BH_HeapRemove
void BH_HeapRemove(void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
Extracts the top element of the heap in the array I<array> (with the number of
elements I<size> and the size of the element I<element>).
The I<equal> parameter takes a pointer to a function that compares two elements.
=head2 BH_HeapInsert
void BH_HeapInsert(void *value,
void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
Adds the element I<value> to the heap in the array I<array> (with the number of
elements I<size> and the size of the element I<element>).
If I<value> is NULL, it is assumed that the new value is at the end of the
array.
The I<equal> parameter takes a pointer to a function that compares two elements.
=head2 BH_HeapReplace
void BH_HeapReplace(void *value,
void *array,
size_t size,
size_t element,
BH_EqualCallback equal);
Extracts the top element of the heap in the array I<array> (with the number of
elements I<size> and the size of the element I<element>) and adds the element
I<value> to it.
If I<value> is NULL, it is assumed that the new value is at the end of the
array.
The I<equal> parameter takes a pointer to a function that compares two elements.
=head1 SEE ALSO
L<BH>

164
doc/Manual/en/BH_Args.pod Normal file
View File

@@ -0,0 +1,164 @@
=encoding UTF-8
=head1 NAME
BH_Args - command line argument processing
=head1 SYNTAX
#include <BH/Args.h>
static BH_ArgsOption options[] =
{
{'h', "help", 0, "Display this help"},
{1000, "list", 0, "List files"},
{'i', "input", BH_ARGS_VALUE, "Input file"},
{'o', "output", BH_ARGS_VALUE | BH_ARGS_OPTIONAL, "Output file"},
{0, NULL, 0, NULL}
};
static int OptionsCallback(int key,
char *arg,
void *data)
{
switch (key)
{
case BH_ARGS_UNKNOWN:
/* Unknown options */
break;
case BH_ARGS_ARGUMENT:
/* Regular argument in arg */
break;
case 'h':
/* Named option without argument */
break;
case 1000:
/* Long-only option without argument */
break;
case 'i':
/* Option with argument in arg */
break;
case 'o':
/* Option with optional argument in arg */
break;
}
return BH_OK;
}
BH_ArgsParse(argc, argv, options, OptionsCallback, NULL);
BH_ArgsHelp(options, 0);
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Args library is designed for convenient handling of command line
arguments in programs. It allows you to define a set of options that can be
specified when starting a program and provides mechanisms for their analysis and
processing.
Argument parsing follows these rules:
=over
=item *
If the "--" argument is specified, subsequent argument parsing is stopped.
=item *
If the "-" argument is specified, it is processed as is.
=item *
For long argument values, the string after the equal sign or the next argument
("--define=value" or "--define value") will be used.
=item *
For short argument values, the remainder of the string after the parameter
character or the next argument ("-dvalue" or "-d value") will be used.
=back
=head1 API CALLS
=head2 BH_ArgsParse
int BH_ArgsParse(int argc,
char **argv,
BH_ArgsOption *options,
BH_ArgsCallback callback,
void *data);
Parses the command line arguments I<options> (specified in I<argc> and I<argv>)
and calls the specified handler I<callback> (with user data I<data>).
The I<options> parameter refers to a null-terminated array.
If successful, this function returns 0, otherwise it returns an error code.
=head2 BH_ArgsHelp
void BH_ArgsHelp(BH_ArgsOption *options,
int padding);
Prints help information for the arguments I<options> to F<stdout> (with the
specified alignment I<padding>).
If the I<padding> parameter is 0, the default value (30) will be used.
=head1 STRUCTURES
=head2 BH_ArgsOption
typedef struct BH_ArgsOption
{
int key;
const char *name;
int flags;
const char *description;
} BH_ArgsOption;
The I<key> field contains the option identifier. If the I<key> identifier is a
printable ASCII character, it will be used as a short argument.
The optional I<name> field contains a string that will be used as a long
argument.
The I<flags> field contains argument flags. A combination of the following flags
is possible:
=over
=item B<BH_ARGS_VALUE>
The argument accepts a value.
=item B<BH_ARGS_OPTIONAL>
The argument value is optional.
=back
The I<description> field contains a string that will be used when displaying
help information using the L</BH_ArgsHelp> function.
=head1 SEE ALSO
L<BH>

View File

@@ -0,0 +1,98 @@
=encoding UTF-8
=head1 NAME
BH_Box2f - two-dimensional bounding box
=head1 SYNTAX
#include <BH/Math/Box2f.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Box2f module provides functions for working with two-dimensional bounding
boxes. It includes operations for union, intersection, checking if a point is
inside a rectangle, and calculating the bounding box for a set of points.
=head1 API CALLS
=head2 BH_Box2fUnion
void BH_Box2fUnion(const float aMin[2],
const float aMax[2],
const float bMin[2],
const float bMax[2],
float outMin[2],
float outMax[2]);
Combines two bounding boxes A and B.
The parameters I<aMin> and I<aMax> describe the bounding box A.
The parameters I<bMin> and I<bMax> describe the bounding box B.
The parameters I<outMin> and I<outMax> describe the resulting bounding box.
=head2 BH_Box2fIntersect
int BH_Box2fIntersect(const float aMin[2],
const float aMax[2],
const float bMin[2],
const float bMax[2],
float outMin[2],
float outMax[2]);
Calculates the intersection of two bounding boxes A and B.
The parameters I<aMin> and I<aMax> describe the bounding box A.
The parameters I<bMin> and I<bMax> describe the bounding box B.
The parameters I<outMin> and I<outMax> describe the resulting bounding box.
Returns 0 in case of successful intersection or an error code.
=head2 BH_Box2fContains
int BH_Box2fContains(const float aMin[2],
const float aMax[2],
const float point[2]);
Checks if the point is inside the bounding box.
The parameters I<aMin> and I<aMax> describe the bounding box.
The parameter I<point> describes the point.
Returns 0 if the point is inside the rectangle, or an error code.
=head2 BH_Box2fEnclose
int BH_Box2fEnclose(const float *points,
size_t size,
float outMin[2],
float outMax[2]);
Calculates the bounding box for the given points.
The parameters I<points> and I<size> describe the input array of points.
The parameters I<outMin> and I<outMax> describe the resulting bounding box.
Returns 0 in case of successful calculation or an error code.
=head1 SEE ALSO
L<BH>,
L<BH_Box3f>

View File

@@ -0,0 +1,98 @@
=encoding UTF-8
=head1 NAME
BH_Box3f - three-dimensional bounding box
=head1 SYNTAX
#include <BH/Math/Box3f.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Box3f module provides functions for working with three-dimensional
bounding boxes. It includes operations for union, intersection, checking if a
point is inside a box, and calculating the bounding box for a set of points.
=head1 API CALLS
=head2 BH_Box3fUnion
void BH_Box3fUnion(const float aMin[3],
const float aMax[3],
const float bMin[3],
const float bMax[3],
float outMin[3],
float outMax[3]);
Combines two bounding boxes I<A> and I<B>.
The parameters I<aMin> and I<aMax> describe the bounding box A.
The parameters I<bMin> and I<bMax> describe the bounding box B.
The parameters I<outMin> and I<outMax> describe the resulting bounding box.
=head2 BH_Box3fIntersect
int BH_Box3fIntersect(const float aMin[3],
const float aMax[3],
const float bMin[3],
const float bMax[3],
float outMin[3],
float outMax[3]);
Calculates the intersection of two bounding boxes A and B.
The parameters I<aMin> and I<aMax> describe the bounding box A.
The parameters I<bMin> and I<bMax> describe the bounding box B.
The parameters I<outMin> and I<outMax> describe the resulting bounding box.
Returns 0 in case of successful intersection or an error code.
=head2 BH_Box3fContains
int BH_Box3fContains(const float aMin[3],
const float aMax[3],
const float point[3]);
Checks if the point is inside the bounding box.
The parameters I<aMin> and I<aMax> describe the bounding box.
The parameter I<point> describes the point.
Returns 0 if the point is inside the bounding box, or an error code.
=head2 BH_Box3fEnclose
int BH_Box3fEnclose(const float *points,
size_t size,
float outMin[3],
float outMax[3]);
Calculates the bounding box for the given points.
The parameters I<points> and I<size> describe the input array of points.
The parameters I<outMin> and I<outMax> describe the resulting bounding box.
Returns 0 in case of success or an error code.
=head1 SEE ALSO
L<BH>,
L<BH_Box2f>

View File

@@ -0,0 +1,197 @@
=encoding UTF-8
=head1 NAME
BH_Hashmap - unordered associative array
=head1 SYNTAX
#include <BH/Hashmap.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Hashmap library provides an implementation of an unordered associative
array based on a hash table. It allows you to store and retrieve data by key
efficiently.
=head1 API CALLS
=head2 BH_HashmapNew
BH_Hashmap *BH_HashmapNew(BH_EqualCallback equal,
BH_HashCallback hash);
Creates an associative array.
The I<equal> parameter takes a pointer to a function that compares two elements.
The I<hash> parameter takes a pointer to a function that calculates the hash
value of an element.
If successful, the function returns a pointer to a new BH_Hashmap object or NULL
in case of an error.
=head2 BH_HashmapFree
void BH_HashmapFree(BH_Hashmap *hashmap);
Destroys the associative array.
=head2 BH_HashmapClear
void BH_HashmapClear(BH_Hashmap *hashmap);
Clears the associative array.
=head2 BH_HashmapReserve
int BH_HashmapReserve(BH_Hashmap *hashmap,
size_t size);
Reserves space for at least I<size> elements.
Calling this function invalidates existing iterators.
If successful, the function returns 0; otherwise, it returns an error code.
=head2 BH_HashmapInsert
int BH_HashmapInsert(BH_Hashmap *hashmap,
void *key,
void *value);
Inserts an element represented by the key-value pair I<key> and I<value>.
The function allows inserting multiple elements with the same key value.
Calling this function invalidates existing iterators.
If successful, the function returns 0; otherwise, it returns an error code.
=head2 BH_HashmapRemove
void BH_HashmapRemove(BH_Hashmap *hashmap,
void *key);
Removes the element with the given key value I<key>.
If the associative array contains multiple elements with the same key value, the
function will remove only one key-value pair.
Calling this function invalidates existing iterators.
=head2 BH_HashmapAt
int BH_HashmapAt(BH_Hashmap *hashmap,
void *key,
void **value);
Checks if there is an element with the given key I<key>.
The optional I<value> parameter returns the value of the element with the given
key.
If successful, the function returns 0; otherwise, it returns an error code.
=head2 BH_HashmapEmpty
int BH_HashmapEmpty(BH_Hashmap *hashmap);
Checks if the associative array is empty.
=head2 BH_HashmapSize
size_t BH_HashmapSize(BH_Hashmap *hashmap);
Returns the number of elements.
=head2 BH_HashmapCapacity
size_t BH_HashmapCapacity(BH_Hashmap *hashmap);
Returns the capacity.
=head2 BH_HashmapFactor
float BH_HashmapFactor(BH_Hashmap *hashmap);
Returns the maximum load factor.
=head2 BH_HashmapSetFactor
void BH_HashmapSetFactor(BH_Hashmap *hashmap,
float factor);
Sets the maximum load factor I<factor>.
The new value of the maximum load factor will be applied on the next call to
L</BH_HashmapInsert> or L</BH_HashmapReserve>.
=head2 BH_HashmapIterAt
void *BH_HashmapIterAt(BH_Hashmap *hashmap,
void *key);
Returns an iterator to the element with the given key I<key>.
If successful, the function returns an iterator or NULL.
=head2 BH_HashmapIterNext
void *BH_HashmapIterNext(BH_Hashmap *hashmap,
void *iter);
Returns an iterator to the next element.
The optional I<iter> parameter takes an iterator to the current element.
If successful, the function returns an iterator or NULL.
=head2 BH_HashmapIterRemove
void BH_HashmapIterRemove(BH_Hashmap *hashmap,
void *iter);
Removes the element by the given iterator I<iter>.
Calling this function invalidates existing iterators.
=head2 BH_HashmapIterKey
void *BH_HashmapIterKey(void *iter);
Returns the key of the element pointed to by the iterator I<iter>.
=head2 BH_HashmapIterValue
void *BH_HashmapIterValue(void *iter);
Returns the value of the element pointed to by the iterator I<iter>.
=head1 SEE ALSO
L<BH>

510
doc/Manual/en/BH_IO.pod Normal file
View File

@@ -0,0 +1,510 @@
=encoding UTF-8
=head1 NAME
BH_IO - I/O subsystem
=head1 SYNOPSIS
#include <BH/io.h>
BH_IO *io = BH_FileNew("input.txt", BH_FILE_WRITE | BH_FILE_TRUNCATE, NULL);
BH_IOWrite(io, "Hello, world!", 13, NULL);
BH_IOFree(io);
cc prog.c -o prog -lbh
=head1 DESCRIPTION
BH_IO provides a subsystem that allows you to work with various objects (files,
sockets, memory) via a single I/O interface. This allows you to write code that
is not tied to a specific input/output system.
It is guaranteed that any BH_IO object supports the following operations:
L</BH_IORead>, L</BH_IOWrite>, L</BH_IOCtl> и L</BH_IOCap>.
Depending on the implementation of a particular BH_IO object, additional
operations may be available: L</BH_IOFlags>, L</BH_IOClear>, L</BH_IOFlush>,
L</BH_IOSize>, L</BH_IOTell>, L</BH_IOSeek>, L</BH_IOPeek> and others.
By default, the I/O subsystem allows you to work with files (L</BH_FileNew>) or
RAM (L</BH_BytesNew>), as well as buffer I/O (L</BH_BufferNew>).
=head1 EXTENSIONS
BH_IO provides the developer with the ability to create custom implementations
of I/O devices. Example:
typedef struct BH_MyIO
{
BH_IO parent;
int flags;
};
static int ioDestroy(BH_MyIO *io)
{
/* Ommitted for the example */
}
static int ioRead(BH_MyIO *io,
BH_IOReadInfo *info)
{
/* Ommitted for the example */
}
static int ioWrite(BH_MyIO *io,
BH_IOWriteInfo *info)
{
/* Ommited for the example */
}
static int ioFlags(BH_MyIO *io,
int *flags)
{
*flags = io->flags;
return BH_OK;
}
static int ioCap(BH_MyIO *io,
int *op)
{
BH_UNUSED(io);
switch (*op)
{
case BH_IO_CTL_FLAGS:
return BH_OK;
default:
return BH_NOIMPL;
}
}
static int ioCtl(BH_MyIO *io,
BH_IOCtlInfo *info)
{
switch (info->op)
{
case BH_IO_CTL_FLAGS:
return ioFlags(io, (int *)info->arg);
default:
return BH_NOIMPL;
}
}
static int ioCallback(BH_MyIO *io,
int type,
void *arg)
{
switch (type)
{
case BH_IO_OP_DESTROY: return ioDestroy(io);
case BH_IO_OP_READ: return ioRead(io, (BH_IOReadInfo *)arg);
case BH_IO_OP_WRITE: return ioWrite(io, (BH_IOWriteInfo *)arg);
case BH_IO_OP_CTL: return ioCtl(io, (BH_IOCtlInfo *)arg);
case BH_IO_OP_CAP: return ioCap(io, (int*)arg);
default: return BH_NOIMPL;
}
}
BH_IO *BH_MyIONew(int *result)
{
BH_MyIO *io;
int code;
code = BH_OOM;
if ((io = malloc(sizeof(*io))))
{
io->parent.callback = (BH_IOCallback)ioCallback;
io->flags = 0;
}
if (result)
*result = code;
return (BH_IO*)io;
}
=head1 API CALLS
=head2 BH_FileNew
BH_IO *BH_FileNew(const char *path,
int mode,
int *result);
Creates an I/O device for working with the file using the I<path>.
The I<mode> parameter can take a combination of the following values:
=over
=item B<BH_FILE_READ>
Opens the file for reading
=item B<BH_FILE_WRTIE>
Opens the file for writing
=item B<BH_FILE_APPEND>
Opens the file in append mode
=item B<BH_FILE_TRUNCATE>
Truncates the file
=item B<BH_FILE_CREATE>
The file must be created
=item B<BH_FILE_EXIST>
The file must exist
=back
The optional parameter I<result> returns 0 or an error code.
This function returns a pointer to a new BH_IO object or NULL.
=head2 BH_BufferNew
BH_IO *BH_BufferNew(BH_IO *device,
size_t size,
int *result);
Creates an I/O device to buffer data to another I<device>.
The I<size> parameter is responsible for the size of the read and write buffers.
The optional parameter I<result> returns 0 or an error code.
If successful, this function returns a pointer to the new BH_IO object or
NULL in case of an error.
=head2 BH_BytesNew
BH_IO *BH_BytesNew(char *data,
size_t size,
int *result);
Creates an I/O device for the memory region I<data> with the size I<size>.
The optional parameter I<result> returns 0 or an error code.
If successful, this function returns a pointer to the new BH_IO object or
NULL in case of an error.
=head2 BH_IOFree
void BH_IOFree(BH_IO *device);
Destroys the I/O device.
=head2 BH_IORead
int BH_IORead(BH_IO *device,
char *buffer,
size_t size,
size_t *actual);
Reads up to I<size> bytes from the I/O device and writes data to
I<buffer>.
The optional parameter I<actual> returns the number of bytes that was read.
If successful, this function returns 0 or an error code.
=head2 BH_IOWrite
int BH_IOWrite(BH_IO *io,
const char *buffer,
size_t size,
size_t *actual);
Writes up to I<size> bytes to the I/O device from I<buffer>.
The optional parameter I<actual> returns the number of bytes that was written.
If successful, this function returns 0 or an error code.
=head2 BH_IOCtl
int BH_IOCtl(BH_IO *device,
int op,
void *arg);
Manipulates the parameters of the I/O device using the I<op> command and
the I<arg> argument.
Possible values of I<op>:
=over
=item B<BH_IO_CTL_FLAGS>
Argument: int *
Return the I/O device flags.
=item B<BH_IO_CTL_CLEAR>
Reset the I/O device errors.
=item B<BH_IO_CTL_PEEK>
Argument: L<BH_IOReadInfo *|/BH_IOReadInfo>
Reads data from an I/O device without extracting it.
=item B<BH_IO_CTL_FLUSH>
Write buffered data to the I/O device.
=item B<BH_IO_CTL_SIZE>
Argument: int64_t *
Get the size of the I/O device.
=item B<BH_IO_CTL_TELL>
Argument: int64_t *
Reads the current offset of the I/O device reader pointer.
=item B<BH_IO_CTL_SEEK>
Argument: L<BH_IOSeekInfo *|/BH_IOSeekInfo>
Changes the current position of the I/O reader pointer.
=item B<BH_IO_CTL_GET_IO>
Argument: L<BH_IO **|/BH_IO>|void *
Gets the device I/O object used in the implementation.
=item B<BH_IO_CTL_SET_IO>
Argument: L<BH_IO *|/BH_IO>|void *
Sets the device I/O object to be used in the implementation.
=back
If successful, this function returns 0 or an error code.
=head2 BH_IOCap
int BH_IOCap(BH_IO *device,
int op);
Checks whether the I<op> command can be executed on the I/O device.
If successful, this function returns 0 or an error code.
=head2 BH_IOFlags
int BH_IOFlags(BH_IO *device,
int *flags);
Returns the current I<flags> flags of the I/O device.
Possible flags (and their combinations):
=over
=item B<BH_IO_FLAG_ERROR>
An error occurred during the execution.
=item B<BH_IO_FLAG_EOF>
The device has reached the end of the file.
=back
If successful, this function returns 0 or an error code.
=head2 BH_IOClear
int BH_IOClear(BH_IO *device);
Cleans the I/O device from errors.
If successful, this function returns 0 or an error code.
=head2 BH_IOPeek
int BH_IOPeek(BH_IO *device,
char *buffer,
size_t size,
size_t *actual);
Reads up to I<size> bytes from the I/O device without extraction and writes
the data to I<buffer>.
The optional parameter I<actual> returns the number of bytes that was actually
read.
If successful, this function returns 0 or an error code.
=head2 BH_IOFlush
int BH_IOFlush(BH_IO *device);
Writes buffered values to the I/O device.
If successful, this function returns 0 or an error code.
=head2 BH_IOSize
int BH_IOSize(BH_IO *device,
int64_t *size);
Reads the current size of the I/O device in bytes and writes the value to
I<size>.
For different types of I/O devices, this value can mean different things (for
example: the current file size, the size of the memory allocated for I/O, etc.).
If successful, this function returns 0 or an error code.
=head2 BH_IOTell
int BH_IOTell(BH_IO *device,
int64_t *offset);
Reads the current offset of the I/O reader pointer relative
to the start and writes the value to I<offset>.
If successful, this function returns 0 or an error code.
=head2 BH_IOSeek
int BH_IOSeek(BH_IO *device,
int64_t offset,
int whence);
Changes the current position of the I/O reader pointer, taking into account
the offset I<offset> and the initial position I<whence>.
Possible values of the initial position I<whence>:
=over
=item B<BH_IO_SEEK_SET>
Offset relative to the beginning of the device.
=item B<BH_IO_SEEK_CUR>
Offset relative to the current position of the device.
=item B<BH_IO_SEEK_END>
Offset relative to the end of the device.
=back
If successful, this function returns 0 or an error code.
=head2 BH_IOError
int BH_IOError(BH_IO *device);
Checks whether the I/O device is in an error state.
This function is equivalent to the following code:
(BH_IOFlags(device) & BH_IO_FLAG_ERROR)
=head2 BH_IOEndOfFile
int BH_IOEndOfFile(BH_IO *device);
Checks whether the I/O device has reached the end.
This function is equivalent to the following code:
(BH_IOFlags(device) & BH_IO_FLAG_EOF)
=head1 STRUCTURES
=head2 BH_IO
typedef struct BH_IO
{
BH_IOCallback callback;
} BH_IO;
=head2 BH_IOReadInfo
typedef struct BH_IOReadInfo
{
char *data;
size_t size;
size_t *actual;
} BH_IOReadInfo;
=head2 BH_IOWriteInfo
typedef struct BH_IOWriteInfo
{
const char *data;
size_t size;
size_t *actual;
} BH_IOWriteInfo;
=head2 BH_IOCtlInfo
typedef struct BH_IOCtlInfo
{
int op;
void *arg;
} BH_IOCtlInfo;
=head2 BH_IOSeekInfo
typedef struct BH_IOSeekInfo
{
int64_t offset;
int whence;
} BH_IOSeekInfo;
=head1 SEE ALSO
L<BH>

62
doc/Manual/en/BH_Line.pod Normal file
View File

@@ -0,0 +1,62 @@
=encoding UTF-8
=head1 NAME
BH_Line - a straight line on a plane.
=head1 SYNTAX
#include <BH/Math.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Line module provides functions for working with straight lines on a
plane. It allows you to calculate the coefficients of a line based on two
points, find the distance from a point to a line, and determine the closest
point on the line to a given point.
=head1 API CALLS
=head2 BH_LineFromPoints
int BH_LineFromPoints(const float a[2],
const float b[2],
float out[3]);
Calculates the coefficients of a line on a plane based on two points I<a> and
I<b>.
The I<out> parameter describes the resulting line on the plane.
If successful, the function returns 0, otherwise it returns an error code.
=head2 BH_LineDistance
float BH_LineDistance(const float line[3],
const float point[2]);
Calculates the distance from the point I<point> to the line I<line>.
=head2 BH_LineClosestPoint
void BH_LineClosestPoint(const float line[3],
const float point[2],
float out[2]);
Calculates the closest point on the line I<line> to another point I<point>.
The I<out> parameter describes the resulting point.
=head1 SEE ALSO
L<BH>

168
doc/Manual/en/BH_Mat3f.pod Normal file
View File

@@ -0,0 +1,168 @@
=encoding UTF-8
=head1 NAME
BH_Mat3f - a real 3x3 matrix
=head1 SYNTAX
#include <BH/Math/Mat3f.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Mat3f module provides a set of functions for working with real 3x3
matrices.
=head1 API CALLS
=head2 BH_Mat3fIdentity
void BH_Mat3fIdentity(float out[9]);
Writes an identity matrix to I<out>.
=head2 BH_Mat3fAdd
void BH_Mat3fAdd(const float a[9],
const float b[9],
float out[9]);
Calculates the sum of two matrices I<a> and I<b>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat3fSub
void BH_Mat3fSub(const float a[9],
const float b[9],
float out[9]);
Calculates the difference between two matrices I<a> and I<b>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat3fMul
void BH_Mat3fMul(const float a[9],
const float b[9],
float out[9]);
Calculates the result of multiplying two matrices I<a> and I<b>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat3fScale
void BH_Mat3fScale(const float a[9],
float b,
float out[9]);
Calculates the result of multiplying matrix I<a> by value I<b>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat3fTranspose
void BH_Mat3fTranspose(const float in[9],
float out[9]);
Transposes matrix I<in>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat3fTrace
float BH_Mat3fTrace(const float in[9]);
Calculates the sum of the elements of the main diagonal of matrix I<in>.
=head2 BH_Mat3fDet
float BH_Mat3fDet(const float in[9]);
Calculates the determinant of matrix I<in>.
=head2 BH_Mat3fInverse
int BH_Mat3fInverse(const float in[9],
float out[9]);
Calculates the inverse matrix for I<in>.
The I<out> parameter describes the resulting matrix.
If successful, the function returns 0, otherwise it returns an error code.
=head2 BH_Mat3fFromScale
void BH_Mat3fFromScale(float x,
float y,
float out[9]);
Calculates a scaling matrix with scales I<x> and I<y>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat3fFromTranslation
void BH_Mat3fFromTranslation(float x,
float y,
float out[9]);
Calculates a translation matrix with values I<x> and I<y>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat3fFromRotation
void BH_Mat3fFromRotation(float angle,
float out[9]);
Calculates a rotation matrix with a given I<angle>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat3fApplyVec3f
void BH_Mat3fApplyVec3f(float a[9],
float b[3],
float out[3]);
Calculates the result of multiplying matrix I<a> by vector I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Mat3fApplyVec2f
void BH_Mat3fApplyVec2f(float a[9],
float b[2],
float out[2]);
Calculates the result of multiplying matrix I<a> by vector I<b>.
The I<out> parameter describes the resulting vector.
=head1 SEE ALSO
L<BH>

286
doc/Manual/en/BH_Mat4f.pod Normal file
View File

@@ -0,0 +1,286 @@
=encoding UTF-8
=head1 NAME
BH_Mat4f - real 4x4 matrix
=head1 SYNTAX
#include <BH/Math/Mat4f.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Mat4f module provides a set of functions for working with real 4x4
matrices. These functions allow you to perform various operations on matrices,
such as addition, subtraction, multiplication, transposition, determinant
calculation, and others.
=head1 API CALLS
=head2 BH_Mat4fIdentity
void BH_Mat4fIdentity(float out[16]);
Writes an identity matrix to I<out>.
=head2 BH_Mat4fAdd
void BH_Mat4fAdd(const float a[16],
const float b[16],
float out[16]);
Calculates the sum of two matrices I<a> and I<b>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fSub
void BH_Mat4fSub(const float a[16],
const float b[16],
float out[16]);
Calculates the difference between two matrices I<a> and I<b>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fMul
void BH_Mat4fMul(const float a[16],
const float b[16],
float out[16]);
Calculates the result of multiplying two matrices I<a> and I<b>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fScale
void BH_Mat4fScale(const float a[16],
float b,
float out[16]);
Calculates the result of multiplying matrix I<a> by value I<b>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fTranspose
void BH_Mat4fTranspose(const float in[16],
float out[16]);
Transposes matrix I<in>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fTrace
float BH_Mat4fTrace(const float in[16]);
Calculates the sum of the elements of the main diagonal of matrix I<in>.
=head2 BH_Mat4fDet
float BH_Mat4fDet(const float in[16]);
Calculates the determinant of matrix I<in>.
=head2 BH_Mat4fInverse
int BH_Mat4fInverse(const float in[16],
float out[16]);
Calculates the inverse matrix for I<in>.
The I<out> parameter describes the resulting matrix.
If successful, the function returns 0, otherwise it returns an error code.
=head2 BH_Mat4fFromScale
void BH_Mat4fFromScale(float x,
float y,
float z,
float out[16]);
Calculates a scaling matrix with scales I<x>, I<y>, and I<z>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fFromTranslation
void BH_Mat4fFromTranslation(float x,
float y,
float z,
float out[16]);
Calculates a translation matrix with values I<x>, I<y>, and I<z>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fFromRotationX
void BH_Mat4fFromRotationX(float angle,
float out[16]);
Calculates a rotation matrix around the X axis with a given I<angle>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fFromRotationY
void BH_Mat4fFromRotationY(float angle,
float out[16]);
Calculates a rotation matrix around the Y axis with a given I<angle>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fFromRotationZ
void BH_Mat4fFromRotationZ(float angle,
float out[16]);
Calculates a rotation matrix around the Z axis with a given I<angle>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fFromAxis
void BH_Mat4fFromAxis(const float axis[3],
float angle,
float out[16]);
Calculates a rotation matrix around the axis I<axis> with a given I<angle>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fFromEuler
void BH_Mat4fFromEuler(float roll,
float pitch,
float yaw,
float out[16]);
Calculates a rotation matrix from the angles of the associated coordinate system
I<roll>, I<pitch>, and I<yaw>.
The order of rotation application is ZYX (yaw, pitch, roll).
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fFromQuat4f
void BH_Mat4fFromQuat4f(const float in[4],
float out[16]);
Calculates a rotation matrix from quaternion I<in>.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fFromOrtho
void BH_Mat4fFromOrtho(float xMin,
float xMax,
float yMin,
float yMax,
float zMin,
float zMax,
float out[16]);
Calculates an orthographic projection matrix.
The I<xMin> and I<xMax> parameters define the valid range of X coordinates.
The I<yMin> and I<yMax> parameters define the valid range of Y coordinates.
The I<zMin> and I<zMax> parameters define the valid range of Z coordinates.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fFromFrustum
void BH_Mat4fFromFrustum(float fov,
float aspect,
float zMin,
float zMax,
float out[16]);
Calculates a perspective projection matrix.
The I<fov> parameter defines the field of view.
The I<aspect> parameter defines the aspect ratio.
The I<zMin> and I<zMax> parameters define the valid range of Z coordinates.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fFromLookAt
void BH_Mat4fFromLookAt(const float position[3],
const float at[3],
const float up[3],
float out[16]);
Calculates the camera view matrix.
The I<position> parameter defines the position of the camera in space.
The I<at> parameter defines the point where the camera is aimed.
The I<up> parameter defines the "up" direction of the camera.
The I<out> parameter describes the resulting matrix.
=head2 BH_Mat4fApplyVec4f
void BH_Mat4fApplyVec4f(const float a[16],
const float b[4],
float out[4]);
Calculates the result of multiplying matrix I<a> by vector I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Mat4fApplyVec3f
void BH_Mat4fApplyVec3f(const float a[16],
const float b[3],
float out[3]);
Calculates the result of multiplying matrix I<a> by vector I<b>.
The I<out> parameter describes the resulting vector.
=head1 SEE ALSO
L<BH>

50
doc/Manual/en/BH_Math.pod Normal file
View File

@@ -0,0 +1,50 @@
=encoding UTF-8
=head1 NAME
BH_Math - Mathematical functions
=head1 SYNTAX
#include <BH/Math.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Math library provides a set of mathematical functions for various
calculations.
=head1 API CALLS
=head2 BH_Lerpf
float BH_Lerpf(float a,
float b,
float t);
Interpolates the value between I<a> and I<b> with a given coefficient I<t>.
=head2 BH_Triangle3fBarycentric
void BH_Triangle3fBarycentric(const float a[3],
const float b[3],
const float c[3],
const float point[3],
float out[3]);
Calculates the barycentric coordinates of the I<point> relative to the
triangle defined by points I<a>, I<b>, I<c>.
The I<out> parameter describes the resulting vector.
=head1 SEE ALSO
L<BH>

View File

@@ -0,0 +1,66 @@
=encoding UTF-8
=head1 NAME
BH_Plane - Plane in space
=head1 SYNTAX
#include <BH/Math.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Plane module provides functions for working with planes in
three-dimensional space. It allows you to calculate the coefficients of a plane
from three points, determine the distance from a point to a plane, and find the
closest point on the plane to a given point.
=head1 API CALLS
=head2 BH_PlaneFromPoints
int BH_PlaneFromPoints(const float a[3],
const float b[3],
const float c[3],
float out[4]);
Calculates the coefficients of a plane from three points I<a>, I<b>, I<c>.
It is assumed that the points are arranged in a clockwise order.
If the points form a degenerate triangle, the function will return an error.
The I<out> parameter defines the resulting plane.
If successful, the function returns 0, otherwise it returns an error code.
=head2 BH_PlaneDistance
float BH_PlaneDistance(const float plane[4],
const float point[3]);
Calculates the distance from the I<point> to the I<plane>.
=head2 BH_PlaneClosestPoint
void BH_PlaneClosestPoint(const float plane[4],
const float point[3],
float out[3]);
Calculates the closest point on the I<plane> to another I<point>.
The I<out> parameter describes the resulting point.
=head1 SEE ALSO
L<BH>

219
doc/Manual/en/BH_Quat.pod Normal file
View File

@@ -0,0 +1,219 @@
=encoding UTF-8
=head1 NAME
BH_Quat - Quaternion
=head1 SYNTAX
#include <BH/Math/Quat.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
This module provides a set of functions for working with quaternions.
Quaternions are used to represent rotations in three-dimensional space and have
advantages over other methods, such as rotation matrices or Euler angles, in
terms of stability against error accumulation during multiple rotation
operations.
=head1 API CALLS
=head2 BH_Quat4fAdd
#define BH_Quat4fAdd(a, b, out) \
BH_Vec4fAdd(a, b, out)
Calculates the sum of two quaternions I<a> and I<b>.
The parameter I<out> describes the resulting quaternion.
=head2 BH_Quat4fSub
#define BH_Quat4fSub(a, b, out) \
BH_Vec4fSub(a, b, out)
Calculates the difference between two quaternions I<a> and I<b>.
The parameter I<out> describes the resulting quaternion.
=head2 BH_Quat4fScale
#define BH_Quat4fScale(a, b, out) \
BH_Vec4fScale(a, b, out)
Calculates the result of multiplying quaternion I<a> by value I<b>.
The parameter I<out> describes the resulting quaternion.
=head2 BH_Quat4fNegate
#define BH_Quat4fNegate(in, out) \
BH_Vec4fNegate(in, out)
Calculates the opposite quaternion from quaternion I<in>.
The parameter I<out> describes the resulting quaternion.
=head2 BH_Quat4fDot
#define BH_Quat4fDot(a, b) \
BH_Vec4fDot(a, b)
Calculates the dot product of quaternions I<a> and I<b>.
=head2 BH_Quat4fLength
#define BH_Quat4fLength(in) \
BH_Vec4fLength(in)
float BH_Vec4fLength(const float in[4]);
Calculates the length of quaternion I<in>.
=head2 BH_Quat4fNormal
#define BH_Quat4fNormal(in, out) \
BH_Vec4fNormal(in, out)
Calculates the normalized form of quaternion I<in>.
The parameter I<out> describes the resulting quaternion.
=head2 BH_Quat4fLerp
#define BH_Quat4fLerp(a, b, t, out) \
BH_Vec4fLerp(a, b, t, out)
Performs linear interpolation between two quaternions I<a> and I<b> with
parameter I<t>.
The parameter I<out> describes the resulting quaternion.
=head2 BH_Quat4fIdentity
void BH_Quat4fIdentity(float out[4]);
Writes the identity quaternion to I<out>.
=head2 BH_Quat4fConjugate
void BH_Quat4fConjugate(const float in[4],
float out[4]);
Calculates the conjugate quaternion from I<in>.
The parameter I<out> describes the resulting quaternion.
=head2 BH_Quat4fInverse
void BH_Quat4fInverse(const float in[4],
float out[4]);
Calculates the inverse quaternion from I<in>.
The parameter I<out> describes the resulting quaternion.
=head2 BH_Quat4fMul
void BH_Quat4fMul(const float a[4],
const float b[4],
float out[4]);
Calculates the result of multiplying two quaternions I<a> and I<b>.
The parameter I<out> describes the resulting quaternion.
=head2 BH_Quat4fSlerp
void BH_Quat4fSlerp(const float a[4],
const float b[4],
float t,
float out[4]);
Performs spherical linear interpolation between two quaternions I<a> and I<b>
with parameter I<t>.
The parameter I<out> describes the resulting quaternion.
=head2 BH_Quat4fFromEuler
void BH_Quat4fFromEuler(float roll,
float pitch,
float yaw,
float out[4]);
Calculates the quaternion from the angles of the associated coordinate system
I<roll>, I<pitch>, and I<yaw>.
The order of rotation application is ZYX (yaw, pitch, roll).
The parameter I<out> describes the resulting quaternion.
=head2 BH_Quat4fFromAxis
void BH_Quat4fFromAxis(const float axis[3],
float angle,
float out[4]);
Calculates the quaternion from rotation around the I<axis> with the given
I<angle>.
The parameter I<out> describes the resulting quaternion.
=head2 BH_Quat4fToEuler
void BH_Quat4fToEuler(const float in[4],
float *roll,
float *pitch,
float *yaw);
Calculates the angles of the associated coordinate system I<roll>, I<pitch>,
and I<yaw> from quaternion I<in>.
The order of rotation application is ZYX (yaw, pitch, roll).
=head2 BH_Quat4fToAxis
void BH_Quat4fToAxis(const float in[4],
float axis[3],
float *angle);
Calculates the rotation I<axis> and I<angle> from quaternion I<in>.
=head2 BH_Quat4fToMat4f
void BH_Quat4fToMat4f(const float in[4],
float out[16]);
Calculates the rotation matrix from quaternion I<in>.
The parameter I<out> describes the resulting matrix.
=head1 SEE ALSO
L<BH>

138
doc/Manual/en/BH_Queue.pod Normal file
View File

@@ -0,0 +1,138 @@
=encoding UTF-8
=head1 NAME
BH_Queue - queue container
=head1 SYNTAX
#include <BH/Queue.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Queue module provides an implementation of a queue container that allows
adding elements to the end and removing them from the beginning. The queue is
based on a dynamic array, which ensures efficient memory usage and fast access
to elements.
=head1 API CALLS
=head2 BH_QueueNew
BH_Queue *BH_QueueNew(void);
Creates a queue.
If successful, the function returns a pointer to a new BH_Queue object, or NULL
in case of an error.
=head2 BH_QueueFree
void BH_QueueFree(BH_Queue *queue);
Destroys the queue.
=head2 BH_QueueClear
void BH_QueueClear(BH_Queue *queue);
Clears the queue.
=head2 BH_QueueReserve
int BH_QueueReserve(BH_Queue *queue,
size_t size);
Reserves space for at least I<size> elements.
Calling this function invalidates existing iterators.
If successful, the function returns 0; otherwise, it returns an error code.
=head2 BH_QueueInsert
int BH_QueueInsert(BH_Queue *queue,
void *value);
Inserts an element I<value>.
Calling this function invalidates existing iterators.
If successful, the function returns 0; otherwise, it returns an error code.
=head2 BH_QueueRemove
void BH_QueueRemove(BH_Queue *queue);
Removes the first element from the queue.
Calling this function invalidates existing iterators.
=head2 BH_QueueFront
int BH_QueueFront(BH_Queue *queue,
void **value);
Returns the first element of the queue.
The I<value> parameter returns the value of the element.
If successful, the function returns 0; otherwise, it returns an error code.
=head2 BH_QueueEmpty
int BH_QueueEmpty(BH_Queue *queue);
Checks if the queue is empty.
=head2 BH_QueueSize
size_t BH_QueueSize(BH_Queue *queue);
Returns the number of elements.
=head2 BH_QueueCapacity
size_t BH_QueueCapacity(BH_Queue *queue);
Returns the capacity.
=head2 BH_QueueIterNext
void *BH_QueueIterNext(BH_Queue *queue,
void *iter);
Returns an iterator to the next element.
The optional I<iter> parameter accepts an iterator to the current element.
If successful, the function returns an iterator or NULL.
=head2 BH_QueueIterValue
void *BH_QueueIterValue(void *iter);
Returns the value of the element pointed to by the iterator.
=head1 SEE ALSO
L<BH>

205
doc/Manual/en/BH_Ray2f.pod Normal file
View File

@@ -0,0 +1,205 @@
=encoding UTF-8
=head1 NAME
BH_Ray2f, BH_Segment2f - Ray/segment on a plane
=head1 SYNTAX
#include <BH/Math/Ray2f.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
This module provides functions for working with rays and segments on a plane.
It includes functions for checking intersections between rays, segments, lines,
and bounding rectangles.
=head1 API CALLS
=head2 BH_Ray2fIntersectLine
int BH_Ray2fIntersectLine(const float start[2],
const float direction[2],
const float line[3],
float *t,
float out[2]);
Checks the intersection between a ray and a line.
The parameters I<start> and I<direction> describe the ray.
The parameter I<line> describes the line.
The parameter I<t> describes the resulting time of the ray's intersection.
The parameter I<out> describes the resulting intersection point.
If successful, the function returns 0, otherwise it returns an error code.
=head2 BH_Ray2fIntersectTime
int BH_Ray2fIntersectTime(const float aStart[2],
const float aDirection[2],
const float bStart[2],
const float bDirection[2],
float *time1,
float *time2);
Calculates the intersection time between two rays.
The parameters I<aStart> and I<aDirection> describe the first ray.
The parameters I<bStart> and I<bDirection> describe the second ray.
The parameter I<time1> describes the resulting intersection time of the first
ray.
The parameter I<time2> describes the resulting intersection time of the second
ray.
If successful, the function returns 0, otherwise it returns an error code.
=head2 BH_Ray2fIntersectRay
int BH_Ray2fIntersectRay(const float aStart[2],
const float aDirection[2],
const float bStart[2],
const float bDirection[2],
float *t,
float out[2]);
Checks the intersection between two rays.
The parameters I<aStart> and I<aDirection> describe the first ray.
The parameters I<bStart> and I<bDirection> describe the second ray.
The parameter I<t> describes the resulting intersection time of the first ray.
The parameter I<out> describes the resulting intersection point.
If successful, the function returns 0, otherwise it returns an error code.
=head2 BH_Ray2fIntersectSegment
int BH_Ray2fIntersectSegment(const float aStart[2],
const float aDirection[2],
const float bStart[2],
const float bEnd[2],
float *t,
float out[2]);
Checks the intersection between a ray and a segment.
The parameters I<aStart> and I<aDirection> describe the ray.
The parameters I<bStart> and I<bEnd> describe the segment.
The parameter I<t> describes the resulting intersection time of the ray.
The parameter I<out> describes the resulting intersection point.
If successful, the function returns 0, otherwise it returns an error code.
=head2 BH_Segment2fIntersectLine
int BH_Segment2fIntersectLine(const float start[2],
const float end[2],
const float line[3],
float *t,
float out[2]);
Checks the intersection between a segment and a line.
The parameters I<start> and I<end> describe the segment.
The parameter I<line> describes the line.
The parameter I<t> describes the resulting intersection time of the segment.
The parameter I<out> describes the resulting intersection point.
If successful, the function returns 0, otherwise it returns an error code.
=head2 BH_Segment2fIntersectSegment
int BH_Segment2fIntersectSegment(const float aStart[2],
const float aEnd[2],
const float bStart[2],
const float bEnd[2],
float *t,
float out[2]);
Checks the intersection between two segments.
The parameters I<aStart> and I<aEnd> describe the first segment.
The parameters I<bStart> and I<bEnd> describe the second segment.
The parameter I<t> describes the resulting intersection time of the first
segment.
The parameter I<out> describes the resulting intersection point.
If successful, the function returns 0, otherwise it returns an error code.
=head2 BH_Ray2fIntersectBox2f
int BH_Ray2fIntersectBox2f(const float aStart[2],
const float aDirection[2],
const float bMin[2],
const float bMax[2],
float *t,
float out[2]);
Checks the intersection between a ray and a bounding box.
The parameters I<aStart> and I<aDirection> describe the ray.
The parameters I<bMin> and I<bMax> describe the bounding box.
The parameter I<t> describes the resulting intersection time of the ray.
The parameter I<out> describes the resulting intersection point.
If successful, the function returns 0, otherwise it returns an error code.
=head2 BH_Segment2fIntersectBox2f
int BH_Segment2fIntersectBox2f(const float aStart[2],
const float aEnd[2],
const float bMin[2],
const float bMax[2],
float *t,
float out[2]);
Checks the intersection between a segment and a bounding box.
The parameters I<aStart> and I<aEnd> describe the segment.
The parameters I<bMin> and I<bMax> describe the bounding box.
The parameter I<t> describes the resulting intersection time of the segment.
The parameter I<out> describes the resulting intersection point.
If successful, the function returns 0, otherwise it returns an error code.
=head1 SEE ALSO
L<BH>

162
doc/Manual/en/BH_Ray3f.pod Normal file
View File

@@ -0,0 +1,162 @@
=encoding UTF-8
=head1 NAME
BH_Ray3f, BH_Segment3f - ray/segment in space
=head1 SYNTAX
#include <BH/Math/Ray3f.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
This module provides functions for working with rays and segments in
three-dimensional space. It includes methods for checking intersections of rays
and segments with planes, triangles, and bounding boxes.
=head1 API CALLS
=head2 BH_Ray3fIntersectPlane
int BH_Ray3fIntersectPlane(const float start[3],
const float direction[3],
const float plane[4],
float *t,
float out[3]);
Checks the intersection between a ray and a plane.
The parameters I<start> and I<direction> describe the ray.
The parameter I<plane> describes the plane.
The parameter I<t> describes the resulting time of the ray's intersection.
The parameter I<out> describes the resulting point of intersection.
In case of success, the function returns 0, in case of an error - an error code.
=head2 BH_Ray3fIntersectTriangle
int BH_Ray3fIntersectTriangle(const float start[3],
const float direction[3],
const float a[3],
const float b[3],
const float c[3],
float *t,
float out[3]);
Checks the intersection between a ray and a triangle.
The parameters I<start> and I<direction> describe the ray.
The parameters I<a>, I<b>, I<c> describe the points of the triangle.
The parameter I<t> describes the resulting time of the ray's intersection.
The parameter I<out> describes the resulting point of intersection.
In case of success, the function returns 0, in case of an error - an error code.
=head2 BH_Segment3fIntersectPlane
int BH_Segment3fIntersectPlane(const float start[3],
const float end[3],
const float plane[4],
float *t,
float out[3]);
Checks the intersection between a segment and a plane.
The parameters I<start> and I<end> describe the segment.
The parameter I<plane> describes the plane.
The parameter I<t> describes the resulting time of the segment's intersection.
The parameter I<out> describes the resulting point of intersection.
In case of success, the function returns 0, in case of an error - an error code.
=head2 BH_Segment3fIntersectTriangle
int BH_Segment3fIntersectTriangle(const float start[3],
const float end[3],
const float a[3],
const float b[3],
const float c[3],
float *t,
float out[3]);
Checks the intersection between a segment and a triangle.
The parameters I<start> and I<end> describe the segment.
The parameters I<a>, I<b>, I<c> describe the points of the triangle.
The parameter I<t> describes the resulting time of the ray's intersection.
The parameter I<out> describes the resulting point of intersection.
In case of success, the function returns 0, in case of an error - an error code.
=head2 BH_Ray3fIntersectBox3f
int BH_Ray3fIntersectBox3f(const float aStart[3],
const float aDirection[3],
const float bMin[3],
const float bMax[3],
float *t,
float out[3]);
Checks the intersection between a ray and a bounding box.
The parameters I<aStart> and I<aDirection> describe the ray.
The parameters I<bMin> and I<bMax> describe the bounding box.
The parameter I<t> describes the resulting time of the first segment's
intersection.
The parameter I<out> describes the resulting point of intersection.
In case of success, the function returns 0, in case of an error - an error code.
=head2 BH_Segment3fIntersectBox3f
int BH_Segment3fIntersectBox3f(const float aStart[3],
const float aEnd[3],
const float bMin[3],
const float bMax[3],
float *t,
float out[3]);
Checks the intersection between a segment and a bounding box.
The parameters I<aStart> and I<aEnd> describe the segment.
The parameters I<bMin> and I<bMax> describe the bounding box.
The parameter I<t> describes the resulting time of the first segment's
intersection.
The parameter I<out> describes the resulting point of intersection.
In case of success, the function returns 0, in case of an error - an error code.
=head1 SEE ALSO
L<BH>

382
doc/Manual/en/BH_String.pod Normal file
View File

@@ -0,0 +1,382 @@
=encoding UTF-8
=head1 NAME
BH_String - Working with strings
=head1 SYNTAX
#include <BH/Math.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_String library provides a set of functions for working with strings,
including converting numbers to strings and back.
=head1 DEFINING THE BASE
The functions of the I<StringToInt> family have an algorithm for determining the
base of a number by string prefixes:
=over
=item *
If the prefix I<0b>, then base 2
=item *
If the prefix I<0>, then base 8
=item *
If the prefix I<0x>, then base 16
=item *
Otherwise, base 10.
=back
=head1 API CALLS
=head2 BH_StringFromDouble
int BH_StringFromDouble(char *string,
size_t size,
double value,
char format,
int precision,
size_t *actual);
Formats a real number I<value> into a null-terminated string I<string>
(with a length limit of I<size>).
The I<format> parameter specifies the format for converting a number to a
string. Acceptable formats:
=over
=item B<f>, B<F>
Fixed format: [-]ddd.ddd
=item B<e>, B<E>
Scientific format: [-]d.dddedd
=item B<g>, B<G>
Fixed or scientific format, depending on which one is shorter.
=back
The I<precision> parameter sets the precision of converting a number to a
string. If the accuracy value is negative, the conversion will be performed with
the minimum required accuracy so that the reverse conversion results in the
original number.
The optional parameter I<actual> returns the length of the recorded string.
This function follows the IEEE 754 rule of rounding to an even number.
If successful, it returns 0 or an error code.
=head2 BH_StringFromInt8s
int BH_StringFromInt8s(char *string,
size_t size,
int8_t value,
int base,
size_t *actual);
Formats an 8-bit signed integer I<value> into a null-terminated string
I<string> (with a length limit of I<size>).
The I<base> parameter sets the base for the conversion.
The optional parameter I<actual> returns the length of the recorded string.
If successful, it returns 0 or an error code.
=head2 BH_StringFromInt16s
int BH_StringFromInt16s(char *string,
size_t size,
int16_t value,
int base,
size_t *actual);
Formats a 16-bit signed integer I<value> into a null-terminated string I<string>
(with a length limit of I<size>).
The I<base> parameter sets the base for the conversion.
The optional parameter I<actual> returns the length of the recorded string.
If successful, it returns 0 or an error code.
=head2 BH_StringFromInt32s
int BH_StringFromInt32s(char *string,
size_t size,
int32_t value,
int base,
size_t *actual);
Formats a 32-bit signed integer I<value> into a null-terminated string I<string>
(with a length limit of I<size>).
The I<base> parameter sets the base for the conversion.
The optional parameter I<actual> returns the length of the recorded string.
If successful, it returns 0 or an error code.
=head2 BH_StringFromInt64s
int BH_StringFromInt64s(char *string,
size_t size,
int64_t value,
int base,
size_t *actual);
Formats a 64-bit signed integer I<value> into a null-terminated string I<string>
(with a length limit of I<size>).
The I<base> parameter sets the base for the conversion.
The optional parameter I<actual> returns the length of the recorded string.
If successful, it returns 0 or an error code.
=head2 BH_StringFromInt8u
int BH_StringFromInt8u(char *string,
size_t size,
uint8_t value,
int base,
size_t *actual);
Formats an 8-bit unsigned integer I<value> into a null-terminated string
I<string> (with a length limit of I<size>).
The I<base> parameter sets the base for the conversion.
The optional parameter I<actual> returns the length of the recorded string.
If successful, it returns 0 or an error code.
=head2 BH_StringFromInt16u
int BH_StringFromInt16u(char *string,
size_t size,
uint16_t value,
int base,
size_t *actual);
Formats a 16-bit unsigned integer I<value> into a null-terminated string
I<string> (with a length limit of I<size>).
The I<base> parameter sets the base for the conversion.
The optional parameter I<actual> returns the length of the recorded string.
If successful, it returns 0 or an error code.
=head2 BH_StringFromInt32u
int BH_StringFromInt32u(char *string,
size_t size,
uint32_t value,
int base,
size_t *actual);
Formats a 32-bit unsigned integer I<value> into a null-terminated string
I<string> (with a length limit of I<size>).
The I<base> parameter sets the base for the conversion.
The optional parameter I<actual> returns the length of the recorded string.
If successful, it returns 0 or an error code.
=head2 BH_StringFromInt64u
int BH_StringFromInt64u(char *string,
size_t size,
uint64_t value,
int base,
size_t *actual);
Formats a 64-bit unsigned integer I<value> into a null-terminated string
I<string> (with a length limit of I<size>).
The I<base> parameter sets the base for the conversion.
The optional parameter I<actual> returns the length of the recorded string.
If successful, it returns 0 or an error code.
=head2 BH_StringToDouble
double BH_StringToDouble(const char *string,
size_t *size);
Converts the string I<string> to a real number.
The optional parameter I<size> returns the number of characters read from the
string.
If successful, it returns the converted number or 0.
=head2 BH_StringToInt8s
int8_t BH_StringToInt8s(const char *string,
size_t *size,
int base);
Converts the string I<string> to an 8-bit signed integer.
The optional parameter I<size> returns the number of characters read from the
string.
The optional parameter I<base> specifies the base of the number.
If successful, it returns the converted number or 0.
=head2 BH_StringToInt16s
int16_t BH_StringToInt16s(const char *string,
size_t *size,
int base);
Converts the string I<string> to a signed 16-bit integer.
The optional parameter I<size> returns the number of characters read from the
string.
The optional parameter I<base> specifies the base of the number.
If successful, it returns the converted number or 0.
=head2 BH_StringToInt32s
int32_t BH_StringToInt32s(const char *string,
size_t *size,
int base);
Converts the string I<string> to a signed 32-bit integer.
The optional parameter I<size> returns the number of characters read from the
string.
The optional parameter I<base> specifies the base of the number.
If successful, it returns the converted number or 0.
=head2 BH_StringToInt64s
int64_t BH_StringToInt64s(const char *string,
size_t *size,
int base);
Converts the string I<string> to a signed 64-bit integer.
The optional parameter I<size> returns the number of characters read from the
string.
The optional parameter I<base> specifies the base of the number.
If successful, it returns the converted number or 0.
=head2 BH_StringToInt8u
uint8_t BH_StringToInt8u(const char *string,
size_t *size,
int base);
Converts the string I<string> to an unsigned 8-bit integer.
The optional parameter I<size> returns the number of characters read from the
string.
The optional parameter I<base> specifies the base of the number.
If successful, it returns the converted number or 0.
=head2 BH_StringToInt16u
uint16_t BH_StringToInt16u(const char *string,
size_t *size,
int base);
Converts the string I<string> to an unsigned 16-bit integer.
The optional parameter I<size> returns the number of characters read from the
string.
The optional parameter I<base> specifies the base of the number.
If successful, it returns the converted number or 0.
=head2 BH_StringToInt32u
uint32_t BH_StringToInt32u(const char *string,
size_t *size,
int base);
Converts the string I<string> to an unsigned 32-bit integer.
The optional parameter I<size> returns the number of characters read from the
string.
The optional parameter I<base> specifies the base of the number.
If successful, it returns the converted number or 0.
=head2 BH_StringToInt64u
uint64_t BH_StringToInt64u(const char *string,
size_t *size,
int base);
Converts the string I<string> to an unsigned 64-bit integer.
The optional parameter I<size> returns the number of characters read from the
string.
The optional parameter I<base> specifies the base of the number.
If successful, it returns the converted number or 0.
=head1 SEE ALSO
L<BH>

289
doc/Manual/en/BH_Thread.pod Normal file
View File

@@ -0,0 +1,289 @@
=encoding UTF-8
=head1 NAME
BH_Thread - multithreading and synchronization primitives
=head1 SYNTAX
#include <BH/Thread.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Thread library provides a set of functions for working with
multithreading and thread synchronization. It includes functions for creating
and managing threads, working with mutexes, semaphores, condition variables, and
spinlocks.
=head1 API CALLS
=head2 BH_ThreadNew
BH_Thread *BH_ThreadNew(size_t stack,
BH_ThreadCallback callback,
void *data);
Creates a thread with a specified stack size I<stack>, execution function
I<callback>, and data I<data>.
Returns a pointer to the thread object on success, otherwise NULL.
=head2 BH_ThreadJoin
int BH_ThreadJoin(BH_Thread *thread);
Blocks the execution of the current thread until another thread completes.
Upon completion of the thread, the resources of the I<thread> are freed.
Returns 0 on success, otherwise an error code.
=head2 BH_ThreadDetach
int BH_ThreadDetach(BH_Thread *thread);
Detaches the thread from the current process.
Upon completion of the thread, the resources of the I<thread> are freed.
Returns 0 on success, otherwise an error code.
=head2 BH_MutexNew
BH_Mutex *BH_MutexNew(void);
Creates a mutex.
Returns a pointer to the mutex object on success, otherwise NULL.
=head2 BH_MutexFree
void BH_MutexFree(BH_Mutex *mutex);
Destroys the mutex.
If the mutex is locked, the behavior is undefined.
=head2 BH_MutexLock
int BH_MutexLock(BH_Mutex *mutex);
Locks the mutex.
If the mutex is already locked, the behavior is undefined.
Returns 0 on success, otherwise an error code.
=head2 BH_MutexUnlock
int BH_MutexUnlock(BH_Mutex *mutex);
Unlocks the mutex.
If the mutex is locked by another thread, the behavior is undefined.
Returns 0 on success, otherwise an error code.
=head2 BH_MutexLockTry
int BH_MutexLockTry(BH_Mutex *mutex);
Attempts to lock the mutex.
Returns 0 on success, otherwise an error code.
=head2 BH_SemaphoreNew
BH_Semaphore *BH_SemaphoreNew(int value);
Creates a semaphore with a specified initial value I<value>.
Returns a pointer to the semaphore object on success, otherwise NULL.
=head2 BH_SemaphoreFree
void BH_SemaphoreFree(BH_Semaphore *semaphore);
Destroys the semaphore.
=head2 BH_SemaphorePost
int BH_SemaphorePost(BH_Semaphore *semaphore);
Increases the semaphore value by 1.
Returns 0 on success, otherwise an error code.
=head2 BH_SemaphoreWait
int BH_SemaphoreWait(BH_Semaphore *semaphore);
Decreases the semaphore value by 1.
If the semaphore value is 0, blocks the execution of the current thread until
the semaphore value becomes greater than 0.
Returns 0 on success, otherwise an error code.
=head2 BH_SemaphoreWaitTry
int BH_SemaphoreWaitTry(BH_Semaphore *semaphore);
Attempts to decrease the semaphore value by 1.
Returns 0 on success, otherwise an error code.
=head2 BH_SemaphoreWaitFor
int BH_SemaphoreWaitFor(BH_Semaphore *semaphore,
uint32_t timeout);
Attempts to decrease the semaphore value by 1 within a specified time
I<timeout>.
The I<timeout> parameter specifies the waiting time in milliseconds.
Returns 0 on success, otherwise an error code.
=head2 BH_ConditionNew
BH_Condition *BH_ConditionNew(void);
Creates a new condition variable.
Returns a pointer to the condition variable object on success, otherwise NULL.
=head2 BH_ConditionFree
void BH_ConditionFree(BH_Condition *condition);
Destroys the condition variable.
If the condition variable is used by other threads, the behavior is undefined.
=head2 BH_ConditionWait
int BH_ConditionWait(BH_Condition *condition,
BH_Mutex *mutex);
Blocks the execution of the current thread until another thread signals
a change in the condition.
In some situations, the signal of a condition change may be false.
The I<mutex> parameter specifies the mutex used in conjunction with the
condition variable.
Returns 0 on success, otherwise an error code.
=head2 BH_ConditionWaitFor
int BH_ConditionWaitFor(BH_Condition *condition,
BH_Mutex *mutex,
uint32_t timeout);
Attempts to block the execution of the current thread until another thread
signals a change in the condition within a specified time I<timeout>.
In some situations, the signal of a condition change may be false.
The I<mutex> parameter specifies the mutex used in conjunction with the
condition variable.
The I<timeout> parameter specifies the waiting time in milliseconds.
Returns 0 on success, otherwise an error code.
=head2 BH_ConditionSignal
int BH_ConditionSignal(BH_Condition *condition);
Signals one waiting thread about a change in the condition.
Returns 0 on success, otherwise an error code.
=head2 BH_ConditionBroadcast
int BH_ConditionBroadcast(BH_Condition *condition);
Signals all waiting threads about a change in the condition.
Returns 0 on success, otherwise an error code.
=head2 BH_SpinlockLock
void BH_SpinlockLock(int *lock);
Locks the spinlock.
=head2 BH_SpinlockLockTry
int BH_SpinlockLockTry(int *lock);
Attempts to lock the spinlock.
Returns 0 on success, otherwise an error code.
=head2 BH_SpinlockUnlock
void BH_SpinlockUnlock(int *lock);
Unlocks the spinlock.
=head2 BH_TssCreate
int BH_TssCreate(BH_GenericCallback callback);
Creates a new TSS/TLS index with a cleanup function I<callback>.
Returns the TSS/TLS index on success, otherwise an error code.
=head2 BH_TssRead
void *BH_TssRead(int index);
Reads data from the TSS/TLS slot.
=head2 BH_TssWrite
void BH_TssWrite(int index,
void *value);
Writes data I<value> to the TSS/TLS slot.
=head1 SEE ALSO
L<BH>

View File

@@ -0,0 +1,184 @@
=encoding UTF-8
=head1 NAME
BH_Unicode - Working with Unicode and UTF encodings
=head1 SYNTAX
#include <BH/Math.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Unicode library provides a set of functions for working with various
Unicode encodings, including UTF-8, UTF-16, and UTF-32. It allows you to
convert characters to uppercase and lowercase, as well as encode and decode
strings in the specified encodings.
=head1 API CALLS
=head2 BH_UnicodeLower
uint32_t BH_UnicodeLower(uint32_t unit);
Converts the Unicode code I<unit> to lowercase.
The conversion is performed for characters in the Basic Multilingual Plane
(i.e., the first 65,536 codes).
=head2 BH_UnicodeUpper
uint32_t BH_UnicodeUpper(uint32_t unit);
Converts the Unicode code I<unit> to uppercase.
The conversion is performed for characters in the Basic Multilingual Plane
(i.e., the first 65,536 codes).
=head2 BH_UnicodeDecodeUtf8
size_t BH_UnicodeDecodeUtf8(const char *string,
size_t size,
uint32_t *unit);
Decodes the UTF-8 sequence from I<string> (with the specified length I<size>)
and writes the code to I<unit>.
Invalid UTF-8 sequences will be converted to code -1.
If successful, the function returns the number of bytes read or 0 if I<string>
contains only part of the sequence.
=head2 BH_UnicodeEncodeUtf8
size_t BH_UnicodeEncodeUtf8(uint32_t unit,
char *string);
Encodes the UTF-8 sequence into I<string> from the code I<unit>.
It is assumed that the string contains 4 bytes of free space.
If successful, the function returns the number of bytes written or 0.
=head2 BH_UnicodeDecodeUtf16LE
size_t BH_UnicodeDecodeUtf16LE(const char *string,
size_t size,
uint32_t *unit);
Decodes the UTF-16LE sequence from I<string> (with the specified length I<size>)
and writes the code to I<unit>.
Invalid UTF-16LE sequences will be converted to code -1.
If successful, the function returns the number of bytes read or 0 if I<string>
contains only part of the sequence.
=head2 BH_UnicodeDecodeUtf16BE
size_t BH_UnicodeDecodeUtf16BE(const char *string,
size_t size,
uint32_t *unit);
Decodes the UTF-16BE sequence from I<string> (with the specified length I<size>)
and writes the code to I<unit>.
Invalid UTF-16BE sequences will be converted to code -1.
If successful, the function returns the number of bytes read or 0 if I<string>
contains only part of the sequence.
=head2 BH_UnicodeEncodeUtf16LE
size_t BH_UnicodeEncodeUtf16LE(uint32_t unit,
char *string);
Encodes the UTF-16LE sequence into I<string> from the code I<unit>.
It is assumed that the string contains 4 bytes of free space.
If successful, the function returns the number of bytes written or 0.
=head2 BH_UnicodeEncodeUtf16BE
size_t BH_UnicodeEncodeUtf16BE(uint32_t unit,
char *string);
Encodes the UTF-16BE sequence into I<string> from the code I<unit>.
It is assumed that the string contains 4 bytes of free space.
If successful, the function returns the number of bytes written or 0.
=head2 BH_UnicodeDecodeUtf32LE
size_t BH_UnicodeDecodeUtf32LE(const char *string,
size_t size,
uint32_t *unit);
Decodes the UTF-32LE sequence from I<string> (with the specified length I<size>)
and writes the code to I<unit>.
Invalid UTF-32LE sequences will be converted to code -1.
If successful, the function returns the number of bytes read or 0 if I<string>
contains only part of the sequence.
=head2 BH_UnicodeDecodeUtf32BE
size_t BH_UnicodeDecodeUtf32BE(const char *string,
size_t size,
uint32_t *unit);
Decodes the UTF-32BE sequence from I<string> (with the specified length I<size>)
and writes the code to I<unit>.
Invalid UTF-32BE sequences will be converted to code -1.
If successful, the function returns the number of bytes read or 0 if I<string>
contains only part of the sequence.
=head2 BH_UnicodeEncodeUtf32LE
size_t BH_UnicodeEncodeUtf32LE(uint32_t unit,
char *string);
Encodes the UTF-32LE sequence into I<string> from the code I<unit>.
It is assumed that the string contains 4 bytes of free space.
If successful, the function returns the number of bytes written or 0.
=head2 BH_UnicodeEncodeUtf32BE
size_t BH_UnicodeEncodeUtf32BE(uint32_t unit,
char *string);
Encodes the UTF-32BE sequence into I<string> from the code I<unit>.
It is assumed that the string contains 4 bytes of free space.
If successful, the function returns the number of bytes written or 0.
=head1 SEE ALSO
L<BH>

241
doc/Manual/en/BH_Util.pod Normal file
View File

@@ -0,0 +1,241 @@
=encoding UTF-8
=head1 NAME
BH_Util - Utility Functions
=head1 SYNTAX
#include <BH/Math.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Util library provides a set of functions for working with numbers in
little-endian and big-endian formats, as well as for classifying floating-point
values.
=head1 API CALLS
=head2 BH_ClassifyDouble
int BH_ClassifyDouble(double value);
Classifies a floating-point value.
This function returns a combination of the following values:
=over
=item B<BH_FP_NORMAL>
The value is normal or subnormal.
=item B<BH_FP_ZERO>
The value is positive or negative zero.
=item B<BH_FP_INFINITE>
The value is positive or negative infinity.
=item B<BH_FP_NAN>
The value is not a number (NaN).
=item B<BH_FP_NEGATIVE>
The value is negative.
=back
=head2 BH_Read16LEu
uint16_t BH_Read16LEu(const char *buffer);
Reads an unsigned 16-bit little-endian integer from the buffer.
=head2 BH_Read16LEs
int16_t BH_Read16LEs(const char *buffer);
Reads a signed 16-bit little-endian integer from the buffer.
=head2 BH_Read32LEu
uint32_t BH_Read32LEu(const char *buffer);
Reads an unsigned 32-bit little-endian integer from the buffer.
=head2 BH_Read32LEs
int32_t BH_Read32LEs(const char *buffer);
Reads a signed 32-bit little-endian integer from the buffer.
=head2 BH_Read64LEu
uint64_t BH_Read64LEu(const char *buffer);
Reads an unsigned 64-bit little-endian integer from the buffer.
=head2 BH_Read64LEs
int64_t BH_Read64LEs(const char *buffer);
Reads a signed 64-bit little-endian integer from the buffer.
=head2 BH_Read16BEu
uint16_t BH_Read16BEu(const char *buffer);
Reads an unsigned 16-bit big-endian integer from the buffer.
=head2 BH_Read16BEs
int16_t BH_Read16BEs(const char *buffer);
Reads a signed 16-bit big-endian integer from the buffer.
=head2 BH_Read32BEu
uint32_t BH_Read32BEu(const char *buffer);
Reads an unsigned 32-bit big-endian integer from the buffer.
=head2 BH_Read32BEs
int32_t BH_Read32BEs(const char *buffer);
Reads a signed 32-bit big-endian integer from the buffer.
=head2 BH_Read64BEu
uint64_t BH_Read64BEu(const char *buffer);
Reads an unsigned 64-bit big-endian integer from the buffer.
=head2 BH_Read64BEs
int64_t BH_Read64BEs(const char *buffer);
Reads a signed 64-bit big-endian integer from the buffer.
=head2 BH_Write16LEu
void BH_Write16LEu(char *buffer,
uint16_t value);
Writes an unsigned 16-bit little-endian integer to the buffer.
=head2 BH_Write16LEs
void BH_Write16LEs(char *buffer,
int16_t value);
Writes a signed 16-bit little-endian integer to the buffer.
=head2 BH_Write32LEu
void BH_Write32LEu(char *buffer,
uint32_t value);
Writes an unsigned 32-bit little-endian integer to the buffer.
=head2 BH_Write32LEs
void BH_Write32LEs(char *buffer,
int32_t value);
Writes a signed 32-bit little-endian integer to the buffer.
=head2 BH_Write64LEu
void BH_Write64LEu(char *buffer,
uint64_t value);
Writes an unsigned 64-bit little-endian integer to the buffer.
=head2 BH_Write64LEs
void BH_Write64LEs(char *buffer,
int64_t value);
Writes a signed 64-bit little-endian integer to the buffer.
=head2 BH_Write16BEu
void BH_Write16BEu(char *buffer,
uint16_t value);
Writes an unsigned 16-bit big-endian integer to the buffer.
=head2 BH_Write16BEs
void BH_Write16BEs(char *buffer,
int16_t value);
Writes a signed 16-bit big-endian integer to the buffer.
=head2 BH_Write32BEu
void BH_Write32BEu(char *buffer,
uint32_t value);
Writes an unsigned 32-bit big-endian integer to the buffer.
=head2 BH_Write32BEs
void BH_Write32BEs(char *buffer,
int32_t value);
Writes a signed 32-bit big-endian integer to the buffer.
=head2 BH_Write64BEu
void BH_Write64BEu(char *buffer,
uint64_t value);
Writes an unsigned 64-bit big-endian integer to the buffer.
=head2 BH_Write64BEs
void BH_Write64BEs(char *buffer,
int64_t value);
Writes a signed 64-bit big-endian integer to the buffer.
=head1 SEE ALSO
L<BH>

200
doc/Manual/en/BH_Vec2f.pod Normal file
View File

@@ -0,0 +1,200 @@
=encoding UTF-8
=head1 NAME
BH_Vec2f - two-dimensional real vector
=head1 SYNTAX
#include <BH/Math/Vec2f.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Vec2f module provides a set of functions for working with two-dimensional
vectors. It includes operations for addition, subtraction, multiplication,
scaling, calculating the dot and cross product, as well as normalizing vectors.
=head1 API CALLS
=head2 BH_Vec2fAdd
void BH_Vec2fAdd(const float a[2],
const float b[2],
float out[2]);
Calculates the sum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2fSub
void BH_Vec2fSub(const float a[2],
const float b[2],
float out[2]);
Calculates the difference between two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2fMul
void BH_Vec2fMul(const float a[2],
const float b[2],
float out[2]);
Calculates the result of multiplying two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2fScale
void BH_Vec2fScale(const float a[2],
float b,
float out[2]);
Calculates the result of multiplying vector I<a> by value I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2fMulAdd
void BH_Vec2fMulAdd(const float a[2],
const float b[2],
const float c[2],
float out[2]);
Calculates the result of the sum I<c> and the product of vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2fNegate
void BH_Vec2fNegate(const float in[2],
float out[2]);
Calculates the opposite vector from vector I<in>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2fDot
float BH_Vec2fDot(const float a[2],
const float b[2]);
Calculates the dot product of vectors I<a> and I<b>.
=head2 BH_Vec2fCross
float BH_Vec2fCross(const float a[2],
const float b[2]);
Calculates the cross product of vectors I<a> and I<b>.
=head2 BH_Vec2fLength
float BH_Vec2fLength(const float in[2]);
Calculates the length of vector I<in>.
=head2 BH_Vec2fNormal
void BH_Vec2fNormal(const float in[2],
float out[2]);
Calculates the normalized form of vector I<in>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2fNormalEx
float BH_Vec2fNormalEx(const float in[2],
float out[2]);
Calculates the normalized form of vector I<in> and returns its original length.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2fMin
void BH_Vec2fMin(const float a[2],
const float b[2],
float out[2]);
Calculates the element-wise minimum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2fMax
void BH_Vec2fMax(const float a[2],
const float b[2],
float out[2]);
Calculates the element-wise maximum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2fLerp
void BH_Vec2fLerp(const float a[2],
const float b[2],
float t,
float out[2]);
Performs linear interpolation between two vectors I<a> and I<b> with parameter
I<t>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2fProject
void BH_Vec2fProject(const float a[2],
const float b[2],
float out[2]);
Calculates the result of projecting vector I<a> onto vector I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2fBarycentric
void BH_Vec2fBarycentric(const float a[2],
const float b[2],
const float c[2],
float v,
float w,
float out[2]);
Calculates the vector from the barycentric coordinates I<v>, I<w> and vectors of
points I<a>, I<b>, I<c>.
The calculation is performed using the formula A + v*(B-A) + w*(C-A).
The I<out> parameter describes the resulting vector.
=head1 SEE ALSO
L<BH>

116
doc/Manual/en/BH_Vec2i.pod Normal file
View File

@@ -0,0 +1,116 @@
=encoding UTF-8
=head1 NAME
BH_Vec2i - two-dimensional integer vector
=head1 SYNTAX
#include <BH/Math.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Vec2i module provides a set of functions for working with two-dimensional
integer vectors.
=head1 API CALLS
=head2 BH_Vec2iAdd
void BH_Vec2iAdd(const int a[2],
const int b[2],
int out[2]);
Calculates the sum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2iSub
void BH_Vec2iSub(const int a[2],
const int b[2],
int out[2]);
Calculates the difference between two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2iMul
void BH_Vec2iMul(const int a[2],
const int b[2],
int out[2]);
Calculates the result of multiplying two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2iScale
void BH_Vec2iScale(const int a[2],
int b,
int out[2]);
Calculates the result of multiplying vector I<a> by value I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2iMulAdd
void BH_Vec2iMulAdd(const int a[2],
const int b[2],
const int c[2],
int out[2]);
Calculates the result of the sum I<c> and the result of multiplying vectors I<a>
and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2iNegate
void BH_Vec2iNegate(const int in[2],
int out[2]);
Calculates the opposite vector from vector I<in>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2iMin
void BH_Vec2iMin(const int a[2],
const int b[2],
int out[2]);
Calculates the element-wise minimum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec2iMax
void BH_Vec2iMax(const int a[2],
const int b[2],
int out[2]);
Calculates the element-wise maximum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head1 SEE ALSO
L<BH>

203
doc/Manual/en/BH_Vec3f.pod Normal file
View File

@@ -0,0 +1,203 @@
=encoding UTF-8
=head1 NAME
BH_Vec3f - three-dimensional real vector
=head1 SYNTAX
#include <BH/Math.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Vec3f module provides a set of functions for working with
three-dimensional vectors. The functions allow performing arithmetic operations,
calculating scalar and vector products, normalizing vectors, and performing
other vector operations.
=head1 API CALLS
=head2 BH_Vec3fAdd
void BH_Vec3fAdd(const float a[3],
const float b[3],
float out[3]);
Calculates the sum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3fSub
void BH_Vec3fSub(const float a[3],
const float b[3],
float out[3]);
Calculates the difference between two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3fMul
void BH_Vec3fMul(const float a[3],
const float b[3],
float out[3]);
Calculates the result of multiplying two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3fScale
void BH_Vec3fScale(const float a[3],
float b,
float out[3]);
Calculates the result of multiplying vector I<a> by value I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3fMulAdd
void BH_Vec3fMulAdd(const float a[3],
const float b[3],
const float c[3],
float out[3]);
Calculates the result of the sum I<c> and the result of multiplying vectors I<a>
and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3fNegate
void BH_Vec3fNegate(const float in[3],
float out[3]);
Calculates the opposite vector from vector I<in>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3fDot
float BH_Vec3fDot(const float a[3],
const float b[3]);
Calculates the dot product of vectors I<a> and I<b>.
=head2 BH_Vec3fCross
void BH_Vec3fCross(const float a[3],
const float b[3],
float out[3]);
Calculates the cross product of vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3fLength
float BH_Vec3fLength(const float in[3]);
Calculates the length of vector I<in>.
=head2 BH_Vec3fNormal
void BH_Vec3fNormal(const float in[3],
float out[3]);
Calculates the normalized form of vector I<in>.
=head2 BH_Vec3fNormalEx
float BH_Vec3fNormalEx(const float in[3],
float out[3]);
Calculates the normalized form of vector I<in> and returns its original length.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3fMin
void BH_Vec3fMin(const float a[3],
const float b[3],
float out[3]);
Calculates the element-wise minimum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3fMax
void BH_Vec3fMax(const float a[3],
const float b[3],
float out[3]);
Calculates the element-wise maximum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3fLerp
void BH_Vec3fLerp(const float a[3],
const float b[3],
float t,
float out[3]);
Performs linear interpolation between two vectors I<a> and I<b> with parameter
I<t>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3fProject
void BH_Vec3fProject(const float a[3],
const float b[3],
float out[3]);
Calculates the result of projecting vector I<a> onto vector I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3fBarycentric
void BH_Vec3fBarycentric(const float a[3],
const float b[3],
const float c[3],
float v,
float w,
float out[3]);
Calculates the vector from barycentric coordinates I<v>, I<w> and vectors of
points I<a>, I<b>, I<c>.
The calculation is performed using the formula A + v*(B-A) + w*(C-A).
The I<out> parameter describes the resulting vector.
=head1 SEE ALSO
L<BH>

116
doc/Manual/en/BH_Vec3i.pod Normal file
View File

@@ -0,0 +1,116 @@
=encoding UTF-8
=head1 NAME
BH_Vec3i - three-dimensional integer vector
=head1 SYNTAX
#include <BH/Math.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Vec3i module provides a set of functions for working with
three-dimensional integer vectors.
=head1 API CALLS
=head2 BH_Vec3iAdd
void BH_Vec3iAdd(const int a[3],
const int b[3],
int out[3]);
Calculates the sum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3iSub
void BH_Vec3iSub(const int a[3],
const int b[3],
int out[3]);
Calculates the difference between two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3iMul
void BH_Vec3iMul(const int a[3],
const int b[3],
int out[3]);
Calculates the result of multiplying two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3iScale
void BH_Vec3iScale(const int a[3],
int b,
int out[3]);
Calculates the result of multiplying vector I<a> by value I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3iMulAdd
void BH_Vec3iMulAdd(const int a[3],
const int b[3],
const int c[3],
int out[3]);
Calculates the result of the sum I<c> and the result of multiplying vectors
I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3iNegate
void BH_Vec3iNegate(const int in[3],
int out[3]);
Calculates the opposite vector from vector I<in>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3iMin
void BH_Vec3iMin(const int a[3],
const int b[3],
int out[3]);
Calculates the element-wise minimum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec3iMax
void BH_Vec3iMax(const int a[3],
const int b[3],
int out[3]);
Calculates the element-wise maximum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head1 SEE ALSO
L<BH>

194
doc/Manual/en/BH_Vec4f.pod Normal file
View File

@@ -0,0 +1,194 @@
=encoding UTF-8
=head1 NAME
BH_Vec4f - four-dimensional real vector
=head1 SYNTAX
#include <BH/Math.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Vec4f module provides a set of functions for working with
four-dimensional vectors. The functions allow performing arithmetic operations,
normalization, calculating the dot product, and other mathematical operations
on vectors.
=head1 API CALLS
=head2 BH_Vec4fAdd
void BH_Vec4fAdd(const float a[4],
const float b[4],
float out[4]);
Calculates the sum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4fSub
void BH_Vec4fSub(const float a[4],
const float b[4],
float out[4]);
Calculates the difference between two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4fMul
void BH_Vec4fMul(const float a[4],
const float b[4],
float out[4]);
Calculates the result of multiplying two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4fScale
void BH_Vec4fScale(const float a[4],
float b,
float out[4]);
Calculates the result of multiplying vector I<a> by value I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4fMulAdd
void BH_Vec4fMulAdd(const float a[4],
const float b[4],
const float c[4],
float out[4]);
Calculates the result of the sum I<c> and the result of multiplying vectors I<a>
and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4fNegate
void BH_Vec4fNegate(const float in[4],
float out[4]);
Calculates the opposite vector from vector I<in>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4fDot
float BH_Vec4fDot(const float a[4],
const float b[4]);
Calculates the dot product of vectors I<a> and I<b>.
=head2 BH_Vec4fLength
float BH_Vec4fLength(const float in[4]);
Calculates the length of vector I<in>.
=head2 BH_Vec4fNormal
void BH_Vec4fNormal(const float in[4],
float out[4]);
Calculates the normalized form of vector I<in>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4fNormalEx
float BH_Vec4fNormalEx(const float in[4],
float out[4]);
Calculates the normalized form of vector I<in> and returns its original length.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4fMin
void BH_Vec4fMin(const float a[4],
const float b[4],
float out[4]);
Calculates the element-wise minimum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4fMax
void BH_Vec4fMax(const float a[4],
const float b[4],
float out[4]);
Calculates the element-wise maximum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4fLerp
void BH_Vec4fLerp(const float a[4],
const float b[4],
float t,
float out[4]);
Performs linear interpolation between two vectors I<a> and I<b> with parameter
I<t>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4fProject
void BH_Vec4fProject(const float a[4],
const float b[4],
float out[4]);
Calculates the result of projecting vector I<a> onto vector I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4fBarycentric
void BH_Vec4fBarycentric(const float a[4],
const float b[4],
const float c[4],
float v,
float w,
float out[4]);
Calculates the vector from barycentric coordinates I<v>, I<w> and vectors of
points I<a>, I<b>, I<c>.
The calculation is performed using the formula A + v*(B-A) + w*(C-A).
The I<out> parameter describes the resulting vector.
=head1 SEE ALSO
L<BH>

116
doc/Manual/en/BH_Vec4i.pod Normal file
View File

@@ -0,0 +1,116 @@
=encoding UTF-8
=head1 NAME
BH_Vec4i - four-dimensional integer vector
=head1 SYNTAX
#include <BH/Math.h>
cc prog.c -o prog -lbh
=head1 DESCRIPTION
The BH_Vec4i module provides a set of functions for working with
four-dimensional integer vectors.
=head1 API CALLS
=head2 BH_Vec4iAdd
void BH_Vec4iAdd(const int a[4],
const int b[4],
int out[4]);
Calculates the sum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4iSub
void BH_Vec4iSub(const int a[4],
const int b[4],
int out[4]);
Calculates the difference between two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4iMul
void BH_Vec4iMul(const int a[4],
const int b[4],
int out[4]);
Calculates the result of multiplying two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4iScale
void BH_Vec4iScale(const int a[4],
int b,
int out[4]);
Calculates the result of multiplying vector I<a> by value I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4iMulAdd
void BH_Vec4iMulAdd(const int a[4],
const int b[4],
const int c[4],
int out[4]);
Calculates the result of the sum I<c> and the result of multiplying vectors I<a>
and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4iNegate
void BH_Vec4iNegate(const int in[4],
int out[4]);
Calculates the opposite vector from vector I<in>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4iMin
void BH_Vec4iMin(const int a[4],
const int b[4],
int out[4]);
Calculates the element-wise minimum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head2 BH_Vec4iMax
void BH_Vec4iMax(const int a[4],
const int b[4],
int out[4]);
Calculates the element-wise maximum of two vectors I<a> and I<b>.
The I<out> parameter describes the resulting vector.
=head1 SEE ALSO
L<BH>