Skip to content

Commit

Permalink
prep
Browse files Browse the repository at this point in the history
  • Loading branch information
al1-ce committed May 5, 2024
1 parent 6b3af50 commit 84d4693
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ bin/
.dub
docs.json
__dummy.html
docs/
generated-docs/
skeleton.html
dub.selections.json

# Code coverage
*.lst
6 changes: 0 additions & 6 deletions .pre-commit-config.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Upstream-Name: sily
Upstream-Contact: Alisa Lain <[email protected]>
Source: https://github.com/al1-ce/sily

Files: test/* readme/*
Files: test/* readme/* docs/*
Copyright: (C) 2022 Alisa Lain <[email protected]>
License: GPL-3.0-or-later

Expand Down
114 changes: 2 additions & 112 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,9 @@ sily is a general-purpose library containing utilities for general programming a
[![Build](https://github.com/al1-ce/sily/actions/workflows/d.yml/badge.svg)](https://github.com/al1-ce/sily/actions/workflows/d.yml)
[![REUSE Compliance Check](https://github.com/al1-ce/sily/actions/workflows/reuse.yml/badge.svg)](https://github.com/al1-ce/sily/actions/workflows/reuse.yml)

## Modules
- [sily](readme/wiki/core.md) - Core utilities
- [sdl](readme/wiki/sdl.md) - Parser for SDLang with minor modifications
- [term](readme/wiki/term.md) - Tools for working with posix terminal
- [web](readme/wiki/web.md) - *Unfinished* parser for html/css

## Usage
Using `dub.sdl` (replace `x.x.x` with latest release version)

```sdl
dependency "sily" version="~>x.x.x"
```

For particular usage see [Modules](#modules)
Documentation can be found [here](https://al1-ce.github.io/sily-docs/)

## Development
- [dmd / ldc / gdc](https://dlang.org/) - D compiler
Expand All @@ -28,110 +17,11 @@ For particular usage see [Modules](#modules)
- [reuse](https://reuse.software/) - See [License](#license)

## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md).
See [CONTRIBUTING.md](/CONTRIBUTING.md).

## License
- Copy of used licenses can be found in `LICENSES` folder. Main license can be found in [LICENSE](LICENSE) file.
- List of authors can be found in [AUTHORS.md](/AUTHORS.md).

This project is [REUSE](https://reuse.software/) compliant.


* sily - Core utils

## core
* `sily.color` and `sily.vector`: Contains color and templated vector structs with utils
```d
// Vector can be constructed manually or with aliases
auto v1 = Vector!(int, 2)(10, 20);
auto v2 = ivec2(10, 20);
auto v3 = ivec2(10, 20);
auto v4 = vec2!int(10, 20);
// Also vector can be given only one value,
// in that case it'll be filled with that value
auto v5 = ivec4(13);
auto v6 = vec4(0.3f);
// Vector values can be accessed with array slicing,
// by using color symbols or swizzling
float v6x = v6.x;
float v6z = v6.z;
float[] v6yzx = v6.yzx;
auto rvec7 = Vector!(real, 7)(10);
auto rvec7s = rvec7.VecType(20);
col c = col(3, 4, 1, 2);
col d = c.brg;
col g = Colors.aquamarine;
vec4 v = d;
vec4 e = v.xyyz;
string code = g.toAnsiString();
```
Color can be converted to bash escape sequence to set/print colors in Ansi8, Ansi256 and TrueColor modes.

![](readme/color.png)

* `sily.getopt`: Contains custom getopt printer:
```d
help = getopt(
args,
config.bundling, config.passThrough, std.getopt.config.caseSensitive,
"columns|c", "Sets width/columns", &conf.width,
"rows|r", "Sets height/rows", &conf.height,
"size|s", "Matches size. Must be \'width\', \'height\' or \'fit\'", &conf.size,
"color|C", "Sets color type. Must be \'ansi8\', \'ansi256\', \'truecolor\'", &conf.color,
);
if (help.helpWanted || args.length == 1) {
printGetopt(
"Usage: app [args] file",
"Size",
help.options[0..3],
"Colors",
help.options[3],
"Misc",
customOption("options", "Returns options")
);
return 0;
}
```
Converts into:
```
Usage: app [args] image-file
Size:
-c, --columns Sets width/columns
-r, --rows Sets height/rows
-s, --size Matches size. Must be 'width', 'height' or 'fit'
Colors:
-C, --color Sets color type. Must be 'ansi8', 'ansi256', 'truecolor'
Misc:
options Returns options
```

* `sily.array`: Array manipulation (fill, search)
* `sily.async`: Async (timer, promise) utils
* `sily.clang`: Utils to work with C bindings (plus `sily.ptr`)
* `sily.conv`: Streamlined conversion
* `sily.curl`: JS-like http requests
* `sily.file`: File manipulation
* `sily.math`: Misc math utils
* `sily.matrix`: Matrix math
* `sily.meta.enums`: Unwraps enums
* `sily.meta.swizzle`: Swizzling used by `sily.vector` and `sily.color`. `sily.meta` itself is empty
* `sily.path`: Path manipulation
* `sily.property`: Template mixin to generate properties
* `sily.ptr`: Pointer conversion
* `sily.quat`: Quaternion math
* `sily.queue`: FCFS queue container
* `sily.random`: std.random wrapper
* `sily.stack`: LCFS stack container
* `sily.stdio`: Stdio wrapper
* `sily.string`: String manipulation
* `sily.thread`: Thread wrapper
* `sily.time`: Time wrapper
* `sily.uid`: UID generator
* `sily.uni`: `std.uni` alternative
* `sily.uri`: URI/URL parser

30 changes: 15 additions & 15 deletions core/sily/color.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ alias col = Color;
alias Color8 = color8;

/// Constructs color from 8 bit (0-255) components
private Color color8(float R, float G, float B, float A = 255) {
private Color color8(ubyte R, ubyte G, ubyte B, ubyte A = 255) {
return Color(R / 255.0f, G / 255.0f, B / 255.0f, A / 255.0f);
}

Expand Down Expand Up @@ -105,31 +105,31 @@ struct Color {
/// opBinary x [+, -, *, /, %] y
auto opBinary(string op, R)(in Color!(R, N) b) const if ( isNumeric!R ) {
// assert(/* this !is null && */ b !is null, "\nOP::ERROR nullptr Color!" ~ 4.to!string ~ ".");
VecType ret = VecType();
Color ret = Color();
foreach (i; 0 .. 4) { mixin( "ret.data[i] = data[i] " ~ op ~ " b.data[i];" ); }
return ret;
}

