Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Adding a new module "sprite" which provides C acellerators for producing SVG files (and canvas primitives) from odielib math ops |
|---|---|
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
823b8f352a73da8315958bda404fa7bf |
| User & Date: | seandeelywoods 2019-10-19 01:58:13 |
Context
|
2023-08-17
| ||
| 17:22 | Tweak to C name Leaf check-in: 4bd4b1f15b user: seandeelywoods tags: dcii | |
|
2019-11-10
| ||
| 12:10 | Updated to the latest practcl check-in: f077acf6ff user: seandeelywoods tags: trunk | |
|
2019-10-19
| ||
| 01:58 | Adding a new module "sprite" which provides C acellerators for producing SVG files (and canvas primitives) from odielib math ops check-in: 823b8f352a user: seandeelywoods tags: trunk | |
|
2019-09-11
| ||
| 14:37 | Added a local copy of practcl, programmed make to use it check-in: 31f60fa725 user: hypnotoad tags: trunk | |
Changes
Changes to cmodules/affine/bbox.tcl.
| ︙ | ︙ | |||
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
my c_function {static inline void VectorXY_BBOX_Measure(VectorXY POINT,BBOXXY bbox)} {
if(POINT[X_IDX]<bbox[BBOX_X0_IDX]) bbox[BBOX_X0_IDX]=POINT[X_IDX];
if(POINT[Y_IDX]>bbox[BBOX_Y1_IDX]) bbox[BBOX_Y1_IDX]=POINT[Y_IDX];
if(POINT[X_IDX]>bbox[BBOX_X1_IDX]) bbox[BBOX_X1_IDX]=POINT[X_IDX];
if(POINT[Y_IDX]<bbox[BBOX_Y0_IDX]) bbox[BBOX_Y0_IDX]=POINT[Y_IDX];
}
###
# Return:
# 0 A and B do not inteserct
# 1 A and B intersect
# 2 A and B are identical
# 3 A is inside of B
| > > > > > > > | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
my c_function {static inline void VectorXY_BBOX_Measure(VectorXY POINT,BBOXXY bbox)} {
if(POINT[X_IDX]<bbox[BBOX_X0_IDX]) bbox[BBOX_X0_IDX]=POINT[X_IDX];
if(POINT[Y_IDX]>bbox[BBOX_Y1_IDX]) bbox[BBOX_Y1_IDX]=POINT[Y_IDX];
if(POINT[X_IDX]>bbox[BBOX_X1_IDX]) bbox[BBOX_X1_IDX]=POINT[X_IDX];
if(POINT[Y_IDX]<bbox[BBOX_Y0_IDX]) bbox[BBOX_Y0_IDX]=POINT[Y_IDX];
}
my c_function {static inline void Vector2d_BBOX_Measure(double x,double y,BBOXXY bbox)} {
if(x<bbox[BBOX_X0_IDX]) bbox[BBOX_X0_IDX]=x;
if(y>bbox[BBOX_Y1_IDX]) bbox[BBOX_Y1_IDX]=y;
if(x>bbox[BBOX_X1_IDX]) bbox[BBOX_X1_IDX]=x;
if(y<bbox[BBOX_Y0_IDX]) bbox[BBOX_Y0_IDX]=y;
}
###
# Return:
# 0 A and B do not inteserct
# 1 A and B intersect
# 2 A and B are identical
# 3 A is inside of B
|
| ︙ | ︙ | |||
116 117 118 119 120 121 122 |
if(Odie_GetVectorXYFromTclObj(interp,objv[i],point)) return TCL_ERROR;
VectorXY_BBOX_Measure(point,C->matrix);
}
}
Tcl_SetObjResult(interp,Matrix_To_TclObj(C));
return TCL_OK;
} {
| | | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
if(Odie_GetVectorXYFromTclObj(interp,objv[i],point)) return TCL_ERROR;
VectorXY_BBOX_Measure(point,C->matrix);
}
}
Tcl_SetObjResult(interp,Matrix_To_TclObj(C));
return TCL_OK;
} {
aliases ::vectorxy::bbox_create
}
my c_tclcmd ::odie::bbox::measure {
MATOBJ *C;
Tcl_Obj *varname,*pResult;
int i;
VectorXY point;
|
| ︙ | ︙ |
Changes to cmodules/affine/vectorxy.tcl.
| ︙ | ︙ | |||
910 911 912 913 914 915 916 |
if(length<Vector_Tolerance) {
return 0.0;
}
return length;
}
my c_tclcmd ::vectorxy::length {
| | | 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 |
if(length<Vector_Tolerance) {
return 0.0;
}
return length;
}
my c_tclcmd ::vectorxy::length {
VectorXY A;
double result;
if(objc != 2) {
Tcl_WrongNumArgs( interp, 1, objv, "A" );
return TCL_ERROR;
}
if(Odie_GetVectorXYFromTclObj(interp,objv[1],A)) return TCL_ERROR;
result=VectorXY_Magnitude(A);
|
| ︙ | ︙ | |||
959 960 961 962 963 964 965 |
}
Tcl_SetObjResult(interp, Tcl_NewDoubleObj(VectorXY_Dot_Product(AB,AC)));
return TCL_OK;
} {
aliases {::vectorxy::.}
}
| | | | | | | | 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 |
}
Tcl_SetObjResult(interp, Tcl_NewDoubleObj(VectorXY_Dot_Product(AB,AC)));
return TCL_OK;
} {
aliases {::vectorxy::.}
}
my c_function {static inline int VectorXY_Point_On_Segment(VectorXY POINT,VectorXY A,VectorXY B)} {
VectorXY INTERSECT;
double t;
t=VectorXY_ClosestPointOnSegment(A,B,POINT,INTERSECT);
if (t<0.0 && t>1.0) return 0;
if(VectorXY_Distance_squared(POINT,INTERSECT)>Vector_Tolerance_Sq) return 0;
return 1;
}
my c_tclcmd ::vectorxy::point_on_segment {
VectorXY A,B,X;
if( objc != 4 ){
Tcl_WrongNumArgs(interp, 1, objv, "point_on_segment X A B");
return TCL_ERROR;
}
if(Odie_GetVectorXYFromTclObj(interp,objv[1],X)) return TCL_ERROR;
if(Odie_GetVectorXYFromTclObj(interp,objv[2],A)) return TCL_ERROR;
if(Odie_GetVectorXYFromTclObj(interp,objv[3],B)) return TCL_ERROR;
Tcl_SetObjResult(interp, Tcl_NewIntObj(VectorXY_Point_On_Segment(X,A,B)));
return TCL_OK;
}
my c_tclcmd ::vectorxy::rightof {
/*
** tclcmd: triag_test_rightof X0 Y0 X1 Y1 X2 Y2
|
| ︙ | ︙ | |||
1047 1048 1049 1050 1051 1052 1053 |
Tcl_ListObjAppendElement(interp,pResult,VectorXY_To_TclObj(B));
}
Tcl_SetObjResult(interp, pResult);
return TCL_OK;
}
my c_tclcmd ::vectorxy::scale {
| < | < < | 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 |
Tcl_ListObjAppendElement(interp,pResult,VectorXY_To_TclObj(B));
}
Tcl_SetObjResult(interp, pResult);
return TCL_OK;
}
my c_tclcmd ::vectorxy::scale {
int i;
VectorXY S,A,B;
if( objc != 3 ){
Tcl_WrongNumArgs(interp, 1, objv, "SCALE V");
return TCL_ERROR;
}
if(Odie_GetVectorXYFromTclObj(interp,objv[1],S)) {
return TCL_ERROR;
}
if(Odie_GetVectorXYFromTclObj(interp,objv[2],A)) {
return TCL_ERROR;
}
if (S[Y_IDX]==0) {
S[Y_IDX]=S[X_IDX];
}
B[X_IDX]=A[X_IDX]*S[X_IDX];
B[Y_IDX]=A[Y_IDX]*S[Y_IDX];
|
| ︙ | ︙ | |||
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 |
B[X_IDX]=x*scale;
B[Y_IDX]=y*scale;
Tcl_ListObjAppendElement(interp,pResult,VectorXY_To_TclObj(B));
}
Tcl_SetObjResult(interp, pResult);
return TCL_OK;
}
my c_tclcmd ::vectorxy::translate_and_zoom {
/*
** Apply Matrices
*/
Tcl_Obj *pResult;
int i;
| > > > > > > > > > > > > > > > > > > > | 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 |
B[X_IDX]=x*scale;
B[Y_IDX]=y*scale;
Tcl_ListObjAppendElement(interp,pResult,VectorXY_To_TclObj(B));
}
Tcl_SetObjResult(interp, pResult);
return TCL_OK;
}
my c_tclcmd ::vectorxy::to_list {
int i;
VectorXY A;
Tcl_Obj *pResult;
if( objc != 2 ){
Tcl_WrongNumArgs(interp, 1, objv, "VECTORXY");
return TCL_ERROR;
}
if(Odie_GetVectorXYFromTclObj(interp,objv[1],A)) {
return TCL_ERROR;
}
pResult=Tcl_NewObj();
Tcl_ListObjAppendElement(interp,pResult,Tcl_NewDoubleObj(A[X_IDX]));
Tcl_ListObjAppendElement(interp,pResult,Tcl_NewDoubleObj(A[Y_IDX]));
Tcl_SetObjResult(interp, pResult);
return TCL_OK;
}
my c_tclcmd ::vectorxy::translate_and_zoom {
/*
** Apply Matrices
*/
Tcl_Obj *pResult;
int i;
|
| ︙ | ︙ | |||
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 |
B[X_IDX]=(A[X_IDX]/zoom)+center[X_IDX];
B[Y_IDX]=(A[Y_IDX]/zoom)+center[Y_IDX];
Tcl_ListObjAppendElement(interp,pResult,VectorXY_To_TclObj(B));
}
Tcl_SetObjResult(interp, pResult);
return TCL_OK;
}
my c_tclcmd ::vectorxy::flatten {
VectorXYZ point;
int i,j;
Tcl_Obj *pResult;
pResult=Tcl_NewObj();
if(objc==2) {
| > > > > > > > > > > > > > > > > > > | 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 |
B[X_IDX]=(A[X_IDX]/zoom)+center[X_IDX];
B[Y_IDX]=(A[Y_IDX]/zoom)+center[Y_IDX];
Tcl_ListObjAppendElement(interp,pResult,VectorXY_To_TclObj(B));
}
Tcl_SetObjResult(interp, pResult);
return TCL_OK;
}
my c_tclcmd ::vectorxy::assign {
int i;
VectorXY A;
Tcl_Obj *pResult;
if( objc != 4 ){
Tcl_WrongNumArgs(interp, 1, objv, "VECTORXY xvar yvar");
return TCL_ERROR;
}
if(Odie_GetVectorXYFromTclObj(interp,objv[1],A)) {
return TCL_ERROR;
}
Tcl_ObjSetVar2(interp,objv[2],NULL,Tcl_NewDoubleObj(A[X_IDX]),0);
Tcl_ObjSetVar2(interp,objv[3],NULL,Tcl_NewDoubleObj(A[Y_IDX]),0);
return TCL_OK;
}
my c_tclcmd ::vectorxy::flatten {
VectorXYZ point;
int i,j;
Tcl_Obj *pResult;
pResult=Tcl_NewObj();
if(objc==2) {
|
| ︙ | ︙ | |||
1159 1160 1161 1162 1163 1164 1165 |
Tcl_ListObjAppendElement(0, pResult, Tcl_NewDoubleObj(point[X_IDX]));
Tcl_ListObjAppendElement(0, pResult, Tcl_NewDoubleObj(point[Y_IDX]));
}
}
Tcl_SetObjResult(interp,pResult);
return TCL_OK;
}
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 |
Tcl_ListObjAppendElement(0, pResult, Tcl_NewDoubleObj(point[X_IDX]));
Tcl_ListObjAppendElement(0, pResult, Tcl_NewDoubleObj(point[Y_IDX]));
}
}
Tcl_SetObjResult(interp,pResult);
return TCL_OK;
}
###
# Adapted from:
# https://stackoverflow.com/questions/2142431/algorithm-for-creating-cells-by-spiral-on-the-hexagonal-field.
# Given an index, produce the X Y coordinates for the center of a tile radiating out from
# a hexagonal spiral
###
my c_function {static inline void VectorXY_getHexPosition(int i, VectorXY A)} {
int layer,side,idx,firstIdxInLayer;
if ( i == 0 ) { A[X_IDX] = A[Y_IDX] = 0.0; return; }
layer = (int) round(sqrt( i/3.0 ));
firstIdxInLayer = 3*layer*(layer-1) + 1;
side = (i - firstIdxInLayer) / layer; // note: this is integer division
idx = (i - firstIdxInLayer) % layer;
A[Y_IDX] = layer * cos( (side - 1) * M_PI/3.0 ) + (idx + 1) * cos( (side + 1) * M_PI/3.0 );
A[X_IDX] = -layer * sin( (side - 1) * M_PI/3.0 ) - (idx + 1) * sin( (side + 1) * M_PI/3.0 );
}
my c_tclcmd ::vectorxy::hex_tile_center {
VectorXY A,C,R;
int i;
double r=1.0;
if(objc != 2 && objc != 3 && objc != 4) {
Tcl_WrongNumArgs( interp, 1, objv, "i ?radius? ?CENTER_XY?" );
return TCL_ERROR;
}
if(Tcl_GetIntFromObj(interp,objv[1],&i)) return TCL_ERROR;
if(objc>2) {
if(Tcl_GetDoubleFromObj(interp,objv[2],&r)) return TCL_ERROR;
}
VectorXY_getHexPosition(i,C);
R[X_IDX]=C[X_IDX]*r;
R[Y_IDX]=C[Y_IDX]*r;
if(objc==4) {
if(Odie_GetVectorXYFromTclObj(interp,objv[3],A)) return TCL_ERROR;
R[X_IDX]+=A[X_IDX];
R[Y_IDX]+=A[Y_IDX];
}
Tcl_SetObjResult(interp,VectorXY_To_TclObj(R));
return TCL_OK;
}
|
Changes to cmodules/affine/vectorxyz.tcl.
| ︙ | ︙ | |||
1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 |
VectorXYZ one,two;
VectorXYZ_Subtract(one, B, A);
VectorXYZ_Subtract(two, C, A);
normal[X_IDX] = one[Y_IDX]*two[Z_IDX] - one[Z_IDX]*two[Y_IDX];
normal[Y_IDX] = one[Z_IDX]*two[X_IDX] - one[X_IDX]*two[Z_IDX];
normal[Z_IDX] = one[X_IDX]*two[Y_IDX] - one[Y_IDX]*two[X_IDX];
}
###
# Spit a stream of XYZ values into a stream of doubles
###
my c_tclcmd ::vectorxyz::flatten {
VectorXYZ point;
int i,j;
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 |
VectorXYZ one,two;
VectorXYZ_Subtract(one, B, A);
VectorXYZ_Subtract(two, C, A);
normal[X_IDX] = one[Y_IDX]*two[Z_IDX] - one[Z_IDX]*two[Y_IDX];
normal[Y_IDX] = one[Z_IDX]*two[X_IDX] - one[X_IDX]*two[Z_IDX];
normal[Z_IDX] = one[X_IDX]*two[Y_IDX] - one[Y_IDX]*two[X_IDX];
}
my c_tclcmd ::vectorxyz::to_list {
int i;
VectorXYZ A;
Tcl_Obj *pResult;
if( objc != 2 ){
Tcl_WrongNumArgs(interp, 1, objv, "VECTORXYZ");
return TCL_ERROR;
}
if(Odie_GetVectorXYZFromTclObj(interp,objv[1],A)) {
return TCL_ERROR;
}
pResult=Tcl_NewObj();
Tcl_ListObjAppendElement(interp,pResult,Tcl_NewDoubleObj(A[X_IDX]));
Tcl_ListObjAppendElement(interp,pResult,Tcl_NewDoubleObj(A[Y_IDX]));
Tcl_ListObjAppendElement(interp,pResult,Tcl_NewDoubleObj(A[Z_IDX]));
Tcl_SetObjResult(interp, pResult);
return TCL_OK;
}
my c_tclcmd ::vectorxyz::assign {
int i;
VectorXYZ A;
Tcl_Obj *pResult;
if( objc != 5 ){
Tcl_WrongNumArgs(interp, 1, objv, "VECTORXYZ xvar yvar zvar");
return TCL_ERROR;
}
if(Odie_GetVectorXYZFromTclObj(interp,objv[1],A)) {
return TCL_ERROR;
}
Tcl_ObjSetVar2(interp,objv[2],NULL,Tcl_NewDoubleObj(A[X_IDX]),0);
Tcl_ObjSetVar2(interp,objv[3],NULL,Tcl_NewDoubleObj(A[Y_IDX]),0);
Tcl_ObjSetVar2(interp,objv[4],NULL,Tcl_NewDoubleObj(A[Z_IDX]),0);
return TCL_OK;
}
###
# Spit a stream of XYZ values into a stream of doubles
###
my c_tclcmd ::vectorxyz::flatten {
VectorXYZ point;
int i,j;
|
| ︙ | ︙ |
Changes to cmodules/geometry/module.ini.
| ︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#endif
}
my code public-macro "
#ifndef RAD_TO_DEG
#define RAD_TO_DEG [expr {180.0/4*atan(1)}]
#endif
"
foreach {file} {
triangulate.tcl
polygon.tcl polygonxyz.tcl segset.tcl shapes.tcl
plotter.tcl slicer.tcl wallset.tcl faceset.tcl polyset.tcl
} {
| > > > > > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#endif
}
my code public-macro "
#ifndef RAD_TO_DEG
#define RAD_TO_DEG [expr {180.0/4*atan(1)}]
#endif
"
my code public-macro "
#ifndef DEG_TO_RAD
#define DEG_TO_RAD [expr {4*atan(1)/180.0}]
#endif
"
foreach {file} {
triangulate.tcl
polygon.tcl polygonxyz.tcl segset.tcl shapes.tcl
plotter.tcl slicer.tcl wallset.tcl faceset.tcl polyset.tcl
} {
|
| ︙ | ︙ |
Added cmodules/sprite/canvas.tcl.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
###
# Accelerators for Canvas Sprites
###
my c_tclproc_nspace ::sprite::canvas
my code tcl {}
my c_tclcmd ::sprite::vector_scale {
Tcl_Obj *pResult=Tcl_NewObj();
int i;
double scalex,scaley;
if( objc < 5 ){
Tcl_WrongNumArgs(interp, 1, objv, "sizex sizey x1 y1 ?x2 y2?...");
return TCL_ERROR;
}
if(Tcl_GetDoubleFromObj(interp,objv[1],&scalex)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[2],&scaley)) return TCL_ERROR;
scalex*=0.5;
scaley*=0.5;
for(i=3;i<objc;i+=2) {
double x,y,sx,sy;
if(Tcl_GetDoubleFromObj(interp,objv[i],&x)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[i+1],&y)) return TCL_ERROR;
sx=x*scalex;
sy=y*scaley;
Tcl_ListObjAppendElement(interp,pResult,Tcl_NewDoubleObj(sx));
Tcl_ListObjAppendElement(interp,pResult,Tcl_NewDoubleObj(sy));
}
Tcl_SetObjResult(interp, pResult);
return TCL_OK;
}
my c_tclcmd ::sprite::canvas::vector_place {
/*
** Apply Matrices
*/
Tcl_Obj *pResult=Tcl_NewObj();
int i;
double zoom;
double matA[6] = {1.0,0.0,0.0,1.0,0.0,0.0};
double centerx,centery,normalx,normaly,angle;
if( objc < 8 ){
Tcl_WrongNumArgs(interp, 1, objv, "zoom centerx centery normalx normaly x1 y1 ?x2 y2?...");
return TCL_ERROR;
}
if(Tcl_GetDoubleFromObj(interp,objv[1],&zoom)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[2],¢erx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[3],¢ery)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[4],&normalx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[5],&normaly)) return TCL_ERROR;
angle=atan2(normaly,normalx);
matA[0]=cos(angle);
matA[1]=sin(angle);
matA[2]=-sin(angle);
matA[3]=cos(angle);
matA[4]=0.0;
matA[5]=0.0;
for(i=6;i<objc;i+=2) {
double x,y,sx,sy,newx,newy;
if(Tcl_GetDoubleFromObj(interp,objv[i],&x)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[i+1],&y)) return TCL_ERROR;
sx=(x/zoom);
sy=(y/zoom);
newx=matA[0]*sx+matA[1]*sy+matA[4]+centerx;
newy=matA[2]*sx+matA[3]*sy+matA[5]+centery;
Tcl_ListObjAppendElement(interp,pResult,Tcl_NewDoubleObj(newx));
Tcl_ListObjAppendElement(interp,pResult,Tcl_NewDoubleObj(newy));
}
Tcl_SetObjResult(interp, pResult);
return TCL_OK;
}
|
Added cmodules/sprite/module.ini.
> > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
set here [file dirname [file normalize [info script]]]
#my define set output_c odielibc_geometry.c
my define set initfunc OdieGeometry_Init
my define add include_dir $here
my include [my <project> define get output_h]
my include {"inline_list.h"}
set loaded {}
my code tcl [::practcl::cat [file join $here sprite.tcl]]
foreach {file} {
canvas.tcl
svg.tcl
} {
lappend loaded [file join $here $file]
set obj [my add [file join $here $file]]
}
# polygonxyz.tcl
# Load the code in cmatrixforms directly
foreach file [glob [file join $here *.tcl]] {
if {$file ni $loaded} {
puts "Forget $file"
}
}
|
Added cmodules/sprite/sprite.tcl.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
namespace eval ::sprite {}
namespace eval ::sprite::svg {}
namespace eval ::sprite::canvas {}
proc ::sprite::default {} {
return {
base polygon
symbol {}
door_mode 0
square_mode 0
square_base 0
label {}
labelscale 1.0
}
}
proc ::sprite::define {name {info {}}} {
variable shapes
set shapedat [default]
foreach {var val} $info {
dict set shapedat $var $val
}
set shapes($name) $shapedat
return $name
}
proc ::sprite::export {} {
set fn [tk_getSaveFile -filetypes {{{Shape Files} .irmshape}} -parent .]
if { $fn eq {} } {
return
}
set fout [open $fn w]
puts $fout {
###
# Sprite file export
###
}
set default [::sprite::default]
foreach {shape info} [lsort -stride 2 -dictionary [array get ::shapes::shapes]] {
puts $fout "::shapes::define \{$shape\} \{"
foreach {var val} [lsort -stride 2 -dictionary $info] {
if {[dict getnull $default $var] eq $val } continue
puts $fout " [list $var $val]"
}
puts $fout \}
}
close $fout
}
proc ::sprite::canvas::build {shape sizex sizey baseopts symbolopts {zoom 1.0}} {
set commands {}
###
# Build a list of canvas commands
###
variable shapes
if {[info exists ::sprite::shapes($shape)]} {
set dat $::sprite::shapes($shape)
} else {
set dat {base polygon symbol {} door_mode 0 square_mode 0 square_base 0 label {}}
}
set labelscale 1.0
dict with dat {}
set prim [lindex $base 0]
set opts [lindex $base 1]
switch $prim {
"hexagon" {
set cmd polygon
set box {1.00 0.00 0.50 0.87 -0.50 0.87 -1.00 -0.00 -0.50 -0.87 0.50 -0.86}
}
"triangle" {
set cmd polygon
set box {1.00 1.00 0.0 -1.0 -1.0 1.0}
}
"inv_triangle" {
set cmd polygon
set box {1.00 -1.00 0.0 1.0 -1.0 -1.0}
}
"rowtie" -
"bowtie" {
set cmd polygon
if { $sizex > $sizey } {
set box {-1 -1 1 1 1 -1 -1 1}
} else {
set box {-1 -1 1 1 -1 1 1 -1}
}
}
chevron {
set cmd polygon
set box {-1 -1 1 -1 1 0 0 1 -1 0}
}
"cylinder" -
"rectangle" {
set cmd "rectangle"
set box {-1 -1 1 1}
}
"sphere" -
"oval" {
set cmd "oval"
set box {-1 -1 1 1}
}
"staircase" {
set cmd polygon
set box {-1.0 -0.1 1.0 -0.1 1.0 1.9 -1.0 1.9}
}
"polygon" -
default {
set cmd polygon
set box {-1 -1 1 -1 1 1 -1 1}
}
}
if {$square_base} {
if { $sizex > $sizey } {
set sizey $sizex
} else {
set sizex $sizey
}
}
lappend commands $cmd [::sprite::vector_scale $sizex $sizey {*}$box] [list {*}${opts} {*}${baseopts}]
if {$zoom>200} {
return $commands
}
set swid $sizex
set shgt $sizey
switch $door_mode {
0 {
if { $square_mode } {
if { $sizex > $sizey } {
set swid $sizey
set shgt $sizey
} else {
set swid $sizex
set shgt $sizex
}
}
}
1 {
###
# Scale the width to the height
set swid $sizey
}
}
foreach {type pt style} $symbol {
set opts $symbolopts
if { $type != "line" } {
set opts [string map {-fill -outline} $opts]
}
lappend opts {*}$style
if { $prim eq "staircase" } {
set old $pt
set pt {}
foreach {x y} $old {
lappend pt $x [expr {$y+.9}]
}
}
lappend commands $type [::sprite::vector_scale $swid $shgt {*}$pt] $opts
}
if {$zoom > 100} {
return $commands
}
if { $label != {} && abs($swid) > 10.0 } {
set text $label
set l [string length $text]
if { [string range $label 0 1] == "/u"} {
set text [format "%c" 0x[string range $label 2 end]]
set l 1
}
lappend commands text {1.0 1.0} [list -text $text {*}$symbolopts -justify right -width 0 -font [expr {round($labelscale*abs($swid)/$l)}]]
}
puts $commands
return $commands
}
proc ::sprite::canvas::render {can2d zoom cx cy nx ny commands} {
foreach {command coords options} $commands {
if { $command eq "text" } {
set size [lindex $options end]
set options [lreplace $options end end [list Consolas [expr {round($size*${::shapes::labelscale}/$zoom)}]]]
}
$can2d create $command {*}[vector_place $zoom $cx $cy $nx $ny {*}$coords] {*}$options
}
}
proc ::sprite::svg::build {shape sizex sizey baseopts symbolopts {zoom 1.0}} {
# Start with a stream of Tk Canvas instructions
# But invert the Y axis, because SVG's coordinate system is upside down wrt to the Tk Canvas
set canvas_commands [::sprite::canvas::build $shape $sizex $sizey $baseopts $symbolopts $zoom]
set result {}
foreach {command coords options} $canvas_commands {
switch $command {
arc {
# Todo
set start 0
set end 360
if {[dict exists $options -start]} {
set start [dict get $options -start]
}
if {[dict exists $options -end]} {
set end [dict get $options -end]
}
append result "<path [arc_to_path $start $end {*}$coords] [css_from_line $options] />"
}
line {
append result "<polyline [coords_to_points {*}$coords] [css_from_line $options] />"
}
oval {
append result "<ellipse [coords_to_ellipse {*}$coords] [css_from_shape $options] />"
}
polygon {
append result "<polygon [coords_to_points {*}$coords] [css_from_shape $options] />"
}
rectangle {
append result "<rect [coords_to_rect {*}$coords] [css_from_shape $options] />"
}
text {
if {![dict exists $options -anchor]} {
set anchor center
} else {
set anchor [dict get $options -anchor]
}
if {![dict exists $options -font]} {
set fontinfo {-family Helvetica -size 13 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 12 -descent 3 -linespace 15 -fixed 0}
} else {
set fontinfo [font_metrics [dict get $options -font]]
}
lassign $coords x y
append result "<text [coords_to_text $anchor $fontinfo $x $y] [css_from_text $options $fontinfo $anchor]>"
set lines [split [dict get $options -text] \n]
if {[llength $lines] > 1} {
set fontsize [css_font_size $options]
append result "[lindex $lines 0]"
set dy [dict get $fontinfo -linespace]
set ly $y
foreach line [lrange $lines 1 end] {
set ly [expr $y + $dy]
append result "<tspan [coords_to_text $anchor $fontinfo $x $ly] [css_from_text $options $fontinfo $anchor]>$line</tspan>
}
} else {
append result [dict get $options -text]
}
append result "</text>"
}
}
}
return $result
}
proc ::sprite::svg::dict_to_style {dict} {
if {[dict size $dict]==0} {
return {}
}
set output "style=\""
dict for {f v} $dict {
append output ${f} : ${v} \;
}
append output \"
return $output
}
proc ::sprite::svg::css_from_line options {
set result {stroke-width 0.5 stroke black fill none}
dict for {opt value} $options {
switch $opt {
-width {
dict set result stroke-width $value
}
-fill {
dict set result stroke $value
}
-outline {
dict set result stroke $value
}
}
}
return [dict_to_style $result]
}
proc ::sprite::svg::css_from_shape options {
set result {stroke-width 0.5 stroke black fill none}
dict for {opt value} $options {
switch $opt {
-width {
dict set result stroke-width $value
}
-fill {
dict set result fill $value
}
-outline {
dict set result stroke $value
}
}
}
return [dict_to_style $result]
}
proc ::sprite::svg::css_from_text {options fontinfo anchor} {
set result {
stroke none fill black
text-anchor middle
dominant-baseline middle
}
dict for {opt value} $options {
switch $opt {
-fill {
dict set result fill $value
}
-outline {
dict set result stroke $value
}
-justify {
dict set result text-align $value
}
}
}
dict set result font-family "\"[dict get $fontinfo -family]\""
dict set result font-size [dict get $fontinfo -size]
switch [dict get $fontinfo -weight] {
bold {
dict set result font-weight bold
}
}
switch [dict get $fontinfo -slant] {
italic {
dict set result font-style italic
}
}
set decoration {}
if {[dict get $fontinfo -underline]} {
lappend decoration underline
}
if {[dict get $fontinfo -overstrike]} {
lappend decoration line-through
}
if {[llength $decoration]} {
dict set result text-decoration $decoration
}
switch $anchor {
n {
dict set result text-anchor middle
dict set result dominant-baseline hanging
}
ne {
dict set result text-anchor start
dict set result dominant-baseline hanging
}
e {
dict set result text-anchor start
dict set result dominant-baseline middle
}
se {
dict set result text-anchor start
dict set result dominant-baseline baseline
}
s {
dict set result text-anchor middle
dict set result dominant-baseline baseline
}
sw {
dict set result text-anchor end
dict set result dominant-baseline baseline
}
w {
dict set result text-anchor end
dict set result dominant-baseline middle
}
nw {
dict set result text-anchor end
dict set result dominant-baseline hanging
}
center {
dict set result text-anchor middle
dict set result dominant-baseline middle
}
}
return [dict_to_style $result]
}
set ::sprite::named_fonts {}
proc ::sprite::svg::named_font {name attrib} {
set name [string tolower $name]
dict for {f v} $attrib {
dict set ::sprite::named_fonts $name $f $v
}
}
if {[info commands ::font] eq {}} {
###
# Running without Tk, use fallback emulator for ::font
###
::sprite::svg::named_font application {-family Sans -size 13 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 13 -descent 3 -linespace 16 -fixed 0}
::sprite::svg::named_font courier {-family Courier -size 13 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 10 -descent 3 -linespace 13 -fixed 1}
::sprite::svg::named_font helvetica {-family Helvetica -size 13 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 12 -descent 3 -linespace 15 -fixed 0}
::sprite::svg::named_font menu {-family Sans -size 14 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 14 -descent 3 -linespace 17 -fixed 0}
::sprite::svg::named_font system {-family Sans -size 13 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 13 -descent 3 -linespace 16 -fixed 0}
::sprite::svg::named_font systemAlertHeaderFont {-family Sans -size 13 -weight bold -slant roman -underline 0 -overstrike 0 -ascent 14 -descent 3 -linespace 17 -fixed 0}
::sprite::svg::named_font systemApplicationFont {-family Sans -size 13 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 13 -descent 3 -linespace 16 -fixed 0}
::sprite::svg::named_font systemDetailEmphasizedSystemFont {-family Sans -size 9 -weight bold -slant roman -underline 0 -overstrike 0 -ascent 10 -descent 2 -linespace 12 -fixed 0}
::sprite::svg::named_font systemDetailSystemFont {-family Sans -size 9 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 9 -descent 2 -linespace 11 -fixed 0}
::sprite::svg::named_font systemEmphasizedSystemFont {-family Sans -size 13 -weight bold -slant roman -underline 0 -overstrike 0 -ascent 14 -descent 3 -linespace 17 -fixed 0}
::sprite::svg::named_font systemLabelFont {-family Sans -size 10 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 10 -descent 2 -linespace 12 -fixed 0}
::sprite::svg::named_font systemMenuItemCmdKeyFont {-family .Keyboard -size 14 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 16 -descent 11 -linespace 27 -fixed 0}
::sprite::svg::named_font systemMenuItemFont {-family Sans -size 14 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 14 -descent 3 -linespace 17 -fixed 0}
::sprite::svg::named_font systemMenuItemMarkFont {-family Sans -size 14 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 14 -descent 3 -linespace 17 -fixed 0}
::sprite::svg::named_font systemMenuTitleFont {-family Sans -size 14 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 14 -descent 3 -linespace 17 -fixed 0}
::sprite::svg::named_font systemMiniSystemFont {-family Sans -size 9 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 9 -descent 2 -linespace 11 -fixed 0}
::sprite::svg::named_font systemPushButtonFont {-family Sans -size 13 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 13 -descent 3 -linespace 16 -fixed 0}
::sprite::svg::named_font systemSmallEmphasizedSystemFont {-family Sans -size 11 -weight bold -slant roman -underline 0 -overstrike 0 -ascent 12 -descent 2 -linespace 14 -fixed 0}
::sprite::svg::named_font systemSmallSystemFont {-family Sans -size 11 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 11 -descent 2 -linespace 13 -fixed 0}
::sprite::svg::named_font systemSystemFont {-family Sans -size 13 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 13 -descent 3 -linespace 16 -fixed 0}
::sprite::svg::named_font systemToolbarFont {-family Sans -size 11 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 11 -descent 2 -linespace 13 -fixed 0}
::sprite::svg::named_font systemUtilityWindowTitleFont {-family Sans -size 11 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 11 -descent 2 -linespace 13 -fixed 0}
::sprite::svg::named_font systemViewsFont {-family Sans -size 12 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 12 -descent 3 -linespace 15 -fixed 0}
::sprite::svg::named_font systemWindowTitleFont {-family Sans -size 13 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 13 -descent 3 -linespace 16 -fixed 0}
::sprite::svg::named_font times {-family Times -size 13 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 12 -descent 3 -linespace 15 -fixed 0}
::sprite::svg::named_font TkCaptionFont {-family Sans -size 13 -weight bold -slant roman -underline 0 -overstrike 0 -ascent 14 -descent 3 -linespace 17 -fixed 0}
::sprite::svg::named_font TkDefaultFont {-family Sans -size 13 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 13 -descent 3 -linespace 16 -fixed 0}
::sprite::svg::named_font TkFixedFont {-family Monaco -size 11 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 12 -descent 3 -linespace 15 -fixed 1}
::sprite::svg::named_font TkHeadingFont {-family Sans -size 11 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 11 -descent 2 -linespace 13 -fixed 0}
::sprite::svg::named_font TkIconFont {-family Sans -size 13 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 13 -descent 3 -linespace 16 -fixed 0}
::sprite::svg::named_font TkMenuFont {-family Sans -size 14 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 14 -descent 3 -linespace 17 -fixed 0}
::sprite::svg::named_font TkSmallCaptionFont {-family Sans -size 10 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 10 -descent 2 -linespace 12 -fixed 0}
::sprite::svg::named_font TkTextFont {-family Sans -size 13 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 13 -descent 3 -linespace 16 -fixed 0}
::sprite::svg::named_font TkTooltipFont {-family Sans -size 11 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 11 -descent 2 -linespace 13 -fixed 0}
proc ::sprite::svg::font_metrics string {
if {[dict exists $::sprite::named_fonts [string tolower $string]]} {
return [dict get $::sprite::named_fonts [string tolower $string]]
}
set result {-family Sans -size 16 -weight normal -slant roman -underline 0 -overstrike 0 -ascent 15 -descent 4 -linespace 19 -fixed 0}
set n [llength $string]
if {$n<=0} {
return $result
}
if {$n==1 && [string is integer [lindex $string 0]]} {
dict set result -size [lindex $string 0]
return $result
}
dict set result -family [lindex $string 0]
if {$n < 2} {
return $result
}
set size [lindex $string 1]
dict set result -size $size
dict set result -ascent $size
dict set result -descent [expr {$size/4}]
dict set result -linespace [expr {$size+$size/4}]
if {[string tolower $family] in {consolas system courier fixed typewriter}} {
dict set result -fixed 1
}
foreach item [lrange $string 2 end] {
switch $item {
bold {
dict set result -weight bold
}
italic {
dict set result -slant italic
}
underline {
dict set result -underline 1
}
overstrike {
dict set result -overstrike 1
}
}
}
return $result
}
} else {
proc ::sprite::svg::font_metrics {string} {
if {[dict exists $::sprite::named_fonts [string tolower $string]]} {
return [dict get $::sprite::named_fonts [string tolower $string]]
}
return [dict create {*}[font actual $string] {*}[font metrics $string]]
}
}
proc ::sprite::svg::css_font_options string {
set fontinfo [font_metrics $string]
return $reply
}
proc ::sprite::svg::coords_to_text {anchor fontinfo cx cy} {
set result " x=\"$cx\" y=\"$cy\""
return $result
}
proc ::sprite::svg::coords_to_points args {
foreach {x y} $args {
append result " $x,$y "
}
return "points=\"$result\""
}
|
Added cmodules/sprite/svg.tcl.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
###
# Accelerators for SVG Sprites
###
my c_tclproc_nspace ::sprite::svg
my c_tclcmd ::sprite::svg::bbox_overlap {
MATOBJ *A,*B;
int c;
if( objc != 3 ){
Tcl_WrongNumArgs(interp, 1, objv, "BBOX BBOX");
return TCL_ERROR;
}
if(Odie_GetMatrixFromTclObj(interp,objv[1],MATFORM_bbox_xy,&A)) return TCL_ERROR;
if(Odie_GetMatrixFromTclObj(interp,objv[2],MATFORM_bbox_xy,&B)) return TCL_ERROR;
c=BBOX_BBOX_Intersect(A->matrix,B->matrix);
Tcl_SetObjResult(interp, Tcl_NewIntObj(c));
return TCL_OK;
}
my c_tclcmd ::sprite::svg::coords_to_bbox {
MATOBJ *C;
double x1,y1,x2,y2;
double maxx,maxy,minx,miny;
if( objc != 5 ){
Tcl_WrongNumArgs(interp, 1, objv, "x1 y1 x2 y2");
return TCL_ERROR;
}
if(Tcl_GetDoubleFromObj(interp,objv[1],&x1)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[2],&y1)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[3],&x2)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[4],&y2)) return TCL_ERROR;
C=Odie_MatrixObj_Create(MATFORM_bbox_xy);
VectorXY_BBOX_Reset(C->matrix);
C->matrix[BBOX_X0_IDX]=min(x1,x2);
C->matrix[BBOX_X1_IDX]=max(x1,x2);
C->matrix[BBOX_Y0_IDX]=min(y1,y2);
C->matrix[BBOX_Y1_IDX]=max(y1,y2);
Tcl_SetObjResult(interp,Matrix_To_TclObj(C));
return TCL_OK;
}
my c_tclcmd ::sprite::svg::rect_to_bbox {
MATOBJ *C;
double centerx,centery,dx,dy;
double maxx,maxy,minx,miny;
if( objc != 5 ){
Tcl_WrongNumArgs(interp, 1, objv, "minx miny sizex sizey");
return TCL_ERROR;
}
if(Tcl_GetDoubleFromObj(interp,objv[1],&minx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[2],&miny)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[3],&dx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[4],&dy)) return TCL_ERROR;
maxx=minx+dx;
maxy=miny+dy;
C=Odie_MatrixObj_Create(MATFORM_bbox_xy);
VectorXY_BBOX_Reset(C->matrix);
C->matrix[BBOX_X0_IDX]=min(minx,maxx);
C->matrix[BBOX_X1_IDX]=max(minx,maxx);
C->matrix[BBOX_Y0_IDX]=min(miny,maxy);
C->matrix[BBOX_Y1_IDX]=max(miny,maxy);
Tcl_SetObjResult(interp,Matrix_To_TclObj(C));
return TCL_OK;
}
my c_tclcmd ::sprite::svg::arc_to_path {
double start,end;
double centerx,centery,rx,ry,sx,sy,ex,ey;
double maxx,maxy,minx,miny;
int largearc;
if( objc != 7 ){
Tcl_WrongNumArgs(interp, 1, objv, "start end minx miny maxx maxy");
return TCL_ERROR;
}
if(Tcl_GetDoubleFromObj(interp,objv[1],&start)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[2],&end)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[3],&minx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[4],&miny)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[5],&maxx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[6],&maxy)) return TCL_ERROR;
rx=(maxx-minx)*0.5;
ry=(maxy-miny)*0.5;
centerx=rx+minx;
centery=ry+miny;
sx=centerx+cos(start*DEG_TO_RAD)*rx;
sy=centery+sin(start*DEG_TO_RAD)*ry;
ex=centerx+cos((start+end)*DEG_TO_RAD)*rx;
ey=centery+sin((start+end)*DEG_TO_RAD)*ry;
if(end<=0 || end>180) {
largearc=1;
} else {
largearc=0;
}
Tcl_SetObjResult(interp, Tcl_ObjPrintf("M %f %f A %f %f, 0, %d, 0, %f %f",sx,sy,fabs(rx),fabs(ry),largearc,ex,ey));
return TCL_OK;
}
my c_tclcmd ::sprite::svg::ellipse_to_bbox {
MATOBJ *C;
double centerx,centery,dx,dy;
double maxx,maxy,minx,miny;
if( objc != 5 ){
Tcl_WrongNumArgs(interp, 1, objv, "centerx centery sizex sizey");
return TCL_ERROR;
}
if(Tcl_GetDoubleFromObj(interp,objv[1],¢erx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[2],¢ery)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[3],&dx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[4],&dy)) return TCL_ERROR;
minx=centerx-dx*0.5;
miny=centery-dy*0.5;
maxx=centerx+dx*0.5;
maxy=centery+dy*0.5;
C=Odie_MatrixObj_Create(MATFORM_bbox_xy);
VectorXY_BBOX_Reset(C->matrix);
C->matrix[BBOX_X0_IDX]=min(minx,maxx);
C->matrix[BBOX_X1_IDX]=max(minx,maxx);
C->matrix[BBOX_Y0_IDX]=min(miny,maxy);
C->matrix[BBOX_Y1_IDX]=max(miny,maxy);
Tcl_SetObjResult(interp,Matrix_To_TclObj(C));
return TCL_OK;
}
my c_tclcmd ::sprite::svg::coords_to_ellipse {
double centerx,centery,rx,ry;
double maxx,maxy,minx,miny;
if( objc != 5 ){
Tcl_WrongNumArgs(interp, 1, objv, "x1 y1 x2 y2");
return TCL_ERROR;
}
if(Tcl_GetDoubleFromObj(interp,objv[1],&minx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[2],&miny)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[3],&maxx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[4],&maxy)) return TCL_ERROR;
rx=(maxx-minx)*0.5;
ry=(maxy-miny)*0.5;
centerx=rx+minx;
centery=ry+miny;
Tcl_SetObjResult(interp, Tcl_ObjPrintf("cx=\"%f\" cy=\"%f\" rx=\"%f\" ry=\"%f\"",centerx,centery,fabs(rx),fabs(ry)));
return TCL_OK;
}
my c_tclcmd ::sprite::svg::coords_to_ellipse_dict {
double centerx,centery,rx,ry;
double maxx,maxy,minx,miny;
Tcl_Obj *pResult;
if( objc != 5 ){
Tcl_WrongNumArgs(interp, 1, objv, "x1 y1 x2 y2");
return TCL_ERROR;
}
if(Tcl_GetDoubleFromObj(interp,objv[1],&minx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[2],&miny)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[3],&maxx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[4],&maxy)) return TCL_ERROR;
rx=(maxx-minx)*0.5;
ry=(maxy-miny)*0.5;
centerx=rx+minx;
centery=ry+miny;
pResult=Tcl_NewObj();
Odie_DictObjPut(interp,pResult,"cx",Tcl_NewDoubleObj(centerx));
Odie_DictObjPut(interp,pResult,"cy",Tcl_NewDoubleObj(centery));
Odie_DictObjPut(interp,pResult,"rx",Tcl_NewDoubleObj(fabs(rx)));
Odie_DictObjPut(interp,pResult,"ry",Tcl_NewDoubleObj(fabs(ry)));
Tcl_SetObjResult(interp,pResult);
return TCL_OK;
}
my c_tclcmd ::sprite::svg::bbox_to_ellipse {
MATOBJ *C;
double centerx,centery,rx,ry;
double maxx,maxy,minx,miny;
if( objc != 2 ){
Tcl_WrongNumArgs(interp, 1, objv, "BBOX");
return TCL_ERROR;
}
if(Odie_GetMatrixFromTclObj(interp,objv[1],MATFORM_bbox_xy,&C)) return TCL_ERROR;
minx=C->matrix[BBOX_X0_IDX];
miny=C->matrix[BBOX_Y0_IDX];
maxx=C->matrix[BBOX_X1_IDX];
maxy=C->matrix[BBOX_Y1_IDX];
rx=(maxx-minx)*0.5;
ry=(maxy-miny)*0.5;
centerx=rx+minx;
centery=ry+miny;
Tcl_SetObjResult(interp, Tcl_ObjPrintf("cx=\"%f\" cy=\"%f\" rx=\"%f\" ry=\"%f\"",centerx,centery,fabs(rx),fabs(ry)));
return TCL_OK;
}
my c_tclcmd ::sprite::svg::bbox_to_ellipse_dict {
MATOBJ *C;
double centerx,centery,rx,ry;
double maxx,maxy,minx,miny;
Tcl_Obj *pResult;
if( objc != 2 ){
Tcl_WrongNumArgs(interp, 1, objv, "BBOX");
return TCL_ERROR;
}
if(Odie_GetMatrixFromTclObj(interp,objv[1],MATFORM_bbox_xy,&C)) return TCL_ERROR;
minx=C->matrix[BBOX_X0_IDX];
miny=C->matrix[BBOX_Y0_IDX];
maxx=C->matrix[BBOX_X1_IDX];
maxy=C->matrix[BBOX_Y1_IDX];
rx=(maxx-minx)*0.5;
ry=(maxy-miny)*0.5;
centerx=rx+minx;
centery=ry+miny;
pResult=Tcl_NewObj();
Odie_DictObjPut(interp,pResult,"cx",Tcl_NewDoubleObj(centerx));
Odie_DictObjPut(interp,pResult,"cy",Tcl_NewDoubleObj(centery));
Odie_DictObjPut(interp,pResult,"rx",Tcl_NewDoubleObj(fabs(rx)));
Odie_DictObjPut(interp,pResult,"ry",Tcl_NewDoubleObj(fabs(ry)));
Tcl_SetObjResult(interp,pResult);
return TCL_OK;
}
my c_tclcmd ::sprite::svg::coords_to_rect {
/*
** Apply Matrices
*/
double dx,dy;
double maxx,maxy,minx,miny;
if( objc != 5 ){
Tcl_WrongNumArgs(interp, 1, objv, "x1 y1 x2 y2");
return TCL_ERROR;
}
if(Tcl_GetDoubleFromObj(interp,objv[1],&minx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[2],&miny)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[3],&maxx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[4],&maxy)) return TCL_ERROR;
dx=fabs(maxx-minx);
dy=fabs(maxy-miny);
Tcl_SetObjResult(interp, Tcl_ObjPrintf("x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\"",min(minx,maxx),min(miny,maxy),dx,dy));
return TCL_OK;
}
my c_tclcmd ::sprite::svg::coords_to_rectdict {
/*
** Apply Matrices
*/
double dx,dy;
double maxx,maxy,minx,miny;
Tcl_Obj *pResult;
if( objc != 5 ){
Tcl_WrongNumArgs(interp, 1, objv, "x1 y1 x2 y2");
return TCL_ERROR;
}
if(Tcl_GetDoubleFromObj(interp,objv[1],&minx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[2],&miny)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[3],&maxx)) return TCL_ERROR;
if(Tcl_GetDoubleFromObj(interp,objv[4],&maxy)) return TCL_ERROR;
dx=fabs(maxx-minx);
dy=fabs(maxy-miny);
pResult=Tcl_NewObj();
Odie_DictObjPut(interp,pResult,"x",Tcl_NewDoubleObj(min(minx,maxx)));
Odie_DictObjPut(interp,pResult,"y",Tcl_NewDoubleObj(min(miny,maxy)));
Odie_DictObjPut(interp,pResult,"width",Tcl_NewDoubleObj(dx));
Odie_DictObjPut(interp,pResult,"height",Tcl_NewDoubleObj(dy));
Tcl_SetObjResult(interp,pResult);
return TCL_OK;
}
my c_tclcmd ::sprite::svg::bbox_to_rect {
MATOBJ *C;
double dx,dy;
double maxx,maxy,minx,miny;
if( objc != 2 ){
Tcl_WrongNumArgs(interp, 1, objv, "BBOX");
return TCL_ERROR;
}
if(Odie_GetMatrixFromTclObj(interp,objv[1],MATFORM_bbox_xy,&C)) return TCL_ERROR;
minx=C->matrix[BBOX_X0_IDX];
miny=C->matrix[BBOX_Y0_IDX];
maxx=C->matrix[BBOX_X1_IDX];
maxy=C->matrix[BBOX_Y1_IDX];
dx=fabs(maxx-minx);
dy=fabs(maxy-miny);
Tcl_SetObjResult(interp, Tcl_ObjPrintf("x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\"",min(minx,maxx),min(miny,maxy),dx,dy));
return TCL_OK;
}
my c_tclcmd ::sprite::svg::bbox_to_rect_dict {
MATOBJ *C;
double dx,dy;
double maxx,maxy,minx,miny;
Tcl_Obj *pResult;
if( objc != 2 ){
Tcl_WrongNumArgs(interp, 1, objv, "BBOX");
return TCL_ERROR;
}
if(Odie_GetMatrixFromTclObj(interp,objv[1],MATFORM_bbox_xy,&C)) return TCL_ERROR;
minx=C->matrix[BBOX_X0_IDX];
miny=C->matrix[BBOX_Y0_IDX];
maxx=C->matrix[BBOX_X1_IDX];
maxy=C->matrix[BBOX_Y1_IDX];
dx=fabs(maxx-minx);
dy=fabs(maxy-miny);
pResult=Tcl_NewObj();
Odie_DictObjPut(interp,pResult,"x",Tcl_NewDoubleObj(min(minx,maxx)));
Odie_DictObjPut(interp,pResult,"y",Tcl_NewDoubleObj(min(miny,maxy)));
Odie_DictObjPut(interp,pResult,"width",Tcl_NewDoubleObj(dx));
Odie_DictObjPut(interp,pResult,"height",Tcl_NewDoubleObj(dy));
Tcl_SetObjResult(interp,pResult);
return TCL_OK;
}
|
Changes to library.ini.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
###
# Define the sources needed to implement odielibc
###
set CWD [my define get builddir]
set SRCPATH [file normalize [file join $CWD [file dirname [info script]]]]
my include [my define get output_h]
foreach module {
linklist hash odieutil btree odiemath
affine fuzzy geometry imgscale listcmd logicset literal typespec
} {
if {[file exists [file join $SRCPATH cmodules $module module.ini]]} {
my add [file join $SRCPATH cmodules $module module.ini]
} elseif {[file exists [file join $SRCPATH cmodules $module $module.tcl]]} {
my add [file join $SRCPATH cmodules $module $module.tcl]
} else {
puts "WARNING: SKIPPED $module"
| > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
###
# Define the sources needed to implement odielibc
###
set CWD [my define get builddir]
set SRCPATH [file normalize [file join $CWD [file dirname [info script]]]]
my include [my define get output_h]
foreach module {
linklist hash odieutil btree odiemath
affine fuzzy geometry imgscale listcmd logicset literal typespec
sprite
} {
if {[file exists [file join $SRCPATH cmodules $module module.ini]]} {
my add [file join $SRCPATH cmodules $module module.ini]
} elseif {[file exists [file join $SRCPATH cmodules $module $module.tcl]]} {
my add [file join $SRCPATH cmodules $module $module.tcl]
} else {
puts "WARNING: SKIPPED $module"
|
| ︙ | ︙ |