如何命名一个既代表大小又代表位置的结构体?

发布于 2024-07-20 00:26:56 字数 398 浏览 4 评论 0原文

我有一个名为 WaveSize 的结构来表示样本量或时间量,但我也使用此结构来表示波内的位置或偏移量。

虽然用 Vector2d 类型表示坐标系中的大小和位置很常见,但我无法找到一个足够抽象的好名称来表示波长和波位置/偏移。

我发现看到这样的东西很奇怪:

public WaveSize Size { get; }
public WaveSize Offset { get; }

我宁愿想出一个好名字,也不愿创建空类或使用“using”。

任何建议将不胜感激。 提前致谢。

编辑:作为里德·科普西和 Marc Gravel 认为拥有两个不同的类很有意义,因为它们是两个不同的概念,因此,代码中的任何相似之处都应被视为纯粹的巧合。

I have a structure named WaveSize to represent both an amount of samples or an amount of time, but I'm also using this structure to represent a position or an offset within a wave.

While it's pretty common to represent both sizes and positions within a coordinate system with a Vector2d type, I'm unable to find a good name abstract enough to represent wave lengths and wave positions/offsets.

I find odd to see something like:

public WaveSize Size { get; }
public WaveSize Offset { get; }

I'd rather come up with a good name than creating empty classes or using 'using'.

Any suggestions will be much appreciated. Thanks in advance.

EDIT: As Reed Copsey & Marc Gravel suggested it makes a lot of sense to have two different classes since they are two different concepts, so, any similarities in code should be seen as mere coincidences.

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

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

发布评论

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

评论(5

殤城〤 2024-07-27 00:26:57

“偏移”的通常名称不是相移吗?

我可能会选择 WaveProperties,真的。

Isn't the usual name for the 'offset' the phase shift?

I'd probably go with WaveProperties, really.

雨的味道风的声音 2024-07-27 00:26:56

我将有两个独立的结构,并使它们之间的转换变得容易。

您试图在这里表示两个概念,一个是位置,另一个是大小。 由于这是两个概念上不同的想法,因此我将它们设为两个结构。

我也同意 Marc Gravell 关于 BCL 的 Point/Size 结构的回答。 我认为他们是一个值得效仿的好榜样。

I would have two separate structs, and make conversions easy between them.

You're trying to represent two concepts here, one for position, and one for size. Since these are two conceptually distinct ideas, I'd make them two structs.

I also agree with Marc Gravell's answer regarding the BCL's Point/Size structs. I think they're a good model to follow.

绮筵 2024-07-27 00:26:56

你能有一个简单地称为 Wave 的结构,然后大小和偏移量可以很好地适应更通用的名称吗? 我希望你还没有 Wave 结构:)

Could you have a struct called simply Wave and then size and offset would fit snugly into the more general name? I hope you dont have a Wave struct already :)

不美如何 2024-07-27 00:26:56

波矢?

WaveVector?

旧情勿念 2024-07-27 00:26:56

您可以与 winforms PointSize 结构进行比较...他们决定即使它们相似,也要将它们分开。 这在代数意义上是有意义的:

Point - Point = Size
Point + Size = Point
Size + Size = Size
Point + Piont = ???? error (no defined operator)

等等

You could compare to the winforms Point and Size structures... they decided that even if they are similar, to keep them separate. It makes sense at the algebraic sense:

Point - Point = Size
Point + Size = Point
Size + Size = Size
Point + Piont = ???? error (no defined operator)

etc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文