/// Ditto
auto opBinaryRight(string op, R)(in Color!(R, N) b) const if ( isNumeric!R ) {
// assert(/* this !is null && */ b !is null, "\nOP::ERROR nullptr Color!" ~ 4.to!string ~ ".");
VecType ret = VecType();
Color ret = Color();
foreach (i; 0 .. 4) { mixin( "ret[i] = b.data[i] " ~ op ~ " data[i];" ); }
return ret;
}

/// Ditto
auto opBinary(string op, R)(in R b) const if ( isNumeric!R ) {
// assert(this !is null, "\nOP::ERROR nullptr Color!" ~ 4.to!string ~ ".");
VecType ret = VecType();
Color ret = Color();
foreach (i; 0 .. 4) { mixin( "ret.data[i] = data[i] " ~ op ~ " b;" ); }
return ret;
}

/// Ditto
auto opBinaryRight(string op, R)(in R b) const if ( isNumeric!R ) {
// assert(this !is null, "\nOP::ERROR nullptr Color!" ~ 4.to!string ~ ".");
VecType ret = VecType();
Color ret = Color();
foreach (i; 0 .. 4) { mixin( "ret[i] = b " ~ op ~ " data[i];" ); }
return ret;
}
Expand All @@ -148,8 +148,8 @@ struct Color {
/// opCmp x [< > <= >=] y
int opCmp(R)(in Color!(R, N) b) const if ( isNumeric!R ) {
// assert(/* this !is null && */ b !is null, "\nOP::ERROR nullptr Color!" ~ 4.to!string ~ ".");
float al = length;
float bl = b.length;
float al = luminance;
float bl = b.luminance;
if (al == bl) return 0;
if (al < bl) return -1;
return 1;
Expand All @@ -158,7 +158,7 @@ struct Color {
/// opUnary [-, +, --, ++] x
auto opUnary(string op)() if(op == "-"){
// assert(this !is null, "\nOP::ERROR nullptr Color!" ~ 4.to!string ~ ".");
VecType ret = VecType();
Color ret = Color();
if (op == "-")
foreach (i; 0 .. 4) { ret.data[i] = -data[i]; }
return ret;
Expand Down Expand Up @@ -197,7 +197,7 @@ struct Color {
/// Ditto
bool opCast(T)() const if (is(T == bool)) {
float s = 0;
foreach (i; 0..4) {
foreach (i; 0..3) {
s += data[i];
}
return !s.isClose(0, float.epsilon);
Expand Down Expand Up @@ -261,12 +261,12 @@ struct Color {
/* -------------------------------------------------------------------------- */

/// Returns: inverted color
Color invert() {
Color invert(bool invertAlpha = false) {
Color c;
c.data[0] = 1.0f - data[0];
c.data[1] = 1.0f - data[1];
c.data[2] = 1.0f - data[2];
c.data[3] = 1.0f - data[3];
if (invertAlpha) c.data[3] = 1.0f - data[3];
return c;
}

Expand Down Expand Up @@ -384,7 +384,7 @@ struct Color {
p_alpha = Include alpha?
Returns: Html string
*/
string toHtml(bool p_alpha = false) const {
string toHtml(bool p_alpha = false) {
string txt;
txt ~= _to_hex(data[0]);
txt ~= _to_hex(data[1]);
Expand Down Expand Up @@ -519,7 +519,7 @@ struct Color {
/* -------------------------------------------------------------------------- */

/// Returns `h` component of hsv
float hue() const {
float hue() {
float cmin = data[0].min(data[1]);
cmin = cmin.min(data[2]);
float cmax = data[0].max(data[1]);
Expand All @@ -546,7 +546,7 @@ struct Color {
}

/// Returns `s` component of hsv
float saturation() const {
float saturation() {
float cmin = data[0].min(data[1]);
cmin = cmin.min(data[2]);
float cmax = data[0].max(data[1]);
Expand All @@ -558,7 +558,7 @@ struct Color {
}

/// Returns `v` component of hsv
float value() const {
float value() {
float cmax = data[0].max(data[1]);
cmax = cmax.max(data[2]);
return cmax;
Expand Down
2 changes: 0 additions & 2 deletions core/sily/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public import sily.random;
/// Ditto
public import sily.stack;
/// Ditto
public import sily.stdio;
/// Ditto
public import sily.string;
/// Ditto
public import sily.thread;
Expand Down
1 change: 1 addition & 0 deletions core/sily/stdio.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

/// std.stdio wrapper
deprecated
module sily.stdio;

static import std.stdio;
Expand Down
Empty file removed readme/wiki/core.md
Empty file.
Empty file removed readme/wiki/sdl.md
Empty file.
Empty file removed readme/wiki/term.md
Empty file.
Empty file removed readme/wiki/web.md
Empty file.
2 changes: 2 additions & 0 deletions test/vector.d
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,7 @@ void main() {
writeln(vpinv * vec3(1, 10, -1));
writeln(vpinv * vec4(1, 10, -1, 1));

writeln(col(1, 2, 3, 4).rgaabargb);

writeln("Completed");
}

0 comments on commit 84d4693

Please sign in to comment.