如何在边界框内绘制线条时考虑线宽

发布于 2024-09-30 09:00:30 字数 660 浏览 0 评论 0原文

我正在整个边界框内绘制一组均匀间隔的水平线。

我遇到的问题是线条(当大于 1px 时)绘制超出了我的边界的顶部和底部边缘。准确地说,顶部和底部各边各有一半缺失。

这是一些尝试修复此问题的伪代码,但没有成功。它应该描述我想要做的事情:

var halfline = linewidth / 2.;
var maxheight = boxsize.height - halfline;
var minheight = halfline;

//draw h lines    
for(i = 0; i < maxlines; i++)
{
    var xloc = 0;
    var xfrac = i / maxlines - 1;
    var yloc = (xfrac * boxsize.height) + minheight;

    move_to(xloc, yloc);
    line_to(boxsize.width, yloc);
}

请记住,语言在这里并不重要,只是如何正确偏移和缩放线条(在 for 循环内绘制)的想法。

感谢您的任何提示...可以安全地假设以下内容:

  1. 线宽以像素为单位

  2. 坐标系基于像素,从(0,0)开始到 (n,n)

I am drawing a set of evenly spaced horizontal lines within the entirety of a bounding box.

The problem I am having is that the lines (when larger than 1px) get drawn beyond the top and bottom edges of my bounds. Half on each side of the top and bottom is missing, to be precise.

Here is some pseudo code that attempts a fix for this, but it didn't work. It should describe what I am trying to do:

var halfline = linewidth / 2.;
var maxheight = boxsize.height - halfline;
var minheight = halfline;

//draw h lines    
for(i = 0; i < maxlines; i++)
{
    var xloc = 0;
    var xfrac = i / maxlines - 1;
    var yloc = (xfrac * boxsize.height) + minheight;

    move_to(xloc, yloc);
    line_to(boxsize.width, yloc);
}

Please keep in mind that the lang is not important here, just the idea of how to offset and scale the lines (that are drawn within the for loop) properly.

Thanks for any tips... It's safe to assume the following:

  1. the line width is in pixels

  2. the coordinate system is pixel-based, from (0,0) to (n,n)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独留℉清风醉 2024-10-07 09:00:30

你的问题有点不清楚,但我认为这可能会有所帮助:

var availablespace = boxsize.height - linewidth;
...
var yloc = (xfrac * availablespace) + minheight;

Your question is a little unclear, but I think this might help:

var availablespace = boxsize.height - linewidth;
...
var yloc = (xfrac * availablespace) + minheight;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文