MCPcopy Create free account
hub / github.com/SimHacker/micropolis / VertLineToArc

Function VertLineToArc

micropolis-activity/src/tk/tkcvarc.c:1439–1480  ·  view source on GitHub ↗
(x, y1, y2, rx, ry, start, extent)

Source from the content-addressed store, hash-verified

1437 * a given arc.
1438 *
1439 * Results:
1440 * The return value is 1 if the given line intersects the
1441 * infinitely-thin arc section defined by rx, ry, start,
1442 * and extent, and 0 otherwise. Only the perimeter of the
1443 * arc is checked: interior areas (e.g. pie-slice or chord)
1444 * are not checked.
1445 *
1446 * Side effects:
1447 * None.
1448 *
1449 *--------------------------------------------------------------
1450 */
1451
1452static int
1453VertLineToArc(x, y1, y2, rx, ry, start, extent)
1454 double x; /* X-coordinate of line segment. */
1455 double y1, y2; /* Y-coords of endpoints of line segment.
1456 * Y1 must be <= y2. */
1457 double rx, ry; /* These x- and y-radii define an oval
1458 * centered at the origin. */
1459 double start, extent; /* Angles that define extent of arc, in
1460 * the standard fashion for this module. */
1461{
1462 double tmp;
1463 double tx, ty; /* Coordinates of intersection point in
1464 * transformed coordinate system. */
1465 double y;
1466
1467 /*
1468 * Compute the y-coordinate of one possible intersection point
1469 * between the arc and the line. Use a transformed coordinate
1470 * system where the oval is a unit circle centered at the origin.
1471 * Then scale back to get actual y-coordinate.
1472 */
1473
1474 tx = x/rx;
1475 tmp = 1 - tx*tx;
1476 if (tmp < 0) {
1477 return 0;
1478 }
1479 ty = sqrt(tmp);
1480 y = ty*ry;
1481
1482 /*
1483 * Test both intersection points.

Callers 1

ArcToAreaFunction · 0.85

Calls 1

AngleInRangeFunction · 0.85

Tested by

no test coverage detected