pgf-tikz / pgf-tikz/pgf

[intersection] `\pgfintersectionofpaths` yields an error when the lines are almost parallel

Open
#369 10 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

intersections
Dominant language
TeX
Stars
1.3k
Forks
118
Avg merge
4d 3h
Merged PRs (30d)
5

Description

Migrated from SourceForge
Author: avani42
Timestamp: 2015-10-22 18:47:05.333000

\pgfintersectionofpaths yields an error when the lines it is trying to intersect are almost parallel. This bug was discovered by users of package forest and attributed to PGF, see TeX.SE question http://tex.stackexchange.com/questions/204094/sn-edges-and-nice-empty-nodes-styles-in-forest-lead-to-dividing-by-zero-whats.

This is an example of code that produces the error.

\pgfintersectionofpaths{%
  \pgfpathmoveto{\pgfpoint{0.0pt}{-3.53297pt}}
  \pgfpathlineto{\pgfpoint{19.54204pt}{-31.44316pt}}%
}{%
  \pgfpathmoveto{\pgfpoint{34.6372pt}{-53.00208pt}}%
  \pgfpathlineto{\pgfpoint{19.54204pt}{-31.44316pt}}}

The error produced is

! Package PGF Math Error: You asked me to calculate 1/0.0', but I cannot divide any number by zero.

The "call stack" is (\pgfintersectionofpaths, \pgfpointintersectionoflines, \pgftransforminvert): so the error occurs during \pgftransforminvert, just as the documentation of this macro claims would happen if the matrix its trying to invert is near-singular.

Prior to calling \pgfpointintersectionoflines to actually compute the intesection of lines, \pgf@intersectionoflines (indirectly called by \pgfintersectionofpaths) tries to figure out whether the lines intersect at all, and the problem seems to be in this part of the code, namely macro \pgf@iflinesintersect, which apparently reports the lines to intersect, although computing the intersection later yields an error.

The expected behaviour would be for \pgfpointintersectionoflines and \pgfiflinesintersect to be consistent.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the provided \pgfintersectionofpaths example and trace the call stack through \pgfpointintersectionoflines, \pgf@iflinesintersect, and \pgftransforminvert. Compare the near-parallel decision with the later intersection calculation. Done means the example no longer triggers division by zero and \pgfpointintersectionoflines and \pgfiflinesintersect report consistent results.

Written by the indexing model from the issue text.

Assessment

Tech stack
tex
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.