Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch line-clipping algorithm #495

Merged
merged 2 commits into from
Oct 16, 2017
Merged

Switch line-clipping algorithm #495

merged 2 commits into from
Oct 16, 2017

Conversation

jbcrail
Copy link
Contributor

@jbcrail jbcrail commented Oct 16, 2017

I switched from Cohen-Sutherland to Liang-Barsky. The performance gains for random lines range from 50-75% improvement for a million lines.

Related to #456

I switched from Cohen-Sutherland to Liang-Barsky. The performance gains
for random lines range from 50-75% improvement for a million lines.

Related to #456
@jbcrail
Copy link
Contributor Author

jbcrail commented Oct 16, 2017

To compare the original (Cohen-Sutherland) and new (Liang-Barsky) algorithms, I generated a random set of lines with variations in how many lines are outside the clipping window:

sample lower-left : (0, 0)
sample upper-right: (10000, 10000)
window lower-left : (0, 0)
window upper-right: (10000, 10000)
iterations : 1000
# points   : 1000000
  cohen-sutherland:  9.2482s
  liang-barsky    :  2.2957s (75.18% faster)

sample lower-left : (-100000, -100000)
sample upper-right: (110000, 110000)
window lower-left : (0, 0)
window upper-right: (10000, 10000)
iterations : 1000
# points   : 1000000
  cohen-sutherland: 29.6957s
  liang-barsky    : 13.4035s (54.86% faster)

sample lower-left : (0, 0)
sample upper-right: (110000, 110000)
window lower-left : (0, 0)
window upper-right: (10000, 10000)
iterations : 1000
# points   : 1000000
  cohen-sutherland: 39.7649s
  liang-barsky    : 15.4240s (61.21% faster)

sample lower-left : (-100000, -100000)
sample upper-right: (10000, 10000)
window lower-left : (0, 0)
window upper-right: (10000, 10000)
iterations : 1000
# points   : 1000000
  cohen-sutherland: 48.8722s
  liang-barsky    : 18.0797s (63.01% faster)

Since the clipping algorithm is always run prior to drawing a line, the performance gains should dominate the overall performance of line().

@jbednar
Copy link
Member

jbednar commented Oct 16, 2017

Thanks!

@jbednar jbednar merged commit edf1096 into master Oct 16, 2017
@jbednar jbednar deleted the line-clipping branch October 16, 2017 12:35
jbednar pushed a commit that referenced this pull request Oct 30, 2017
Switched from Cohen-Sutherland to Liang-Barsky. The performance gains
for random lines range from 50-75% improvement for a million lines. Related to #456.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants