Hello,
Think about CIRCLE statement:
circle x, y, radius
Current statements for ARC, CHORD and PIE are:
arc x_expr, y_expr, width_expr, height_expr, startangle_expr, widthangle_expr chord x_expr, y_expr, width_expr, height_expr, startangle_expr, widthangle_expr pie x_expr, y_expr, width_expr, height_expr, startangle_expr, widthangle_expr
How about to implement those versions:
arc x, y, radius, startangle, widthangle chord x, y, radius, startangle, widthangle pie x, y, radius, startangle, widthangle
They seem more logical in conjunction with CIRCLE command style.
clg color black, clear circle 100, 100, 50 color red penwidth 5 arc 100, 100, 50, 0, PI/2 print "This is a quarter of a circle"
These can also co-exist with current ones.
arc x, y, width, height, startangle, widthangle
or
arc x, y, radius, startangle, widthangle
chord x, y, width, height, startangle, widthangle
or
chord x, y, radius, startangle, widthangle
pie x, y, width, height, startangle, widthangle
or
pie x, y, radius, startangle, widthangle
The trick is to check the number of arguments. To implement this style, make those changes:
basicParse.y
arcstmt: B256ARC args_eeeeee { addIntOp(OP_PUSHINT, 6); // 6 arguments addOp(OP_ARC); } | B256ARC args_eeeee { addIntOp(OP_PUSHINT, 5); // 5 arguments addOp(OP_ARC); } ; chordstmt: B256CHORD args_eeeeee { addIntOp(OP_PUSHINT, 6); // 6 arguments addOp(OP_CHORD); } | B256CHORD args_eeeee { addIntOp(OP_PUSHINT, 5); // 5 arguments addOp(OP_CHORD); } ; piestmt: B256PIE args_eeeeee { addIntOp(OP_PUSHINT, 6); // 6 arguments addOp(OP_PIE); } | B256PIE args_eeeee { addIntOp(OP_PUSHINT, 5); // 5 arguments addOp(OP_PIE); } ;
Interpreter.cpp - just change the beginning of OP_ARC/OP_CHORD/OP_PIE part:
case OP_ARC: case OP_CHORD: case OP_PIE: { int yval, xval, hval, wval; int arg = stack->popint(); // number of arguments double angwval = stack->popfloat(); double startval = stack->popfloat(); if(arg==5){ int rval = stack->popint(); yval = stack->popint() - rval; xval = stack->popint() - rval; hval = rval * 2; wval = rval * 2; }else{ hval = stack->popint(); wval = stack->popint(); yval = stack->popint(); xval = stack->popint(); } // degrees * 16
Et voila!
Do you remember arc_example.kbs
from ARC help page?
# arc_example.kbs # 2012-12-29 j.m.reneau # # example of arc statement added on 0.9.9.25 clg color black for t = 1 to 100 step 3 arc 150-t,150-t,t*2,t*2,0,pi*2*t/100 #ambiguous calculations next t
This can be done just like this:
clg color black for t = 1 to 100 step 3 arc 150,150,t,0,pi*2*t/100 #simply next t
STAGE 2
I would like to add an ELLIPSE statement. Eg.
basicParse.y
ellipsestmt: B256ELLIPSE args_eeee { addOp(OP_ELLIPSE); } ;
Interpreter.cpp
case OP_ELLIPSE: { int hval = stack->popint(); int wval = stack->popint(); int yval = stack->popint(); int xval = stack->popint(); QPainter *ian; if (printing) { ian = printdocumentpainter; } else { ian = new QPainter(graphwin->image); } ian->setPen(drawingpen); ian->setBrush(drawingbrush); if (CompositionModeClear) { ian->setCompositionMode(QPainter::CompositionMode_Clear); } ian->drawEllipse(xval, yval, wval, hval); if(!printing) { ian->end(); delete ian; if (!fastgraphics) waitForGraphics(); } } break;
I know that we can override the CIRCLE statement, but ellipse != circle.
circle x, y, radius circle x, y, width, height # this is an ellipse ellipse x, y, width, height
Putting all things together, we will have:
cicle x, y, radius arc x, y, radius, startangle, widthangle chord x, y, radius, startangle, widthangle pie x, y, radius, startangle, widthangle ellipse x, y, width, height arc x, y, width, height, startangle, widthangle chord x, y, width, height, startangle, widthangle pie x, y, width, height, startangle, widthangle
Remember that these proposed changes also keep 100% compatibility with old programs.
Respectfully,
Florin Oprea
Change integrated into 1.99.99.65 and after - will be committed soon.