1
0

initial commit

This commit is contained in:
2023-04-04 20:48:51 +02:00
commit 3cf894b67f
21 changed files with 1002 additions and 0 deletions

43
line_seg-295810/jshintrc Normal file
View File

@@ -0,0 +1,43 @@
/*
* Example jshint configuration file for Pebble development.
*
* Check out the full documentation at http://www.jshint.com/docs/options/
*/
{
// Declares the existence of the globals available in PebbleKit JS.
"globals": {"localStorage": true, "Int16Array": true, "Uint32Array": true, "setTimeout": true, "Uint8ClampedArray": true, "navigator": true, "setInterval": true, "WebSocket": true, "Int32Array": true, "Uint8Array": true, "Float64Array": true, "Int8Array": true, "XMLHttpRequest": true, "Uint16Array": true, "Float32Array": true, "console": true, "Pebble": true},
// Do not mess with standard JavaScript objects (Array, Date, etc)
"freeze": true,
// Do not use eval! Keep this warning turned on (ie: false)
"evil": false,
/*
* The options below are more style/developer dependent.
* Customize to your liking.
*/
// All variables should be in camelcase - too specific for CloudPebble builds to fail
// "camelcase": true,
// Do not allow blocks without { } - too specific for CloudPebble builds to fail.
// "curly": true,
// Prohibits the use of immediate function invocations without wrapping them in parentheses
"immed": true,
// Don't enforce indentation, because it's not worth failing builds over
// (especially given our somewhat lacklustre support for it)
"indent": false,
// Do not use a variable before it's defined
"latedef": "nofunc",
// Spot undefined variables
"undef": "true",
// Spot unused variables
"unused": "true"
}

View File

@@ -0,0 +1,21 @@
{
"author": "lastfuture@lastfuture.de",
"dependencies": {},
"keywords": [],
"name": "line-seg",
"pebble": {
"displayName": "line seg",
"enableMultiJS": false,
"messageKeys": [],
"projectType": "native",
"resources": {
"media": []
},
"sdkVersion": "3",
"uuid": "3ef2a83a-ba8e-48c5-ad81-f0da09b74649",
"watchapp": {
"watchface": false
}
},
"version": "1.0.0"
}

View File

@@ -0,0 +1,159 @@
#include <pebble.h>
/*
* GraphicsGems.h
* Version 1.0 - Andrew Glassner
* from "Graphics Gems", Academic Press, 1990
*/
#ifndef GG_H
#define GG_H 1
/*********************/
/* 2d geometry types */
/*********************/
typedef struct Point2Struct { /* 2d point */
double x, y;
} Point2;
typedef Point2 Vector2;
typedef struct IntPoint2Struct { /* 2d integer point */
int x, y;
} IntPoint2;
typedef struct Matrix3Struct { /* 3-by-3 matrix */
double element[3][3];
} Matrix3;
typedef struct Box2dStruct { /* 2d box */
Point2 min, max;
} Box2;
/*********************/
/* 3d geometry types */
/*********************/
typedef struct Point3Struct { /* 3d point */
double x, y, z;
} Point3;
typedef Point3 Vector3;
typedef struct IntPoint3Struct { /* 3d integer point */
int x, y, z;
} IntPoint3;
typedef struct Matrix4Struct { /* 4-by-4 matrix */
double element[4][4];
} Matrix4;
typedef struct Box3dStruct { /* 3d box */
Point3 min, max;
} Box3;
/***********************/
/* one-argument macros */
/***********************/
/* absolute value of a */
#define ABS(a) (((a)<0) ? -(a) : (a))
/* round a to nearest int */
#define ROUND(a) ((a)>0 ? (int)((a)+0.5) : -(int)(0.5-(a)))
/* take sign of a, either -1, 0, or 1 */
#define ZSGN(a) (((a)<0) ? -1 : (a)>0 ? 1 : 0)
/* take binary sign of a, either -1, or 1 if >= 0 */
#define SGN(a) (((a)<0) ? -1 : 1)
/* shout if something that should be true isn't */
#define ASSERT(x) \
if (!(x)) fprintf(stderr," Assert failed: x\n");
/* square a */
#define SQR(a) ((a)*(a))
/***********************/
/* two-argument macros */
/***********************/
/* find minimum of a and b */
#define MIN(a,b) (((a)<(b))?(a):(b))
/* find maximum of a and b */
#define MAX(a,b) (((a)>(b))?(a):(b))
/* swap a and b (see Gem by Wyvill) */
#define SWAP(a,b) { a^=b; b^=a; a^=b; }
/* linear interpolation from l (when a=0) to h (when a=1)*/
/* (equal to (a*h)+((1-a)*l) */
#define LERP(a,l,h) ((l)+(((h)-(l))*(a)))
/* clamp the input to the specified range */
#define CLAMP(v,l,h) ((v)<(l) ? (l) : (v) > (h) ? (h) : v)
/****************************/
/* memory allocation macros */
/****************************/
/* create a new instance of a structure (see Gem by Hultquist) */
#define NEWSTRUCT(x) (struct x *)(malloc((unsigned)sizeof(struct x)))
/* create a new instance of a type */
#define NEWTYPE(x) (x *)(malloc((unsigned)sizeof(x)))
/********************/
/* useful constants */
/********************/
#define PI 3.141592 /* the venerable pi */
#define PITIMES2 6.283185 /* 2 * pi */
#define PIOVER2 1.570796 /* pi / 2 */
#define E 2.718282 /* the venerable e */
#define SQRT2 1.414214 /* sqrt(2) */
#define SQRT3 1.732051 /* sqrt(3) */
#define GOLDEN 1.618034 /* the golden ratio */
#define DTOR 0.017453 /* convert degrees to radians */
#define RTOD 57.29578 /* convert radians to degrees */
/************/
/* booleans */
/************/
#define TRUE 1
#define FALSE 0
#define ON 1
#define OFF 0
typedef int boolean; /* boolean data type */
typedef boolean flag; /* flag data type */
extern double V2SquaredLength(), V2Length();
extern double V2Dot(), V2DistanceBetween2Points();
extern Vector2 *V2Negate(), *V2Normalize(), *V2Scale(), *V2Add(), *V2Sub();
extern Vector2 *V2Lerp(), *V2Combine(), *V2Mul(), *V2MakePerpendicular();
extern Vector2 *V2New(), *V2Duplicate();
extern Point2 *V2MulPointByMatrix();
extern Matrix3 *V2MatMul();
extern double V3SquaredLength(), V3Length();
extern double V3Dot(), V3DistanceBetween2Points();
extern Vector3 *V3Normalize(), *V3Scale(), *V3Add(), *V3Sub();
extern Vector3 *V3Lerp(), *V3Combine(), *V3Mul(), *V3Cross();
extern Vector3 *V3New(), *V3Duplicate();
extern Point3 *V3MulPointByMatrix();
extern Matrix4 *V3MatMul();
extern double RegulaFalsi(), NewtonRaphson(), findroot();
#endif

View File

@@ -0,0 +1,47 @@
#include <pebble.h>
/*
Fast Circle-Rectangle Intersection Checking
by Clifford A. Shaffer
from "Graphics Gems", Academic Press, 1990
*/
#include "GraphicsGems.h"
boolean Check_Intersect(R, C, Rad)
/* Return TRUE iff rectangle R intersects circle with centerpoint C and
radius Rad. */
Box2 *R;
Point2 *C;
double Rad;
{
double Rad2;
Rad2 = Rad * Rad;
/* Translate coordinates, placing C at the origin. */
R->max.x -= C->x; R->max.y -= C->y;
R->min.x -= C->x; R->min.y -= C->y;
if (R->max.x < 0) /* R to left of circle center */
if (R->max.y < 0) /* R in lower left corner */
return ((R->max.x * R->max.x + R->max.y * R->max.y) < Rad2);
else if (R->min.y > 0) /* R in upper left corner */
return ((R->max.x * R->max.x + R->min.y * R->min.y) < Rad2);
else /* R due West of circle */
return(ABS(R->max.x) < Rad);
else if (R->min.x > 0) /* R to right of circle center */
if (R->max.y < 0) /* R in lower right corner */
return ((R->min.x * R->min.x + R->max.y * R->max.y) < Rad2);
else if (R->min.y > 0) /* R in upper right corner */
return ((R->min.x * R->min.x + R->min.y * R->min.y) < Rad2);
else /* R due East of circle */
return (R->min.x < Rad);
else /* R on circle vertical centerline */
if (R->max.y < 0) /* R due South of circle */
return (ABS(R->max.y) < Rad);
else if (R->min.y > 0) /* R due North of circle */
return (R->min.y < Rad);
else /* R contains circle centerpoint */
return(TRUE);
}

