Skip to content

Commit 26eac45

Browse files
author
Owen
authored
initial development (#1)
* initial development * Create pyproject.toml * Update lint.yml * format clang * Update lint.yml
1 parent 718faeb commit 26eac45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2131
-1
lines changed

.clang-format

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
# We'll use defaults from the Google style.
3+
BasedOnStyle: Google
4+
---
5+
Language: Cpp
6+
# Force pointers to the type for C++.
7+
DerivePointerAlignment: false
8+
PointerAlignment: Left
9+
AlignAfterOpenBracket: AlwaysBreak
10+
---
11+
Language: Proto
12+
# Don't format .proto files.
13+
DisableFormat: true
14+
...

.clang-format-ignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
third-party/sicgl

.github/workflows/ci.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# continuous integration
2+
name: ci
3+
4+
on:
5+
workflow_dispatch:
6+
push:
7+
branches: [ "main" ]
8+
pull_request:
9+
10+
jobs:
11+
lint:
12+
name: 'linting'
13+
uses: ./.github/workflows/lint.yml

.github/workflows/lint.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# linting
2+
name: check-lint
3+
4+
on:
5+
workflow_call:
6+
workflow_dispatch:
7+
8+
jobs:
9+
clang-format-lint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
# check out the repo
13+
- uses: actions/checkout@v3
14+
with:
15+
submodules: true
16+
17+
# install clang-format
18+
- name: install clang-format
19+
run: |
20+
sudo apt update
21+
sudo apt install clang-format
22+
clang-format --version
23+
24+
# lint using clang-format
25+
- name: clang-format lint
26+
run: |
27+
./scripts/third-party/run-clang-format/run-clang-format.py -r src include
28+
29+
python-lint:
30+
runs-on: ubuntu-latest
31+
steps:
32+
# check out the repo
33+
- uses: actions/checkout@v3
34+
with:
35+
submodules: true
36+
37+
# setup ci tools
38+
- name: set up ci tools
39+
run: |
40+
python3 -m venv venv
41+
. ./venv/bin/activate
42+
pip install -r requirements.dev.txt
43+
44+
# lint using pylint
45+
- name: run black
46+
run: |
47+
. ./venv/bin/activate
48+
black . --check

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.vscode
2+
13
# Byte-compiled / optimized / DLL files
24
__pycache__/
35
*.py[cod]

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "third-party/sicgl"]
2+
path = third-party/sicgl
3+
url = https://github.com/oclyke/sicgl
4+
[submodule "scripts/third-party/run-clang-format"]
5+
path = scripts/third-party/run-clang-format
6+
url = https://github.com/Sarcasm/run-clang-format

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Owen
3+
Copyright (c) 2023 oclyke
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

examples/simple.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pysicgl
2+
3+
# create a screen definition with extent (WIDTH, HEIGHT)
4+
WIDTH = 256
5+
HEIGHT = 128
6+
display_screen = pysicgl.Screen((WIDTH, HEIGHT))
7+
8+
# allocate memory for the interface using the number of
9+
# pixels in the display screen
10+
display_memory = pysicgl.allocate_pixel_memory(display_screen.pixels)
11+
12+
# create an interface which controls access to this
13+
# memory. the screen definition is used to inform
14+
# geometrical constraints.
15+
display = pysicgl.Interface(display_screen, display_memory)
16+
17+
# create a orange-red color using a 4-tuple of RGBA components
18+
color = pysicgl.Color.from_rgba((255, 128, 3, 0))
19+
20+
# draw a pixel directly to the interface origin
21+
# the coordinates are given in the interface-relative system
22+
display.interface_pixel(color, (0, 0))
23+
24+
# show the fist pixel as memory
25+
print(list(display.memory[0:4]))

include/pysicgl.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include "pysicgl/color_sequence.h"
4+
#include "pysicgl/drawing/blit.h"
5+
#include "pysicgl/drawing/compose.h"
6+
#include "pysicgl/drawing/field.h"
7+
#include "pysicgl/drawing/global.h"
8+
#include "pysicgl/drawing/interface.h"
9+
#include "pysicgl/drawing/screen.h"
10+
#include "pysicgl/field.h"
11+
#include "pysicgl/interface.h"
12+
#include "pysicgl/screen.h"
13+
#include "pysicgl/utilities.h"

include/pysicgl/color.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes must come first
6+
7+
#include "sicgl/color.h"
8+
9+
// declare the type
10+
extern PyTypeObject ColorType;
11+
12+
typedef struct {
13+
PyObject_HEAD
14+
} ColorObject;

include/pysicgl/color_sequence.h

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes must come first
6+
7+
#include "sicgl/color_sequence.h"
8+
9+
// declare the type
10+
extern PyTypeObject ColorSequenceType;
11+
12+
typedef struct {
13+
PyObject_HEAD PyObject* _colors;
14+
int _type;
15+
sequence_map_fn _interpolation_map_fn;
16+
} ColorSequenceObject;
17+
18+
int ColorSequence_post_ready_init();
19+
20+
int ColorSequence_get(
21+
ColorSequenceObject* self, size_t* len, color_t* colors_out,
22+
size_t colors_out_len);
23+
int ColorSequence_get_interp_map_fn(
24+
size_t interp_type, sequence_map_fn* fn_out);

include/pysicgl/drawing/blit.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes must come first
6+
7+
PyObject* blit(PyObject* self, PyObject* args);

include/pysicgl/drawing/compose.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes must come first
6+
7+
PyObject* compose(PyObject* self_in, PyObject* args);

include/pysicgl/drawing/field.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes must come first
6+
7+
PyObject* scalar_field(PyObject* self_in, PyObject* args);

include/pysicgl/drawing/global.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes must come first
6+
7+
PyObject* global_pixel(PyObject* self_in, PyObject* args);
8+
PyObject* global_line(PyObject* self_in, PyObject* args);
9+
PyObject* global_rectangle(PyObject* self_in, PyObject* args);
10+
PyObject* global_rectangle_filled(PyObject* self_in, PyObject* args);
11+
PyObject* global_circle(PyObject* self_in, PyObject* args);
12+
PyObject* global_ellipse(PyObject* self_in, PyObject* args);

include/pysicgl/drawing/interface.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes must come first
6+
7+
PyObject* interface_fill(PyObject* self_in, PyObject* args);
8+
PyObject* interface_pixel(PyObject* self_in, PyObject* args);
9+
PyObject* interface_line(PyObject* self_in, PyObject* args);
10+
PyObject* interface_rectangle(PyObject* self_in, PyObject* args);
11+
PyObject* interface_rectangle_filled(PyObject* self_in, PyObject* args);
12+
PyObject* interface_circle(PyObject* self_in, PyObject* args);
13+
PyObject* interface_ellipse(PyObject* self_in, PyObject* args);

include/pysicgl/drawing/screen.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes must come first
6+
7+
PyObject* screen_fill(PyObject* self_in, PyObject* args);
8+
PyObject* screen_pixel(PyObject* self_in, PyObject* args);
9+
PyObject* screen_line(PyObject* self_in, PyObject* args);
10+
PyObject* screen_rectangle(PyObject* self_in, PyObject* args);
11+
PyObject* screen_rectangle_filled(PyObject* self_in, PyObject* args);
12+
PyObject* screen_circle(PyObject* self_in, PyObject* args);
13+
PyObject* screen_ellipse(PyObject* self_in, PyObject* args);

include/pysicgl/field.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes must come first
6+
7+
#include "sicgl/field.h"
8+
9+
// declare the type
10+
extern PyTypeObject ScalarFieldType;
11+
12+
typedef struct {
13+
PyObject_HEAD Py_buffer _scalars_buffer;
14+
} ScalarFieldObject;
15+
16+
int scalar_field_get_scalars(
17+
ScalarFieldObject* self, size_t* len, double** scalars);

include/pysicgl/interface.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes must come first
6+
7+
#include "pysicgl/screen.h"
8+
#include "sicgl/interface.h"
9+
#include "sicgl/screen.h"
10+
11+
// declare the type
12+
extern PyTypeObject InterfaceType;
13+
14+
typedef struct {
15+
PyObject_HEAD
16+
// the underlying sicgl type
17+
interface_t interface;
18+
19+
// a ScreenObject which is linked to
20+
// the interface screen by reference
21+
ScreenObject* _screen;
22+
23+
// a buffer backs up the interface memory
24+
Py_buffer _memory_buffer;
25+
} InterfaceObject;

include/pysicgl/screen.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes must come first
6+
7+
#include <stdbool.h>
8+
9+
#include "sicgl/screen.h"
10+
11+
// declare the type
12+
extern PyTypeObject ScreenType;
13+
14+
typedef struct {
15+
PyObject_HEAD
16+
/* Type-specific fields go here. */
17+
screen_t* screen;
18+
screen_t _screen;
19+
20+
// a flag to explicitly indicate whether this is an object or reference
21+
bool _is_reference;
22+
} ScreenObject;
23+
24+
// publicly accessible constructors
25+
ScreenObject* new_screen_object(screen_t* ref);

include/pysicgl/utilities.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
#define PY_SSIZE_T_CLEAN
4+
#include <Python.h>
5+
// python includes must come first
6+
7+
#include "sicgl/extent.h"
8+
9+
// int unpack_ext_t_tuple2(PyObject* obj, ext_t* u, ext_t* v);

pyproject.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[tool.black]
2+
include = '''
3+
src\/.*\.pyi?$|
4+
tests\/.*\.pyi?$|
5+
examples\/.*\.pyi?$
6+
'''
7+
exclude = '''
8+
third-party\/.*\.pyi?$|
9+
venv\/.*\.pyi?$
10+
'''

requirements.dev.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
black >= 22.12.0, < 23.0.0
2+
pytest >= 7.2.1, < 8.0.0

scripts/third-party/run-clang-format

Submodule run-clang-format added at 39081c9

0 commit comments

Comments
 (0)