Vertex v = {};
v.uv.z = -1;
- float hw = ctx->lineWidth / 2.0;
- int i = 0, ptrPath = 0;
+ float hw = ctx->lineWidth / 2.0f;
+ uint i = 0, ptrPath = 0;
uint32_t lastPathPointIdx, iL, iR;
while (ptrPath < ctx->pathPtr){
- int ptrCurve = 0;
+ uint ptrCurve = 0;
uint32_t firstIdx = ctx->vertCount;
i = ctx->pathes[ptrPath]&PATH_ELT_MASK;
vhw = vec2_perp(vhw);
if (ctx->lineCap == VKVG_LINE_CAP_ROUND){
- float step = M_PI / hw;
- float a = acos(n.x) + M_PI_2;
+ float step = M_PIF / hw;
+ float a = acosf(n.x) + M_PIF_2;
if (n.y < 0)
- a = M_PI-a;
- float a1 = a + M_PI;
+ a = M_PIF-a;
+ float a1 = a + M_PIF;
a+=step;
while (a < a1){
- _add_vertexf(ctx, cos(a) * hw + p0.x, sin(a) * hw + p0.y);
+ _add_vertexf(ctx, cosf(a) * hw + p0.x, sinf(a) * hw + p0.y);
a+=step;
}
uint32_t p0Idx = ctx->vertCount;
- for (int p = firstIdx; p < p0Idx; p++)
+ for (uint p = firstIdx; p < p0Idx; p++)
_add_triangle_indices(ctx, p0Idx+1, p, p+1);
firstIdx = p0Idx;
}
}
if (_path_has_curves (ctx,ptrPath)) {
+
while (i < lastPathPointIdx){
if (ptrPath + ptrCurve + 2 < ctx->pathPtr && (ctx->pathes [ptrPath + 2 + ptrCurve]&PATH_ELT_MASK) == i){
uint32_t lastCurvePoint = ctx->pathes[ptrPath + 3 + ptrCurve]&PATH_ELT_MASK;
while (i<lastCurvePoint){
iR = i+1;
- _build_vb_step(ctx,v,hw,iL,i,iR,true);
+ _build_vb_step (ctx, v, hw, iL, i, iR, true);
iL = i++;
}
ptrCurve += 2;
}else{
iR = i+1;
- _build_vb_step(ctx,v,hw,iL,i,iR, false);
+ _build_vb_step (ctx, v, hw, iL, i, iR, false);
iL = i++;
}
}
if (ctx->lineCap == VKVG_LINE_CAP_ROUND){
firstIdx = ctx->vertCount;
- float step = M_PI / hw;
- float a = acos(n.x)+ M_PI_2;
+ float step = M_PIF / hw;
+ float a = acosf(n.x)+ M_PIF_2;
if (n.y < 0)
- a = M_PI-a;
- float a1 = a - M_PI;
+ a = M_PIF-a;
+ float a1 = a - M_PIF;
a-=step;
while ( a > a1){
- _add_vertexf(ctx, cos(a) * hw + p0.x, sin(a) * hw + p0.y);
+ _add_vertexf(ctx, cosf(a) * hw + p0.x, sinf(a) * hw + p0.y);
a-=step;
}
uint32_t p0Idx = ctx->vertCount-1;
- for (int p = firstIdx-1 ; p < p0Idx; p++)
+ for (uint p = firstIdx-1 ; p < p0Idx; p++)
_add_triangle_indices(ctx, p+1, p, firstIdx-2);
}
ctx->curvePtr+=2;
}
//path start pointed at ptrPath has curve bit
-inline bool _path_has_curves (VkvgContext ctx, int ptrPath) {
+inline bool _path_has_curves (VkvgContext ctx, uint ptrPath) {
return ctx->pathes[ptrPath] & PATH_HAS_CURVES_BIT;
}
//this function expect that current path is empty
vec2 bisec = vec2_norm(vec2_add(v0n,v1n));
- float alpha = acos(v0n.x * v1n.x + v0n.y * v1n.y)/2;
+ float alpha = acosf(v0n.x * v1n.x + v0n.y * v1n.y)/2;
float cross = v0n.x * v1n.y - v0n.y * v1n.x;
if (cross<0)
alpha = -alpha;
- float lh = hw / cos(alpha);
+ float lh = hw / cosf(alpha);
bisec = vec2_perp(bisec);
bisec = vec2_mult(bisec,lh);
}
}else if (ctx->lineJoin == VKVG_LINE_JOIN_ROUND){
float step = M_PIF / hw;
- float a = acos(vp.x);
+ float a = acosf(vp.x);
if (vp.y < 0)
a = -a;
float a1 = a + alpha*2;
a-=step;
while (a > a1){
- _add_vertexf(ctx, cos(a) * hw + ctx->points[i].x, sin(a) * hw + ctx->points[i].y);
+ _add_vertexf(ctx, cosf(a) * hw + ctx->points[i].x, sinf(a) * hw + ctx->points[i].y);
a-=step;
}
}else{
float a1 = a + alpha*2;
a+=step;
while (a < a1){
- _add_vertexf(ctx, cos(a) * hw + ctx->points[i].x, sin(a) * hw + ctx->points[i].y);
+ _add_vertexf(ctx, cosf(a) * hw + ctx->points[i].x, sinf(a) * hw + ctx->points[i].y);
a+=step;
}
}
uint32_t p0Idx = ctx->vertCount;
_add_triangle_indices(ctx, idx, idx+2, idx+1);
if (cross<0){
- for (int p = idx+2; p < p0Idx; p++)
+ for (uint p = idx+2; p < p0Idx; p++)
_add_triangle_indices(ctx, p, p+1, idx);
_add_triangle_indices(ctx, p0Idx, p0Idx+2, idx);
_add_triangle_indices(ctx, idx, p0Idx+1, p0Idx+2);
}else{
- for (int p = idx+2; p < p0Idx; p++)
+ for (uint p = idx+2; p < p0Idx; p++)
_add_triangle_indices(ctx, p, p+1, idx+1);
_add_triangle_indices(ctx, p0Idx, p0Idx+1, idx+1);
_add_triangle_indices(ctx, idx+1, p0Idx+1, p0Idx+2);
bool _path_is_closed (VkvgContext ctx, uint32_t ptrPath);
void _set_curve_start (VkvgContext ctx);
void _set_curve_end (VkvgContext ctx);
-bool _path_has_curves (VkvgContext ctx, int ptrPath);
+bool _path_has_curves (VkvgContext ctx, uint ptrPath);
float _normalizeAngle (float a);
#include <math.h>
#define M_PIF 3.14159265358979323846f /* float pi */
+#define M_PIF_2 1.57079632679489661923f
#define PATH_CLOSED_BIT 0x80000000 /* most significant bit of path elmts is closed/open path state */
#define PATH_HAS_CURVES_BIT 0x40000000 /* most significant bit of path elmts end is continue path bit
Used to handle curved/line transition */
--- /dev/null
+#include "test.h"
+
+void test(){
+ VkvgContext ctx = vkvg_create(surf);
+
+ vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD);
+ vkvg_set_line_width(ctx, 30);
+
+ vkvg_set_line_join(ctx, VKVG_LINE_JOIN_ROUND);
+
+ //vkvg_arc (ctx, 200, 500, 100, 0, M_PI);
+
+ vkvg_translate(ctx,-50,-50);
+
+ vkvg_set_source_rgb (ctx, 0.5,0,0);
+
+ for (int j=0;j<2;j++) {
+ int i=0;
+ vkvg_move_to(ctx,100,100);
+ for (i=0;i<4;i++) {
+ vkvg_rel_line_to(ctx,50,70);
+ vkvg_rel_line_to(ctx,50,-70);
+ }
+ vkvg_stroke(ctx);
+
+ vkvg_move_to(ctx,500,200);
+ for (i=0;i<4;i++) {
+ vkvg_rel_line_to(ctx,-50,70);
+ vkvg_rel_line_to(ctx,-50,-70);
+ }
+ vkvg_stroke(ctx);
+
+ vkvg_move_to(ctx,100,400);
+ for (i=0;i<4;i++) {
+ vkvg_rel_line_to(ctx,50,-70);
+ vkvg_rel_line_to(ctx,50,70);
+ }
+ vkvg_stroke(ctx);
+
+ vkvg_move_to(ctx,500,500);
+ for (i=0;i<4;i++) {
+ vkvg_rel_line_to(ctx,-50,-70);
+ vkvg_rel_line_to(ctx,-50,70);
+ }
+ vkvg_stroke(ctx);
+ vkvg_set_line_join(ctx, VKVG_LINE_JOIN_BEVEL);
+ vkvg_translate(ctx,450,0);
+ }
+
+ vkvg_destroy(ctx);
+}
+
+int main(int argc, char *argv[]) {
+
+ perform_test (test, 1024, 768);
+
+ return 0;
+}
#include "test.h"
void test(){
- vkvg_surface_clear(surf);
+ //vkvg_surface_clear(surf);
struct timeval currentTime;
gettimeofday(¤tTime, NULL);
vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO);
vkvg_set_line_width(ctx,2);
vkvg_set_source_rgba(ctx,1.0,0.0,0.0,0.1);
- for (int i=0; i<1500; i++) {
- //randomize_color(ctx);
+ for (int i=0; i<500; i++) {
+ randomize_color(ctx);
float x = trunc( (0.5*(float)w*rand())/RAND_MAX );
float y = trunc( (0.5*(float)w*rand())/RAND_MAX );
float z = trunc( (0.5*(float)w*rand())/RAND_MAX ) + 1;
vkvg_rectangle(ctx, x+1, y+1, z, v);
vkvg_fill_preserve(ctx);
- //randomize_color(ctx);
+ randomize_color(ctx);
vkvg_stroke(ctx);
}
vkvg_destroy(ctx);