View File

@@ -0,0 +1,109 @@
#include <pebble.h>
#define DONT_INTERSECT 0
#define DO_INTERSECT 1
#define COLLINEAR 2
#define SAME_SIGNS( a, b ) \
(((long) ((unsigned long) a ^ (unsigned long) b)) >= 0 )
int lines_intersect(
x1, y1,
x2, y2,
x3, y3,
x4, y4,
x,
y
)
long x1, y1, x2, y2, x3, y3, x4, y4, *x, *y;
{
long a1, a2, b1, b2, c1, c2; /* Coefficients of line eqns. */
long r1, r2, r3, r4; /* 'Sign' values */
long denom, offset, num; /* Intermediate values */
a1 = y2 - y1;
b1 = x1 - x2;
c1 = x2 * y1 - x1 * y2;
r3 = a1 * x3 + b1 * y3 + c1;
r4 = a1 * x4 + b1 * y4 + c1;
if ( r3 != 0 &&
r4 != 0 &&
SAME_SIGNS( r3, r4 ))
return ( DONT_INTERSECT );
a2 = y4 - y3;
b2 = x3 - x4;
c2 = x4 * y3 - x3 * y4;
r1 = a2 * x1 + b2 * y1 + c2;
r2 = a2 * x2 + b2 * y2 + c2;
if ( r1 != 0 &&
r2 != 0 &&
SAME_SIGNS( r1, r2 ))
return ( DONT_INTERSECT );
denom = a1 * b2 - a2 * b1;
if ( denom == 0 )
return ( COLLINEAR );
offset = denom < 0 ? - denom / 2 : denom / 2;
num = b1 * c2 - b2 * c1;
*x = ( num < 0 ? num - offset : num + offset ) / denom;
num = a2 * c1 - a1 * c2;
*y = ( num < 0 ? num - offset : num + offset ) / denom;
return ( DO_INTERSECT );
}
#define INTERSECTION_NONE 0
#define INTERSECTION_PARTIAL 1
#define INTERSECTION_FULL 2
typedef struct {
uint8_t success;
GPoint p1;
GPoint p2;
} Intersection;
Intersection rectintersect(GPoint p1, GPoint p2, GRect rect) {
long x,y;
long x1=0,y1=0,x2=0,y2=0;
bool intersection = false, final_intersection = false;
if (lines_intersect(p1.x, p1.y, p2.x, p2.y, rect.origin.x, rect.origin.y, rect.origin.x, rect.origin.y+rect.size.h, &x, &y) == DO_INTERSECT) {
x1 = x; y1 = y; intersection = true;
}
if (lines_intersect(p1.x, p1.y, p2.x, p2.y, rect.origin.x, rect.origin.y, rect.origin.x+rect.size.w, rect.origin.y, &x, &y) == DO_INTERSECT) {
if (!intersection) {
x1 = x; y1 = y; intersection = true;
} else {
x2 = x; y2 = y; final_intersection = true;
}
}
if (!final_intersection && lines_intersect(p1.x, p1.y, p2.x, p2.y, rect.origin.x, rect.origin.y+rect.size.h, rect.origin.x+rect.size.w, rect.origin.y+rect.size.h, &x, &y) == DO_INTERSECT) {
if (!intersection) {
x1 = x; y1 = y; intersection = true;
} else {
x2 = x; y2 = y; final_intersection = true;
}
}
if (!final_intersection && lines_intersect(p1.x, p1.y, p2.x, p2.y, rect.origin.x+rect.size.w, rect.origin.y, rect.origin.x+rect.size.w, rect.origin.y+rect.size.h, &x, &y) == DO_INTERSECT) {
if (!intersection) {
x1 = x; y1 = y;
} else {
x2 = x; y2 = y; final_intersection = true;
}
}
if(final_intersection) {
return (Intersection) { .success = INTERSECTION_FULL, .p1 = (GPoint) { .x = x1, .y = y1 }, .p2 = (GPoint) { .x = x2, .y = y2 } };
} else if (intersection) {
return (Intersection) { .success = INTERSECTION_PARTIAL, .p1 = (GPoint) { .x = x1, .y = y1 }, .p2 = (GPoint) { .x = x2, .y = y2 } };
} else {
return (Intersection) { .success = INTERSECTION_NONE, .p1 = (GPoint) { .x = x1, .y = y1 }, .p2 = (GPoint) { .x = x2, .y = y2 } };
}
}

