MCPcopy Create free account
hub / github.com/Kitware/VTK / getIntersectionParameter

Function getIntersectionParameter

Rendering/FreeType/vtkFreeTypeTools.cxx:1573–1615  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1571namespace RasterScanQuad
1572{
1573VTK_ABI_NAMESPACE_BEGIN
1574
1575// Return true and set t1 (if 0 <= t1 <= 1) for the intersection of lines:
1576//
1577// P1(t1) = p1 + t1 * v1 and
1578// P2(t2) = p2 + t2 * v2.
1579//
1580// This method is specialized for the case of P2(t2) always being a horizontal
1581// line (v2 = {1, 0}) with p1 defined as {0, y}.
1582//
1583// If the lines do not intersect or t1 is outside of the specified range, return
1584// false.
1585inline bool getIntersectionParameter(const vtkVector2i& p1, const vtkVector2i& v1, int y, float& t1)
1586{
1587 // First check if the input vector is parallel to the scan line, returning
1588 // false if it is:
1589 if (v1[1] == 0)
1590 {
1591 return false;
1592 }
1593
1594 // Given the lines:
1595 // P1(t1) = p1 + t1 * v1 (The polygon edge)
1596 // P2(t2) = p2 + t2 * v2 (The horizontal scan line)
1597 //
1598 // And defining the vector:
1599 // w = p1 - p2
1600 //
1601 // The value of t1 at the intersection of P1 and P2 is:
1602 // t1 = (v2[1] * w[0] - v2[0] * w[1]) / (v2[0] * v1[1] - v2[1] * v1[0])
1603 //
1604 // We know that p2 = {0, y} and v2 = {1, 0}, since we're scanning along the
1605 // x axis, so the above becomes:
1606 // t1 = (-w[1]) / (v1[1])
1607 //
1608 // Expanding the definition of w, w[1] --> (p1[1] - p2[1]) --> p1[1] - y,
1609 // resulting in the final:
1610 // t1 = -(p1[1] - y) / v1[1], or
1611 // t1 = (y - p1[1]) / v1[1]
1612
1613 t1 = (y - p1[1]) / static_cast<float>(v1[1]);
1614 return t1 >= 0.f && t1 <= 1.f;
1615}
1616
1617// Evaluate the line equation P(t) = p + t * v at the supplied t, and return
1618// the x value of the resulting point.

Callers 1

findScanRangeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected