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 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 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 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 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 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 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 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 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 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 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 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 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 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206
|
@c -*- mode: Noweb; noweb-doc-mode: texinfo-mode; noweb-code-mode: c-mode -*-
@node File o_line_basic.c,,,Top
@chapter File @file{o_line_basic.c}
@section File header
@format
@anchor{o_line_basic.c - -root-}
@i{<<o_line_basic.c : *>>=}@t{
@i{<<o_line_basic.c : copyright and license -- @ref{o_line_basic.c - copyright and license}>>}
/* DO NOT read or edit this file ! Use ../noweb/o_line_basic.nw instead */
@i{<<o_line_basic.c : include directives -- @ref{o_line_basic.c - include directives}>>}
@i{<<o_line_basic.c : o_line_add() -- @ref{o_line_basic.c - o_line_add()}>>}
@i{<<o_line_basic.c : o_line_copy() -- @ref{o_line_basic.c - o_line_copy()}>>}
@i{<<o_line_basic.c : o_line_modify() -- @ref{o_line_basic.c - o_line_modify()}>>}
@i{<<o_line_basic.c : o_line_read() -- @ref{o_line_basic.c - o_line_read()}>>}
@i{<<o_line_basic.c : o_line_save() -- @ref{o_line_basic.c - o_line_save()}>>}
@i{<<o_line_basic.c : o_line_translate() -- @ref{o_line_basic.c - o_line_translate()}>>}
@i{<<o_line_basic.c : o_line_translate_world() -- @ref{o_line_basic.c - o_line_translate_world()}>>}
@i{<<o_line_basic.c : o_line_rotate() -- @ref{o_line_basic.c - o_line_rotate()}>>}
@i{<<o_line_basic.c : o_line_rotate_world() -- @ref{o_line_basic.c - o_line_rotate_world()}>>}
@i{<<o_line_basic.c : o_line_mirror() -- @ref{o_line_basic.c - o_line_mirror()}>>}
@i{<<o_line_basic.c : o_line_mirror_world() -- @ref{o_line_basic.c - o_line_mirror_world()}>>}
@i{<<o_line_basic.c : o_line_recalc() -- @ref{o_line_basic.c - o_line_recalc()}>>}
@i{<<o_line_basic.c : get_line_bounds() -- @ref{o_line_basic.c - get_line_bounds()}>>}
@i{<<o_line_basic.c : world_get_line_bounds() -- @ref{o_line_basic.c - world_get_line_bounds()}>>}
@i{<<o_line_basic.c : o_line_print() -- @ref{o_line_basic.c - o_line_print()}>>}
@i{<<o_line_basic.c : o_line_print_solid() -- @ref{o_line_basic.c - o_line_print_solid()}>>}
@i{<<o_line_basic.c : o_line_print_dotted() -- @ref{o_line_basic.c - o_line_print_dotted()}>>}
@i{<<o_line_basic.c : o_line_print_dashed() -- @ref{o_line_basic.c - o_line_print_dashed()}>>}
@i{<<o_line_basic.c : o_line_print_center() -- @ref{o_line_basic.c - o_line_print_center()}>>}
@i{<<o_line_basic.c : o_line_print_phantom() -- @ref{o_line_basic.c - o_line_print_phantom()}>>}
#if 0 /* original way of printing line, no longer used */
@i{<<o_line_basic.c : o_line_print_old() -- @ref{o_line_basic.c - o_line_print_old()}>>}
#endif
@i{<<o_line_basic.c : o_line_image_write() -- @ref{o_line_basic.c - o_line_image_write()}>>}
@i{<<o_line_basic.c : o_line_scale_world() -- @ref{o_line_basic.c - o_line_scale_world()}>>}
@i{<<o_line_basic.c : o_line_visible() -- @ref{o_line_basic.c - o_line_visible()}>>}
@i{<<o_line_basic.c : o_line_length() -- @ref{o_line_basic.c - o_line_length()}>>}
}
@end format
@format
@anchor{o_line_basic.c - copyright and license}
@i{<<o_line_basic.c : copyright and license>>=}@t{
/* gEDA - GPL Electronic Design Automation
* libgeda - gEDA's library
* Copyright (C) 1998-2000 Ales V. Hvezda
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
*/
}
@end format
@format
@anchor{o_line_basic.c - include directives}
@i{<<o_line_basic.c : include directives>>=}@t{
#include <config.h>
#include <stdio.h>
#include <math.h>
#include <gtk/gtk.h>
#include <libguile.h>
#ifdef HAS_LIBGDGEDA
#include <gdgeda/gd.h>
#endif
#include "defines.h"
#include "struct.h"
#include "globals.h"
#include "o_types.h"
#include "colors.h"
#include "funcs.h"
#include "../include/prototype.h"
#ifdef HAVE_LIBDMALLOC
#include <dmalloc.h>
#endif
}
@end format
@section Function @code{o_line_add()}
@defun o_line_add w_current object_list type color x1 y1 x2 y2
This function creates a new object representing a line. This object is added to the end of the list @code{object_list} pointed object belongs to.
The line is described by its two ends - @code{x1},@code{y1} and @code{x2},@code{y2}.
The @code{type} parameter must be equal to @code{OBJ_LINE}. The @code{color} parameter corresponds to the color the box will be drawn with.
@end defun
The @code{OBJECT} structure is allocated with the @code{s_basic_init_object()} function. The structure describing the line is allocated and initialized with the parameters given to the function.
Both the line type and the filling type are set to default values : solid line type with a width of 0, and no filling. It can be changed after with the @code{o_set_line_options()} and @code{o_set_fill_options()}.
The object is added to the end of the list described by the @code{object_list} parameter by the @code{s_basic_link_object()}.
The function returns a new pointer on the new end of the object list.
@format
@anchor{o_line_basic.c - o_line_add()}
@i{<<o_line_basic.c : o_line_add()>>=}@t{
OBJECT *
o_line_add(TOPLEVEL *w_current, OBJECT *object_list,
char type, int color,
int x1, int y1, int x2, int y2)
@{
OBJECT *new_node;
@i{<<o_line_add() : allocate memory for the new line -- @ref{o_line_add() - allocate memory for the new line}>>}
@i{<<o_line_add() : initialize the line -- @ref{o_line_add() - initialize the line}>>}
@i{<<o_line_add() : calculate the screen coords and the bounding box -- @ref{o_line_add() - calculate the screen coords and the bounding box}>>}
@i{<<o_line_add() : add the object to the list -- @ref{o_line_add() - add the object to the list}>>}
return(object_list);
@}
@display
@r{Defines :
@t{o_line_add},
-- @ref{o_line_read() - add the new line to the list of objects},
-- @ref{o_line_copy() - create and insert a new object in the list}.
}
@end display
}
@end format
@format
@anchor{o_line_add() - allocate memory for the new line}
@i{<<o_line_add() : allocate memory for the new line>>=}@t{
/* create the object */
new_node = s_basic_init_object("line");
new_node->type = type;
new_node->color = color;
new_node->line = (LINE *) malloc(sizeof(LINE));
}
@end format
@format
@anchor{o_line_add() - initialize the line}
@i{<<o_line_add() : initialize the line>>=}@t{
/* describe the line with its two ends */
new_node->line->x[0] = x1;
new_node->line->y[0] = y1;
new_node->line->x[1] = x2;
new_node->line->y[1] = y2;
/* line type and filling initialized to default */
o_set_line_options(w_current, new_node,
END_NONE, TYPE_SOLID, 0, -1, -1);
o_set_fill_options(w_current, new_node,
FILLING_HOLLOW, -1, -1, -1, -1, -1);
/* TODO: questionable cast */
new_node->draw_func = (void *) line_draw_func;
/* TODO: questionable cast */
new_node->sel_func = (void *) select_func;
}
@end format
@format
@anchor{o_line_add() - calculate the screen coords and the bounding box}
@i{<<o_line_add() : calculate the screen coords and the bounding box>>=}@t{
/* compute bounding box and screen coords */
o_line_recalc(w_current, new_node);
@display
@r{Uses :
@t{o_line_recalc}, -- @ref{o_line_basic.c - o_line_recalc()}.
}
@end display
}
@end format
@format
@anchor{o_line_add() - add the object to the list}
@i{<<o_line_add() : add the object to the list>>=}@t{
object_list = (OBJECT *) s_basic_link_object(new_node, object_list);
}
@end format
@section Function @code{o_line_copy()}
@defun o_line_copy w_current list_tail o_current
The function @code{o_line_copy()} creates a verbatim copy of the object pointed by @code{o_current} describing a line. The new object is added at the end of the list following the @code{list_tail} pointed object.
@end defun
The function returns a new pointer on the end of the object list.
@format
@anchor{o_line_basic.c - o_line_copy()}
@i{<<o_line_basic.c : o_line_copy()>>=}@t{
OBJECT *
o_line_copy(TOPLEVEL *w_current, OBJECT *list_tail, OBJECT *o_current)
@{
OBJECT *new_obj;
ATTRIB *a_current;
int color;
if (o_current->saved_color == -1) @{
color = o_current->color;
@} else @{
color = o_current->saved_color;
@}
@i{<<o_line_copy() : create and insert a new object in the list -- @ref{o_line_copy() - create and insert a new object in the list}>>}
@i{<<o_line_copy() : modify the fields of the new object -- @ref{o_line_copy() - modify the fields of the new object}>>}
@i{<<o_line_copy() : copy the attributes -- @ref{o_line_copy() - copy the attributes}>>}
/* return the new tail of the object list */
return(new_obj);
@}
@display
@r{Defines :
.
}
@end display
}
@end format
A new line object is added a the end of the object list with @code{o_line_add()}. Values for its fields are default and need to be modified.
@format
@anchor{o_line_copy() - create and insert a new object in the list}
@i{<<o_line_copy() : create and insert a new object in the list>>=}@t{
/* create a new line object */
new_obj = o_line_add(w_current, list_tail,
OBJ_LINE, color,
0, 0, 0, 0);
@display
@r{Uses :
@t{o_line_add}, -- @ref{o_line_basic.c - o_line_add()}.
}
@end display
}
@end format
The coordinates of the ends of the new line are set with the ones of the original line. The two lines have the sale line type and filling options.
The coordinates and the values in screen unit are computed with @code{o_line_recalc()}.
@format
@anchor{o_line_copy() - modify the fields of the new object}
@i{<<o_line_copy() : modify the fields of the new object>>=}@t{
/* modify the line ends of the new line */
new_obj->line->x[0] = o_current->line->x[0];
new_obj->line->y[0] = o_current->line->y[0];
new_obj->line->x[1] = o_current->line->x[1];
new_obj->line->y[1] = o_current->line->y[1];
/* copy the line type and filling options */
o_set_line_options(w_current, new_obj, o_current->line_end,
o_current->line_type, o_current->line_width,
o_current->line_length, o_current->line_space);
o_set_fill_options(w_current, new_obj,
o_current->fill_type, o_current->fill_width,
o_current->fill_pitch1, o_current->fill_angle1,
o_current->fill_pitch2, o_current->fill_angle2);
/* calc the screen coords */
o_line_recalc(w_current, o_current);
@display
@r{Uses :
@t{o_line_recalc}, -- @ref{o_line_basic.c - o_line_recalc()}.
}
@end display
}
@end format
@format
@anchor{o_line_copy() - copy the attributes}
@i{<<o_line_copy() : copy the attributes>>=}@t{
/* new_obj->attribute = 0;*/
a_current = o_current->attribs;
if (a_current) @{
while ( a_current ) @{
/* head attrib node has prev = NULL */
if (a_current->prev != NULL) @{
a_current->copied_to = new_obj;
@}
a_current = a_current->next;
@}
@}
}
@end format
@section Function @code{o_line_modify()}
@defun o_line_modify w_current object x y whichone
This function modifies the coordinates of one of the two ends of the line described by @code{*object}. The new coordinates of this end, identified by @code{whichone}, are given by @code{x} and @code{y} in world unit.
@end defun
The coordinates of the end of line is modified in the world coordinate system. Screen coordinates and boundings are then updated.
@format
@anchor{o_line_basic.c - o_line_modify()}
@i{<<o_line_basic.c : o_line_modify()>>=}@t{
/* pb20011009 - modified */
void
o_line_modify(TOPLEVEL *w_current, OBJECT *object,
int x, int y, int whichone)
@{
/* change one of the end of the line */
switch(whichone) @{
case LINE_END1:
object->line->x[0] = x;
object->line->y[0] = y;
break;
case LINE_END2:
object->line->x[1] = x;
object->line->y[1] = y;
break;
default:
return;
@}
/* recalculate the screen coords and the boundings */
o_line_recalc(w_current, object);
@}
@display
@r{Defines :
.
}
@end display
@display
@r{Uses :
@t{o_line_recalc}, -- @ref{o_line_basic.c - o_line_recalc()}.
}
@end display
}
@end format
@section Function @code{o_line_read()}
@defun o_line_read w_current object_list buf version
The function @code{o_line_read()} gets from the character string @code{*buf} the description of a box. The new box is added to the list of objects of which @code{*object_list} is the last element before the call.
The function returns a pointer on the new last element, that is the added line object.
@end defun
Depending on @code{*version}, the correct file format is considered. Currently two file format revisions are supported :
@itemize @bullet
@item
the file format used until 20010704 release ;
@item
the file format used for the releases after 20010704.
@end itemize
@format
@anchor{o_line_basic.c - o_line_read()}
@i{<<o_line_basic.c : o_line_read()>>=}@t{
OBJECT *
o_line_read(TOPLEVEL *w_current, OBJECT *object_list, char buf[],
unsigned int release_ver, unsigned int fileformat_ver)
@{
char type;
int x1, y1;
int x2, y2;
int d_x1, d_y1;
int d_x2, d_y2;
int line_width, line_space, line_length;
int line_end;
int line_type;
int color;
if(release_ver <= VERSION_20000704) @{
@i{<<o_line_read() : old geda file format -- @ref{o_line_read() - old geda file format}>>}
@} else @{
@i{<<o_line_read() : geda file format after release 20000704 -- @ref{o_line_read() - geda file format after release 20000704}>>}
@}
d_x1 = x1; /* PB : Needed ? */
d_y1 = y1;
d_x2 = x2;
d_y2 = y2;
@i{<<o_line_read() : check the values of the parameters -- @ref{o_line_read() - check the values of the parameters}>>}
@i{<<o_line_read() : add the new line to the list of objects -- @ref{o_line_read() - add the new line to the list of objects}>>}
return(object_list);
@}
@display
@r{Defines :
.
}
@end display
}
@end format
The old geda file format, i.e. releases 20000704 and older, does not handle the line type and the filling - here filling is irrelevant. They are set to default.
@format
@anchor{o_line_read() - old geda file format}
@i{<<o_line_read() : old geda file format>>=}@t{
sscanf(buf, "%c %d %d %d %d %d\n", &type,
&x1, &y1, &x2, &y2, &color);
line_width = 0;
line_end = END_NONE;
line_type = TYPE_SOLID;
line_length= -1;
line_space = -1;
}
@end format
The current line format to describe a line is a space separated list of characters and numbers in plain ASCII on a single line. The meaning of each item is described in the file format documentation.
@format
@anchor{o_line_read() - geda file format after release 20000704}
@i{<<o_line_read() : geda file format after release 20000704>>=}@t{
sscanf(buf, "%c %d %d %d %d %d %d %d %d %d %d\n", &type,
&x1, &y1, &x2, &y2, &color,
&line_width, &line_end, &line_type, &line_length, &line_space);
}
@end format
Null length line are not allowed. If such a line is detected a message is issued.
It also checks is the required color is valid.
@format
@anchor{o_line_read() - check the values of the parameters}
@i{<<o_line_read() : check the values of the parameters>>=}@t{
if (x1 == x2 && y1 == y2) @{
fprintf(stderr, "Found a zero length line [ %c %d %d %d %d %d ]\n",
type, x1, y1, x2, y2, color);
s_log_message("Found a zero length line [ %c %d %d %d %d %d ]\n",
type, x1, y1, x2, y2, color);
@}
if (color < 0 || color > MAX_COLORS) @{
fprintf(stderr, "Found an invalid color [ %s ]\n", buf);
s_log_message("Found an invalid color [ %s ]\n", buf);
s_log_message("Setting color to WHITE\n");
color = WHITE;
@}
}
@end format
A line is internally described by its two ends. A new object is allocated, initialized and added to the list of objects. Its line type is set according to the values of the fields on the line.
@format
@anchor{o_line_read() - add the new line to the list of objects}
@i{<<o_line_read() : add the new line to the list of objects>>=}@t{
/* create and add the line to the list */
object_list = o_line_add(w_current, object_list,
type, color, d_x1, d_y1, d_x2, d_y2);
/* set its line options */
o_set_line_options(w_current, object_list,
line_end, line_type, line_width, line_length,
line_space);
/* filling is irrelevant for line, just set to default */
o_set_fill_options(w_current, object_list,
FILLING_HOLLOW, -1, -1, -1, -1, -1);
@display
@r{Uses :
@t{o_line_add}, -- @ref{o_line_basic.c - o_line_add()}.
}
@end display
}
@end format
@section Function @code{o_line_save()}
@defun o_line_save buf object
The function formats a string in the buffer @code{*buff} to describe the box object @code{*object}.
It follows the post-20000704 release file format that handle the line type and fill options - filling is irrelevant here.
A pointer to the new allocated and formated string is returned. The
string must be freed at some point.
@end defun
@format
@anchor{o_line_basic.c - o_line_save()}
@i{<<o_line_basic.c : o_line_save()>>=}@t{
char *
o_line_save(OBJECT *object)
@{
int x1, x2, y1, y2;
int color;
int line_width, line_space, line_length;
char *buf;
OBJECT_END line_end;
OBJECT_TYPE line_type;
@i{<<o_line_save() : prepare the description of the line -- @ref{o_line_save() - prepare the description of the line}>>}
@i{<<o_line_save() : describe a line with post-20000704 file format -- @ref{o_line_save() - describe a line with post-20000704 file format}>>}
return(buf);
@}
@display
@r{Defines :
.
}
@end display
}
@end format
@format
@anchor{o_line_save() - prepare the description of the line}
@i{<<o_line_save() : prepare the description of the line>>=}@t{
/* get the two ends */
x1 = object->line->x[0];
y1 = object->line->y[0];
x2 = object->line->x[1];
y2 = object->line->y[1];
/* description of the line type */
line_width = object->line_width;
line_end = object->line_end;
line_type = object->line_type;
line_length= object->line_length;
line_space = object->line_space;
/* Use the right color */
if (object->saved_color == -1) @{
color = object->color;
@} else @{
color = object->saved_color;
@}
}
@end format
@format
@anchor{o_line_save() - describe a line with post-20000704 file format}
@i{<<o_line_save() : describe a line with post-20000704 file format>>=}@t{
buf = g_strdup_printf("%c %d %d %d %d %d %d %d %d %d %d", object->type,
x1, y1, x2, y2, color,
line_width, line_end, line_type, line_length, line_space);
}
@end format
@section Function @code{o_line_translate()}
@defun o_line_translate w_current dx dy object
This function applies a translation of (@code{dx},@code{dy}) to the line described by @code{*object}. @code{dx} and @code{dy} are in screen unit.
@end defun
@format
@anchor{o_line_basic.c - o_line_translate()}
@i{<<o_line_basic.c : o_line_translate()>>=}@t{
void
o_line_translate(TOPLEVEL *w_current, int dx, int dy, OBJECT *object)
@{
int x, y;
if (object == NULL) printf("lt NO!\n");
@i{<<o_line_translate() : translate the line -- @ref{o_line_translate() - translate the line}>>}
@i{<<o_line_translate() : update the world coordinates -- @ref{o_line_translate() - update the world coordinates}>>}
@}
@display
@r{Defines :
.
}
@end display
}
@end format
@format
@anchor{o_line_translate() - translate the line}
@i{<<o_line_translate() : translate the line>>=}@t{
/* Do screen coords */
object->line->screen_x[0] = object->line->screen_x[0] + dx;
object->line->screen_y[0] = object->line->screen_y[0] + dy;
object->line->screen_x[1] = object->line->screen_x[1] + dx;
object->line->screen_y[1] = object->line->screen_y[1] + dy;
}
@end format
@format
@anchor{o_line_translate() - update the world coordinates}
@i{<<o_line_translate() : update the world coordinates>>=}@t{
/* do we want snap grid here? hack */
SCREENtoWORLD(w_current,
object->line->screen_x[0], object->line->screen_y[0],
&x, &y);
object->line->x[0] = snap_grid(w_current, x);
object->line->y[0] = snap_grid(w_current, y);
SCREENtoWORLD(w_current,
object->line->screen_x[1], object->line->screen_y[1],
&x, &y);
object->line->x[1] = snap_grid(w_current, x);
object->line->y[1] = snap_grid(w_current, y);
}
@end format
@section Function @code{o_line_translate_world()}
@defun o_line_translate_world w_current x1 y1 object
This function applies a translation of (@code{x1},@code{y1}) to the box described by @code{*object}. @code{x1} and @code{y1} are in world unit.
@end defun
@format
@anchor{o_line_basic.c - o_line_translate_world()}
@i{<<o_line_basic.c : o_line_translate_world()>>=}@t{
void
o_line_translate_world(TOPLEVEL *w_current, int x1, int y1, OBJECT *object)
@{
int screen_x1, screen_y1;
int screen_x2, screen_y2;
int left, right, top, bottom;
if (object == NULL) printf("ltw NO!\n");
@i{<<o_line_translate_world() : translate the box -- @ref{o_line_translate_world() - translate the box}>>}
@i{<<o_line_translate_world() : update the screen coordinates -- @ref{o_line_translate_world() - update the screen coordinates}>>}
@}
@display
@r{Defines :
@t{o_line_translate_world},
-- @ref{o_line_basic.c - o_line_mirror_world()},
-- @ref{o_line_rotate_world() - rotate the line world coords}.
}
@end display
}
@end format
@format
@anchor{o_line_translate_world() - translate the box}
@i{<<o_line_translate_world() : translate the box>>=}@t{
/* Do world coords */
object->line->x[0] = object->line->x[0] + x1;
object->line->y[0] = object->line->y[0] + y1;
object->line->x[1] = object->line->x[1] + x1;
object->line->y[1] = object->line->y[1] + y1;
}
@end format
@format
@anchor{o_line_translate_world() - update the screen coordinates}
@i{<<o_line_translate_world() : update the screen coordinates>>=}@t{
/* update screen coords */
WORLDtoSCREEN(w_current, object->line->x[0],
object->line->y[0],
&screen_x1,
&screen_y1);
object->line->screen_x[0] = screen_x1;
object->line->screen_y[0] = screen_y1;
WORLDtoSCREEN(w_current, object->line->x[1],
object->line->y[1],
&screen_x2,
&screen_y2);
object->line->screen_x[1] = screen_x2;
object->line->screen_y[1] = screen_y2;
/* update bounding box */
get_line_bounds(w_current, object->line, &left, &top, &right, &bottom);
object->left = left;
object->top = top;
object->right = right;
object->bottom = bottom;
@display
@r{Uses :
@t{get_line_bounds}, -- @ref{o_line_basic.c - get_line_bounds()}.
}
@end display
}
@end format
@section Function @code{o_line_rotate()}
@defun o_line_rotate w_current centerx centery angle object
This function applies a rotation of center (@code{centerx},@code{centery}) and angle @code{angle} to the line object @code{*object}.
The coordinates of the rotation center are in screen units.
@code{angle} mst be a 90 degree multiple. If not, no rotation is applied.
@end defun
The rotation is made by the @code{o_line_rotate_world()} function that perform a rotation of angle @code{angle} and center (@code{world_centerx},@code{world_centery}) in world unit.
@format
@anchor{o_line_basic.c - o_line_rotate()}
@i{<<o_line_basic.c : o_line_rotate()>>=}@t{
/* takes in screen coordinates for the centerx,y, and then does the rotate
* in world space */
/* also ignores angle argument... for now, rotate only in 90 degree
* increments */
void
o_line_rotate(TOPLEVEL *w_current, int centerx, int centery, int angle,
OBJECT *object)
@{
int world_centerx, world_centery;
/* convert the center of rotation to world unit */
SCREENtoWORLD(w_current, centerx, centery,
&world_centerx,
&world_centery);
/* rotate the line */
/* the check on the rotation angle is in o_line_rotate_world() */
o_line_rotate_world(w_current,
world_centerx, world_centery, angle,
object);
@}
@display
@r{Defines :
.
}
@end display
@display
@r{Uses :
@t{o_line_rotate_world}, -- @ref{o_line_basic.c - o_line_rotate_world()}.
}
@end display
}
@end format
@section Function @code{o_line_rotate_world()}
@defun o_line_rotate_world w_current world_centerx world_centery angle object
The function @code{o_line_rotate_world()} rotates the box described by @code{*object} around the (@code{world_centerx},@code{world_centery}) point by @code{angle} degrees.
The center of rotation is in world unit.
@end defun
@format
@anchor{o_line_basic.c - o_line_rotate_world()}
@i{<<o_line_basic.c : o_line_rotate_world()>>=}@t{
void
o_line_rotate_world(TOPLEVEL *w_current,
int world_centerx, int world_centery, int angle,
OBJECT *object)
@{
int newx, newy;
if (angle == 0)
return;
@i{<<o_line_rotate_world() : check the rotation angle -- @ref{o_line_rotate_world() - check the rotation angle}>>}
@i{<<o_line_rotate_world() : rotate the line world coords -- @ref{o_line_rotate_world() - rotate the line world coords}>>}
@}
@display
@r{Defines :
@t{o_line_rotate_world},
-- @ref{o_line_basic.c - o_line_rotate()}.
}
@end display
}
@end format
@format
@anchor{o_line_rotate_world() - check the rotation angle}
@i{<<o_line_rotate_world() : check the rotation angle>>=}@t{
/* angle must be positive */
if(angle < 0) angle = -angle;
/* angle must be 90 multiple or no rotation performed */
if((angle % 90) != 0) return;
}
@end format
The center of rotation (@code{world_centerx},@code{world_centery}) is translated to the origin. The rotation of the two ends of the line is performed. FInally, the rotated line is translated back to its previous location.
@format
@anchor{o_line_rotate_world() - rotate the line world coords}
@i{<<o_line_rotate_world() : rotate the line world coords>>=}@t{
/* translate object to origin */
o_line_translate_world(w_current, -world_centerx, -world_centery, object);
/* rotate line end 1 */
rotate_point_90(object->line->x[0], object->line->y[0], angle,
&newx, &newy);
object->line->x[0] = newx;
object->line->y[0] = newy;
/* rotate line end 2 */
rotate_point_90(object->line->x[1], object->line->y[1], angle,
&newx, &newy);
object->line->x[1] = newx;
object->line->y[1] = newy;
/* translate object back to normal position */
o_line_translate_world(w_current, world_centerx, world_centery, object);
@display
@r{Uses :
@t{o_line_translate_world}, -- @ref{o_line_basic.c - o_line_translate_world()}.
}
@end display
}
@end format
@section Function @code{o_line_mirror()}
@defun o_line_mirror w_current centerx centery object
This function mirrors the line from the point (@code{centerx},@code{centery}) in screen unit.
@end defun
The origin of the mirror in screen unit is converted in world unit. The line is mirrored with the function @code{o_line_mirror_world()} for which the origin of the mirror must be given in world unit.
@format
@anchor{o_line_basic.c - o_line_mirror()}
@i{<<o_line_basic.c : o_line_mirror()>>=}@t{
void
o_line_mirror(TOPLEVEL *w_current,
int centerx, int centery,
OBJECT *object)
@{
int world_centerx, world_centery;
/* convert the origin of mirror */
SCREENtoWORLD(w_current, centerx, centery,
&world_centerx,
&world_centery);
/* apply the mirror in world coords */
o_line_mirror_world(w_current,
world_centerx, world_centery,
object);
@}
@display
@r{Defines :
.
}
@end display
@display
@r{Uses :
@t{o_line_mirror_world}, -- @ref{o_line_basic.c - o_line_mirror_world()}.
}
@end display
}
@end format
@section Function @code{o_line_mirror_world()}
@defun o_line_mirror_world w_current world_centerx world_centery object
This function mirrors the line from the point (@code{world_centerx},@code{world_centery}) in world unit.
@end defun
The line if first translated to the origin, then mirrored and finally translated back at its previous position.
@format
@anchor{o_line_basic.c - o_line_mirror_world()}
@i{<<o_line_basic.c : o_line_mirror_world()>>=}@t{
void
o_line_mirror_world(TOPLEVEL *w_current, int world_centerx,
int world_centery, OBJECT *object)
@{
/* translate object to origin */
o_line_translate_world(w_current, -world_centerx, -world_centery, object);
/* mirror the line ends */
object->line->x[0] = -object->line->x[0];
object->line->x[1] = -object->line->x[1];
/* translate back in position */
o_line_translate_world(w_current, world_centerx, world_centery, object);
@}
@display
@r{Defines :
@t{o_line_mirror_world},
-- @ref{o_line_basic.c - o_line_mirror()}.
}
@end display
@display
@r{Uses :
@t{o_line_translate_world}, -- @ref{o_line_basic.c - o_line_translate_world()}.
}
@end display
}
@end format
@section Function @code{o_line_recalc()}
@defun o_line_recalc w_current o_current
This function recalculate the screen coords of the @code{o_current} pointed line object from its world coords.
@end defun
The line ends coordinates and its bounding box are recalculated as well as the OBJECT specific fields (line width, filling ...).
@format
@anchor{o_line_basic.c - o_line_recalc()}
@i{<<o_line_basic.c : o_line_recalc()>>=}@t{
void
o_line_recalc(TOPLEVEL *w_current, OBJECT *o_current)
@{
int screen_x1, screen_y1;
int screen_x2, screen_y2;
int left, right, top, bottom;
if (o_current->line == NULL) @{
return;
@}
@i{<<o_line_recalc() : update the screen coords from world coords -- @ref{o_line_recalc() - update the screen coords from world coords}>>}
@i{<<o_line_recalc() : update the bounding box in screen unit -- @ref{o_line_recalc() - update the bounding box in screen unit}>>}
@i{<<o_line_recalc() : update the object general fields -- @ref{o_line_recalc() - update the object general fields}>>}
@}
@display
@r{Defines :
@t{o_line_recalc},
-- @ref{o_line_basic.c - o_line_scale_world()},
-- @ref{o_line_add() - calculate the screen coords and the bounding box},
-- @ref{o_line_copy() - modify the fields of the new object},
-- @ref{o_line_basic.c - o_line_modify()}.
}
@end display
}
@end format
@format
@anchor{o_line_recalc() - update the screen coords from world coords}
@i{<<o_line_recalc() : update the screen coords from world coords>>=}@t{
/* update the screen coords of end 1 of the line */
WORLDtoSCREEN(w_current,
o_current->line->x[0], o_current->line->y[0],
&screen_x1, &screen_y1);
o_current->line->screen_x[0] = screen_x1;
o_current->line->screen_y[0] = screen_y1;
/* update the screen coords of end 2 of the line */
WORLDtoSCREEN(w_current,
o_current->line->x[1], o_current->line->y[1],
&screen_x2, &screen_y2);
o_current->line->screen_x[1] = screen_x2;
o_current->line->screen_y[1] = screen_y2;
}
@end format
@format
@anchor{o_line_recalc() - update the bounding box in screen unit}
@i{<<o_line_recalc() : update the bounding box in screen unit>>=}@t{
/* update the bounding box - screen unit */
get_line_bounds(w_current, o_current->line,
&left, &top, &right, &bottom);
o_current->left = left;
o_current->top = top;
o_current->right = right;
o_current->bottom = bottom;
@display
@r{Uses :
@t{get_line_bounds}, -- @ref{o_line_basic.c - get_line_bounds()}.
}
@end display
}
@end format
@format
@anchor{o_line_recalc() - update the object general fields}
@i{<<o_line_recalc() : update the object general fields>>=}@t{
/* recalc OBJECT specific parameters */
o_object_recalc(w_current, o_current);
}
@end format
@section Function @code{get_line_bounds()}
@defun get_line_bounds w_current line left top right bottom
The @code{get_box_bounds()} function set the @code{left}, @code{top}, @code{right} and @code{bottom} pointed variables to the boundings of the line object described by @code{*line} in screen unit.
@end defun
@format
@anchor{o_line_basic.c - get_line_bounds()}
@i{<<o_line_basic.c : get_line_bounds()>>=}@t{
void
get_line_bounds(TOPLEVEL *w_current, LINE *line, int *left, int *top,
int *right, int *bottom)
@{
*left = w_current->width;
*top = w_current->height;
*right = 0;
*bottom = 0;
if (line->screen_x[0] < *left) *left = line->screen_x[0];
if (line->screen_x[0] > *right) *right = line->screen_x[0];
if (line->screen_y[0] < *top) *top = line->screen_y[0];
if (line->screen_y[0] > *bottom) *bottom = line->screen_y[0];
if (line->screen_x[1] < *left) *left = line->screen_x[1];
if (line->screen_x[1] > *right) *right = line->screen_x[1];
if (line->screen_y[1] < *top) *top = line->screen_y[1];
if (line->screen_y[1] > *bottom) *bottom = line->screen_y[1];
/* PB : bounding box has to take into account the width of the line */
/* PB : but line width is unknown here */
*left = *left - 4;
*top = *top - 4;
*right = *right + 4;
*bottom = *bottom + 4;
@}
@display
@r{Defines :
@t{get_line_bounds},
-- @ref{o_line_translate_world() - update the screen coordinates},
-- @ref{o_line_recalc() - update the bounding box in screen unit}.
}
@end display
}
@end format
@section Function @code{world_get_line_bounds()}
@defun world_get_line_bounds w_current line left top right bottom
The @code{world_get_line_bounds()} function sets the @code{left}, @code{top}, @code{right} and @code{bottom} pointed variables to the boundings of the line object described in @code{*line} in world unit.
@end defun
@format
@anchor{o_line_basic.c - world_get_line_bounds()}
@i{<<o_line_basic.c : world_get_line_bounds()>>=}@t{
void
world_get_line_bounds(TOPLEVEL *w_current, LINE *line, int *left, int *top,
int *right, int *bottom)
@{
*left = w_current->init_right;
*top = w_current->init_bottom;
*right = 0;
*bottom = 0;
if (line->x[0] < *left) *left = line->x[0];
if (line->x[0] > *right) *right = line->x[0];
if (line->y[0] < *top) *top = line->y[0];
if (line->y[0] > *bottom) *bottom = line->y[0];
if (line->x[1] < *left) *left = line->x[1];
if (line->x[1] > *right) *right = line->x[1];
if (line->y[1] < *top) *top = line->y[1];
if (line->y[1] > *bottom) *bottom = line->y[1];
@}
@display
@r{Defines :
.
}
@end display
}
@end format
@section Function @code{o_line_print()}
@defun o_line_print w_current fp o_current origin_x origin_y
This function writes in a postscript file the line described by the @code{o_current} pointed object.
The postscript resulting file is described by the @code{fp} file pointer.
@end defun
Parameters of the line are extracted from object pointed by @code{o_current}.
@format
@anchor{o_line_basic.c - o_line_print()}
@i{<<o_line_basic.c : o_line_print()>>=}@t{
void
o_line_print(TOPLEVEL *w_current, FILE *fp, OBJECT *o_current,
int origin_x, int origin_y)
@{
int x1, y1, x2, y2;
int color;
int line_width, length, space;
void (*outl_func)() = NULL;
if (o_current == NULL) @{
printf("got null in o_line_print\n");
return;
@}
x1 = o_current->line->x[0];
y1 = o_current->line->y[0];
x2 = o_current->line->x[1];
y2 = o_current->line->y[1];
color = o_current->color;
@i{<<o_line_print() : printing line -- @ref{o_line_print() - printing line}>>}
@}
@display
@r{Defines :
@t{o_line_print},
-- @ref{o_line_basic.c - o_line_image_write()},
-- @ref{o_line_basic.c - o_line_print_old()}.
}
@end display
}
@end format
Depending on the type of the line for this particular line, the appropriate function is chosen among @code{o_line_print_solid()}, @code{o_line_print_dotted()}, @code{o_line_print_dashed()}, @code{o_line_print_center} and @code{o_line_print_phantom()}.
The needed parameters for each of these types are extracted from the @code{o_current} object. Depending on the type, unused parameters are set to -1.
In the eventuality of a length and/or space null, the line is printed solid to avoid and endless loop produced by other functions.
@format
@anchor{o_line_print() - printing line}
@i{<<o_line_print() : printing line>>=}@t{
line_width = o_current->line_width;
length = o_current->line_length;
space = o_current->line_space;
switch(o_current->line_type) @{
case(TYPE_SOLID):
length = -1; space = -1;
outl_func = (void *) o_line_print_solid;
break;
case(TYPE_DOTTED):
length = -1;
outl_func = (void *) o_line_print_dotted;
break;
case(TYPE_DASHED):
outl_func = (void *) o_line_print_dashed;
break;
case(TYPE_CENTER):
outl_func = (void *) o_line_print_center;
break;
case(TYPE_PHANTOM):
outl_func = (void *) o_line_print_phantom;
break;
case(TYPE_ERASE):
/* Unused for now, print it solid */
length = -1; space = -1;
outl_func = (void *) o_line_print_solid;
break;
@}
if((length == 0) || (space == 0)) @{
length = -1; space = -1;
outl_func = (void *) o_line_print_solid;
@}
(*outl_func)(w_current, fp,
x1 - origin_x, y1 - origin_y,
x2 - origin_x, y2 - origin_y,
color,
line_width, length, space,
origin_x, origin_y);
@display
@r{Uses :
@t{o_line_print_center}, -- @ref{o_line_basic.c - o_line_print_center()}.
@t{o_line_print_dashed}, -- @ref{o_line_basic.c - o_line_print_dashed()}.
@t{o_line_print_dotted}, -- @ref{o_line_basic.c - o_line_print_dotted()}.
@t{o_line_print_phantom}, -- @ref{o_line_basic.c - o_line_print_phantom()}.
@t{o_line_print_solid}, -- @ref{o_line_basic.c - o_line_print_solid()}.
}
@end display
}
@end format
@section Function @code{o_line_print_solid()}
@defun o_line_print_solid w_current fp x1 y1 x2 y2 color line_width length space origin_x origin_y
This function prints a line when a solid line type is required. The line is defined by the coordinates of its two ends in (@code{x1},@code{y1}) and (@code{x2},@code{y2}).
The postscript file is defined by the file pointer @code{fp}.
The parameters @code{length} and @code{space} are ignored whereas @code{line_width} specifies the width of the printed line.
@end defun
All dimensions are in mils.
@format
@anchor{o_line_basic.c - o_line_print_solid()}
@i{<<o_line_basic.c : o_line_print_solid()>>=}@t{
void
o_line_print_solid(TOPLEVEL *w_current, FILE *fp,
int x1, int y1, int x2, int y2,
int color,
int line_width, int length, int space,
int origin_x, int origin_y)
@{
fprintf(fp, "gsave\n");
if (w_current->print_color) @{
f_print_set_color(fp, color);
@}
f_print_set_line_width(fp, line_width);
fprintf(fp, "newpath\n");
fprintf(fp, "%d mils %d mils moveto\n", x1, y1);
fprintf(fp, "%d mils %d mils lineto\n", x2, y2);
fprintf(fp, "stroke\n");
fprintf(fp, "grestore\n");
@}
@display
@r{Defines :
@t{o_line_print_solid},
-- @ref{o_line_print() - printing line}.
}
@end display
}
@end format
@section Function @code{o_line_print_dotted()}
@defun o_line_print_dotted w_current fp x1 y1 x2 y2 color line_width length space origin_x origin_y
This function prints a line when a dotted line type is required. The line is defined by the coordinates of its two ends in (@code{x1},@code{y1}) and (@code{x2},@code{y2}).
The postscript file is defined by the file pointer @code{fp}.
The parameter @code{length} is ignored whereas @code{line_width} specifies the diameter of the dots and @code{space} the distance between two dots.
@end defun
A negative value for @code{space} leads to an endless loop.
All dimensions are in mils.
The function sets the color in which the line will be printed with.
@format
@anchor{o_line_basic.c - o_line_print_dotted()}
@i{<<o_line_basic.c : o_line_print_dotted()>>=}@t{
void
o_line_print_dotted(TOPLEVEL *w_current, FILE *fp,
int x1, int y1, int x2, int y2,
int color,
int line_width, int length, int space,
int origin_x, int origin_y)
@{
double dx, dy, l, d;
double dx1, dy1;
double xa, ya;
fprintf(fp, "gsave\n");
if (w_current->print_color) @{
f_print_set_color(fp, color);
@}
/* PB : is the width relevant for a dot (circle) ? */
f_print_set_line_width(fp, line_width);
@display
@r{Defines :
@t{o_line_print_dotted},
-- @ref{o_line_print() - printing line}.
}
@end display
}
@end format
Depending on the slope of the line the space parameter is projected on each of the two directions x and y resulting in @code{dx1} and @code{dy1}. Starting from one end by increments of space the dots are printed.
@format
@anchor{o_line_basic.c - o_line_print_dotted() (2)}
@i{<<o_line_basic.c : o_line_print_dotted()>>+=}@t{
dx = (double) (x2 - x1);
dy = (double) (y2 - y1);
l = sqrt((dx * dx) + (dy * dy));
dx1 = (dx * space) / l;
dy1 = (dy * space) / l;
d = 0;
xa = x1; ya = y1;
while(d < l) @{
@i{<<o_line_print_dotted() : printing a dot -- @ref{o_line_print_dotted() - printing a dot}>>}
d = d + space;
xa = xa + dx1;
ya = ya + dy1;
@}
fprintf(fp, "grestore\n");
@}
}
@end format
A dot is represented by a filled circle. Position of the circle is (@code{xa}, @code{ya}) and its radius is the @code{line_width} parameter.
@format
@anchor{o_line_print_dotted() - printing a dot}
@i{<<o_line_print_dotted() : printing a dot>>=}@t{
fprintf(fp, "newpath\n");
fprintf(fp, "%d mils %d mils\n",
(int) xa, (int) ya);
if(line_width <= 1) @{
fprintf(fp, "2 mils\n");
@} else @{
fprintf(fp, "%d mils\n", line_width/2);
@}
fprintf(fp, "0 360 arc\n");
fprintf(fp, "fill\n");
}
@end format
@section Function @code{o_line_print_dashed()}
@defun o_line_print_dashed w_current fp x1 y1 x2 y2 color line_width length space origin_x origin_y
This function prints a line when a dashed line type is required. The line is defined by the coordinates of its two ends in (@code{x1},@code{y1}) and (@code{x2},@code{y2}).
The postscript file is defined by the file pointer @code{fp}.
@end defun
A negative value for @code{space} or @code{length} leads to an endless loop.
All dimensions are in mils.
The function sets the color in which the line will be printed and the width of the line - that is the width of the dashes.
@format
@anchor{o_line_basic.c - o_line_print_dashed()}
@i{<<o_line_basic.c : o_line_print_dashed()>>=}@t{
void
o_line_print_dashed(TOPLEVEL *w_current, FILE *fp,
int x1, int y1, int x2, int y2,
int color,
int line_width, int length, int space,
int origin_x, int origin_y)
@{
double dx, dy, l, d;
double dx1, dy1, dx2, dy2;
double xa, ya, xb, yb;
fprintf(fp, "gsave\n");
if (w_current->print_color) @{
f_print_set_color(fp, color);
@}
f_print_set_line_width(fp, line_width);
@display
@r{Defines :
@t{o_line_print_dashed},
-- @ref{o_line_print() - printing line}.
}
@end display
}
@end format
Depending on the slope of the line the @code{length} (resp. @code{space}) parameter is projected on each of the two directions x and y resulting in @code{dx1} and @code{dy1} (resp. @code{dx2} and @code{dy2}). Starting from one end and incrementing alternatively by @code{space} and @code{length} the dashes are printed.
It prints as many dashes of length @code{length} as possible.
@format
@anchor{o_line_basic.c - o_line_print_dashed() (2)}
@i{<<o_line_basic.c : o_line_print_dashed()>>+=}@t{
dx = (double) (x2 - x1);
dy = (double) (y2 - y1);
l = sqrt((dx * dx) + (dy * dy));
dx1 = (dx * length) / l;
dy1 = (dy * length) / l;
dx2 = (dx * space) / l;
dy2 = (dy * space) / l;
d = 0;
xa = x1; ya = y1;
while((d + length + space) < l) @{
d = d + length;
xb = xa + dx1;
yb = ya + dy1;
@i{<<o_line_print_dashed() : printing a dash -- @ref{o_line_print_dashed() - printing a dash}>>}
d = d + space;
xa = xb + dx2;
ya = yb + dy2;
@}
}
@end format
When the above condition is no more satisfied, then it is not possible to print a dash of length @code{length}. However it may be possible to print the complete dash or a shorter one.
@format
@anchor{o_line_basic.c - o_line_print_dashed() (3)}
@i{<<o_line_basic.c : o_line_print_dashed()>>+=}@t{
if((d + length) < l) @{
d = d + length;
xb = xa + dx1;
yb = ya + dy1;
@} else @{
xb = x2;
yb = y2;
@}
@i{<<o_line_print_dashed() : printing a dash -- @ref{o_line_print_dashed() - printing a dash}>>}
fprintf(fp, "grestore\n");
@}
}
@end format
@format
@anchor{o_line_print_dashed() - printing a dash}
@i{<<o_line_print_dashed() : printing a dash>>=}@t{
fprintf(fp, "newpath\n");
fprintf(fp, "%d mils %d mils moveto\n", (int) xa, (int) ya);
fprintf(fp, "%d mils %d mils lineto\n", (int) xb, (int) yb);
fprintf(fp, "stroke\n");
}
@end format
@section Function @code{o_line_print_center()}
@defun o_line_print_center w_current fp x1 y1 x2 y2 color line_width length space origin_x origin_y
This function prints a line when a centered line type is required. The line is defined by the coordinates of its two ends in (@code{x1},@code{y1}) and (@code{x2},@code{y2}).
The postscript file is defined by the file pointer @code{fp}.
@end defun
A negative value for @code{space} or @code{length} leads to an endless loop.
All dimensions are in mils.
The function sets the color in which the line will be printed and the width of the line - that is the width of the dashes and the diameter of the dots.
@format
@anchor{o_line_basic.c - o_line_print_center()}
@i{<<o_line_basic.c : o_line_print_center()>>=}@t{
void
o_line_print_center(TOPLEVEL *w_current, FILE *fp,
int x1, int y1, int x2, int y2,
int color,
int line_width, int length, int space,
int origin_x, int origin_y)
@{
double dx, dy, l, d;
double dx1, dy1, dx2, dy2;
double xa, ya, xb, yb;
fprintf(fp, "gsave\n");
if (w_current->print_color) @{
f_print_set_color(fp, color);
@}
f_print_set_line_width(fp, line_width);
@display
@r{Defines :
@t{o_line_print_center},
-- @ref{o_line_print() - printing line}.
}
@end display
}
@end format
Depending on the slope of the line the @code{length} (resp. @code{space}) parameter is projected on each of the two directions x and y resulting in @code{dx1} and @code{dy1} (resp. @code{dx2} and @code{dy2}). Starting from one end and incrementing alternatively by @code{space} and @code{length} the dashes and dots are printed.
It prints as many sets of dash and dot as possible.
@format
@anchor{o_line_basic.c - o_line_print_center() (2)}
@i{<<o_line_basic.c : o_line_print_center()>>+=}@t{
dx = (double) (x2 - x1);
dy = (double) (y2 - y1);
l = sqrt((dx * dx) + (dy * dy));
dx1 = (dx * length) / l;
dy1 = (dy * length) / l;
dx2 = (dx * space) / l;
dy2 = (dy * space) / l;
d = 0;
xa = x1; ya = y1;
while((d + length + 2 * space) < l) @{
d = d + length;
xb = xa + dx1;
yb = ya + dy1;
@i{<<o_line_print_center() : printing a dash -- @ref{o_line_print_center() - printing a dash}>>}
d = d + space;
xa = xb + dx2;
ya = yb + dy2;
@i{<<o_line_print_center() : printing a dot -- @ref{o_line_print_center() - printing a dot}>>}
d = d + space;
xa = xa + dx2;
ya = ya + dy2;
@}
}
@end format
When the above condition is no more satisfied, then it is not possible to print a dash of length @code{length}. However two cases are possible :
@itemize @bullet
@item
it is possible to print the dash and the dot ;
@item
it is possible to print the dash or a part of the original dash ;
@end itemize
@format
@anchor{o_line_basic.c - o_line_print_center() (3)}
@i{<<o_line_basic.c : o_line_print_center()>>+=}@t{
if((d + length + space) < l) @{
d = d + length;
xb = xa + dx1;
yb = ya + dy1;
@i{<<o_line_print_center() : printing a dash -- @ref{o_line_print_center() - printing a dash}>>}
d = d + space;
xa = xb + dx2;
ya = yb + dy2;
@i{<<o_line_print_center() : printing a dot -- @ref{o_line_print_center() - printing a dot}>>}
@} else @{
if(d + length < l) @{
xb = xa + dx1;
yb = ya + dy1;
@} else @{
xb = x2;
yb = y2;
@}
@i{<<o_line_print_center() : printing a dash -- @ref{o_line_print_center() - printing a dash}>>}
@}
fprintf(fp, "grestore\n");
@}
}
@end format
@format
@anchor{o_line_print_center() - printing a dash}
@i{<<o_line_print_center() : printing a dash>>=}@t{
fprintf(fp, "newpath\n");
fprintf(fp, "%d mils %d mils moveto\n", (int) xa, (int) ya);
fprintf(fp, "%d mils %d mils lineto\n", (int) xb, (int) yb);
fprintf(fp, "stroke\n");
}
@end format
A dot is represented by a filled circle. Position of the circle is (@code{xa}, @code{ya}) and its radius by the @code{line_width} parameter.
@format
@anchor{o_line_print_center() - printing a dot}
@i{<<o_line_print_center() : printing a dot>>=}@t{
fprintf(fp, "newpath\n");
fprintf(fp, "%d mils %d mils\n", (int) xa, (int) ya);
if(line_width <= 1) @{
fprintf(fp, "2 mils\n");
@} else @{
fprintf(fp, "%d mils\n", line_width/2);
@}
fprintf(fp, "0 360 arc\n");
fprintf(fp, "fill\n");
}
@end format
@section Function @code{o_line_print_phantom()}
@defun o_line_print_phantom w_current fp x1 y1 x2 y2 color line_width length space origin_x origin_y
This function prints a line when a phantom line type is required. The line is defined by the coordinates of its two ends in (@code{x1},@code{y1}) and (@code{x2},@code{y2}).
The postscript file is defined by the file pointer @code{fp}.
@end defun
A negative value for @code{space} or @code{length} leads to an endless loop.
All dimensions are in mils.
The function sets the color in which the line will be printed and the width of the line - that is the width of the dashes and the diameter of the dots.
@format
@anchor{o_line_basic.c - o_line_print_phantom()}
@i{<<o_line_basic.c : o_line_print_phantom()>>=}@t{
void
o_line_print_phantom(TOPLEVEL *w_current, FILE *fp,
int x1, int y1, int x2, int y2,
int color,
int line_width, int length, int space,
int origin_x, int origin_y)
@{
double dx, dy, l, d;
double dx1, dy1, dx2, dy2;
double xa, ya, xb, yb;
fprintf(fp, "gsave\n");
if (w_current->print_color) @{
f_print_set_color(fp, color);
@}
f_print_set_line_width(fp, line_width);
@display
@r{Defines :
@t{o_line_print_phantom},
-- @ref{o_line_print() - printing line}.
}
@end display
}
@end format
Depending on the slope of the line the @code{length} (resp. @code{space}) parameter is projected on each of the two directions x and y resulting in @code{dx1} and @code{dy1} (resp. @code{dx2} and @code{dy2}). Starting from one end and incrementing alternatively by @code{space} and @code{length} the dashes and dots are printed.
It prints as many sets of dash-dot-dot as possible.
@format
@anchor{o_line_basic.c - o_line_print_phantom() (2)}
@i{<<o_line_basic.c : o_line_print_phantom()>>+=}@t{
dx = (double) (x2 - x1);
dy = (double) (y2 - y1);
l = sqrt((dx * dx) + (dy * dy));
dx1 = (dx * length) / l;
dy1 = (dy * length) / l;
dx2 = (dx * space) / l;
dy2 = (dy * space) / l;
d = 0;
xa = x1; ya = y1;
while((d + length + 3 * space) < l) @{
d = d + length;
xb = xa + dx1;
yb = ya + dy1;
@i{<<o_line_print_phantom() : printing a dash -- @ref{o_line_print_phantom() - printing a dash}>>}
d = d + space;
xa = xb + dx2;
ya = yb + dy2;
@i{<<o_line_print_phantom() : printing a dot -- @ref{o_line_print_phantom() - printing a dot}>>}
d = d + space;
xa = xa + dx2;
ya = ya + dy2;
@i{<<o_line_print_phantom() : printing a dot -- @ref{o_line_print_phantom() - printing a dot}>>}
d = d + space;
xa = xa + dx2;
ya = ya + dy2;
@}
}
@end format
When the above condition is no more satisfied, then it is not possible to print a complete set of dash-dot-dot. However three cases are possible :
@itemize @bullet
@item
it is possible to print a dash and a dot and a dot ;
@item
it is possible to print a dash and a dot ;
@item
it is possible to print the dash or a part of the original dash ;
@end itemize
@format
@anchor{o_line_basic.c - o_line_print_phantom() (3)}
@i{<<o_line_basic.c : o_line_print_phantom()>>+=}@t{
if((d + length + 2 * space) < l) @{
d = d + length;
xb = xa + dx1;
yb = ya + dy1;
@i{<<o_line_print_phantom() : printing a dash -- @ref{o_line_print_phantom() - printing a dash}>>}
d = d + space;
xa = xb + dx2;
ya = yb + dy2;
@i{<<o_line_print_phantom() : printing a dot -- @ref{o_line_print_phantom() - printing a dot}>>}
d = d + space;
xa = xb + dx2;
ya = yb + dy2;
@i{<<o_line_print_phantom() : printing a dot -- @ref{o_line_print_phantom() - printing a dot}>>}
@} else @{
if(d + length + space < l) @{
d = d + length;
xb = xa + dx1;
yb = ya + dy1;
@i{<<o_line_print_phantom() : printing a dash -- @ref{o_line_print_phantom() - printing a dash}>>}
d = d + space;
xa = xb + dx2;
ya = yb + dy2;
@i{<<o_line_print_phantom() : printing a dot -- @ref{o_line_print_phantom() - printing a dot}>>}
@} else @{
if(d + length < l) @{
xb = xa + dx1;
yb = ya + dy1;
@} else @{
xb = x2;
yb = y2;
@}
@i{<<o_line_print_phantom() : printing a dash -- @ref{o_line_print_phantom() - printing a dash}>>}
@}
@}
fprintf(fp, "grestore\n");
@}
}
@end format
@format
@anchor{o_line_print_phantom() - printing a dash}
@i{<<o_line_print_phantom() : printing a dash>>=}@t{
fprintf(fp, "newpath\n");
fprintf(fp, "%d mils %d mils moveto\n", (int) xa, (int) ya);
fprintf(fp, "%d mils %d mils lineto\n", (int) xb, (int) yb);
fprintf(fp, "stroke\n");
}
@end format
A dot is represented by a filled circle. Position of the circle is (@code{xa}, @code{ya}) and its radius by the @code{line_width} parameter.
@format
@anchor{o_line_print_phantom() - printing a dot}
@i{<<o_line_print_phantom() : printing a dot>>=}@t{
fprintf(fp, "newpath\n");
fprintf(fp, "%d mils %d mils\n", (int) xa, (int) ya);
if(line_width <= 1) @{
fprintf(fp, "2 mils\n");
@} else @{
fprintf(fp, "%d mils\n", line_width/2);
@}
fprintf(fp, "0 360 arc\n");
fprintf(fp, "fill\n");
}
@end format
@section Function @code{o_line_print_old()}
@defun o_line_print_old w_current fp o_current origin_x origin_y
This function is the old function to print a line. It does not handle line type.
@end defun
@format
@anchor{o_line_basic.c - o_line_print_old()}
@i{<<o_line_basic.c : o_line_print_old()>>=}@t{
void
o_line_print_old(TOPLEVEL *w_current, FILE *fp, OBJECT *o_current,
int origin_x, int origin_y)
@{
if (o_current == NULL) @{
printf("got null in o_line_print\n");
return;
@}
if (w_current->print_color) @{
f_print_set_color(fp, o_current->color);
@}
fprintf(fp, "newpath\n");
fprintf(fp, "%d mils %d mils moveto\n",
o_current->line_points->x1-origin_x,
o_current->line_points->y1-origin_y);
fprintf(fp, "%d mils %d mils lineto\n",
o_current->line_points->x2-origin_x,
o_current->line_points->y2-origin_y);
fprintf(fp, "stroke\n");
@}
@display
@r{Defines :
.
}
@end display
@display
@r{Uses :
@t{o_line_print}, -- @ref{o_line_basic.c - o_line_print()}.
}
@end display
}
@end format
@section Function @code{o_line_image_write()}
@defun o_line_image_write w_current o_current origin_x origin_y color_mode
This function draws a line in an image with the libgdgeda function @code{gdImageLine()}.
@end defun
@format
@anchor{o_line_basic.c - o_line_image_write()}
@i{<<o_line_basic.c : o_line_image_write()>>=}@t{
void
o_line_image_write(TOPLEVEL *w_current, OBJECT *o_current,
int origin_x, int origin_y, int color_mode)
@{
int color;
if (o_current == NULL) @{
printf("got null in o_line_print\n");
return;
@}
if (color_mode == TRUE) @{
color = o_image_geda2gd_color(o_current->color);
@} else @{
color = image_black;
@}
/* assumes screen coords are already calculated correctly */
#ifdef HAS_LIBGDGEDA
gdImageSetThickness(current_im_ptr, SCREENabs(w_current,
o_current->line_width));
gdImageLine(current_im_ptr,
o_current->line->screen_x[0],
o_current->line->screen_y[0],
o_current->line->screen_x[1],
o_current->line->screen_y[1],
color);
#endif
@}
@display
@r{Defines :
.
}
@end display
@display
@r{Uses :
@t{o_line_print}, -- @ref{o_line_basic.c - o_line_print()}.
}
@end display
}
@end format
@section Function @code{o_line_scale_world()}
@defun o_line_scale_world w_current x_scale y_scale object
@end defun
@format
@anchor{o_line_basic.c - o_line_scale_world()}
@i{<<o_line_basic.c : o_line_scale_world()>>=}@t{
void
o_line_scale_world(TOPLEVEL *w_current, int x_scale, int y_scale, OBJECT *object)
@{
if (object == NULL) printf("lsw NO!\n");
/* scale the line world coords */
object->line->x[0] = object->line->x[0] * x_scale;
object->line->y[0] = object->line->y[0] * y_scale;
object->line->x[1] = object->line->x[1] * x_scale;
object->line->y[1] = object->line->y[1] * y_scale;
/* update screen coords */
o_line_recalc(w_current, object);
@}
@display
@r{Defines :
.
}
@end display
@display
@r{Uses :
@t{o_line_recalc}, -- @ref{o_line_basic.c - o_line_recalc()}.
}
@end display
}
@end format
@section Function @code{o_line_visible()}
@defun o_line_visible w_current line x1 y1 x2 y2
@end defun
@format
@anchor{o_line_basic.c - o_line_visible()}
@i{<<o_line_basic.c : o_line_visible()>>=}@t{
int
o_line_visible(TOPLEVEL *w_current, LINE *line,
int *x1, int *y1, int *x2, int *y2)
@{
int visible=0;
/* don't do clipping if this is false */
if (!w_current->object_clipping) @{
return(TRUE);
@}
*x1 = line->screen_x[0];
*y1 = line->screen_y[0];
*x2 = line->screen_x[1];
*y2 = line->screen_y[1];
visible = SCREENclip_change(w_current, x1, y1, x2, y2);
return(visible);
@}
@display
@r{Defines :
.
}
@end display
}
@end format
@section Function @code{o_line_length()}
@defun o_line_length object
@end defun
@format
@anchor{o_line_basic.c - o_line_length()}
@i{<<o_line_basic.c : o_line_length()>>=}@t{
double
o_line_length(OBJECT *object)
@{
double length;
double dx, dy;
if (!object->line) @{
return 0.0;
@}
dx = object->line->x[0]-object->line->x[1];
dy = object->line->y[0]-object->line->y[1];
length = sqrt((dx*dx) + (dy*dy));
return(length);
@}
@display
@r{Defines :
.
}
@end display
}
@end format
|