View File

@@ -0,0 +1,71 @@
#include <pebble.h>
#include <intersection.h>
static Window *s_main_window;
static Layer *s_canvas_layer;
static void canvas_update_proc(Layer *this_layer, GContext *ctx) {
//GRect bounds = layer_get_bounds(this_layer);
GRect rect = GRect(25, 15, 55, 70);
graphics_context_set_fill_color(ctx, GColorYellow);
graphics_fill_rect(ctx, rect, 0, GCornerNone);
graphics_context_set_stroke_width(ctx, 1);
graphics_context_set_stroke_color(ctx, GColorRed);
GPoint line_start = GPoint(50,90);
GPoint line_end = GPoint(99,10);
graphics_draw_line(ctx, line_start, line_end);
Intersection intersect = rectintersect(line_start, line_end, rect);
if (intersect.success >= INTERSECTION_FULL) {
APP_LOG(APP_LOG_LEVEL_INFO, "Intersection");
graphics_context_set_stroke_color(ctx, GColorRed);
graphics_context_set_stroke_width(ctx, 3);
graphics_draw_line(ctx, intersect.p1, intersect.p2);
}
}
static void main_window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window);
GRect window_bounds = layer_get_bounds(window_layer);
// Create Layer
s_canvas_layer = layer_create(GRect(0, 0, window_bounds.size.w, window_bounds.size.h));
layer_add_child(window_layer, s_canvas_layer);
// Set the update_proc
layer_set_update_proc(s_canvas_layer, canvas_update_proc);
}
static void main_window_unload(Window *window) {
// Destroy Layer
layer_destroy(s_canvas_layer);
}
static void init(void) {
// Create main Window
s_main_window = window_create();
window_set_window_handlers(s_main_window, (WindowHandlers) {
.load = main_window_load,
.unload = main_window_unload,
});
window_stack_push(s_main_window, true);
}
static void deinit(void) {
// Destroy main Window
window_destroy(s_main_window);
}
int main(void) {
init();
app_event_loop();
deinit();
}

62
line_seg-295810/wscript Normal file
View File

@@ -0,0 +1,62 @@
#
# This file is the default set of rules to compile a Pebble project.
#
# Feel free to customize this to your needs.
#
import os.path
try:
from sh import CommandNotFound, jshint, cat, ErrorReturnCode_2
hint = jshint
except (ImportError, CommandNotFound):
hint = None
top = '.'
out = 'build'
def options(ctx):
ctx.load('pebble_sdk')
def configure(ctx):
ctx.load('pebble_sdk')
def build(ctx):
if False and hint is not None:
try:
hint([node.abspath() for node in ctx.path.ant_glob("src/**/*.js")], _tty_out=False) # no tty because there are none in the cloudpebble sandbox.
except ErrorReturnCode_2 as e:
ctx.fatal("\nJavaScript linting failed (you can disable this in Project Settings):\n" + e.stdout)
# Concatenate all our JS files (but not recursively), and only if any JS exists in the first place.
ctx.path.make_node('src/js/').mkdir()
js_paths = ctx.path.ant_glob(['src/*.js', 'src/**/*.js'])
if js_paths:
ctx(rule='cat ${SRC} > ${TGT}', source=js_paths, target='pebble-js-app.js')
has_js = True
else:
has_js = False
ctx.load('pebble_sdk')
build_worker = os.path.exists('worker_src')
binaries = []
for p in ctx.env.TARGET_PLATFORMS:
ctx.set_env(ctx.all_envs[p])
ctx.set_group(ctx.env.PLATFORM_NAME)
app_elf='{}/pebble-app.elf'.format(p)
ctx.pbl_program(source=ctx.path.ant_glob('src/c/**/*.c'),
target=app_elf)
if build_worker:
worker_elf='{}/pebble-worker.elf'.format(p)
binaries.append({'platform': p, 'app_elf': app_elf, 'worker_elf': worker_elf})
ctx.pbl_worker(source=ctx.path.ant_glob('worker_src/c/**/*.c'),
target=worker_elf)
else:
binaries.append({'platform': p, 'app_elf': app_elf})
ctx.set_group('bundle')
ctx.pbl_bundle(binaries=binaries, js='pebble-js-app.js' if has_js else [])