Repository navigation
[6020] 规范底层定长整数并将排版几何坐标升级为 64 位整型避免超长文档溢出 - #4715
Merged
Merged
Conversation
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述
在超长篇文档(例如数万段落、上万页的长篇专著/文档)中,排版几何坐标自上而下顺序累加,整书累计纵向坐标可达数十亿 SI 单位,突破了 32 位有符号整型$2^{31}-1 \approx 2.147 \times 10^9$ (通常在近万页规模时发生溢出变为负数)。
SI(int)的最大值由此引发以下缺陷:
is_visible产生逻辑反转,将处于当前视口中的页面误判为不可见,导致视口呈现空白;Ctrl+PageDown(traverse-next结构化向下漫游)或跨章节长距离移动光标时,目标坐标与前沿位置判定异常,导致光标定位陷入死循环或假死停顿。解决方案
1. 规范
lolly基础类型体系lolly/Kernel/Abstractions/minmax.hpp中引入<cstdint>:SI(Single Integer)与SN严格规范为 32 位整型(int32_t/uint32_t);DI(Double Integer)与DN规范为 64 位整型(int64_t/uint64_t),替换原有的long long int;min/max引入 C++ 模板实现,支持混合整型比较(std::common_type),彻底消除 32 位与 64 位整型混用时的重载歧义。2. 排版几何坐标与视口系统升级为 64 位整数(
DI)将排版与几何系统中的绝对坐标、边界尺寸与视口参数统一升级为 64 位整型
DI:moebius/Kernel/Types/rectangles.hpp中的rectangle_rep(x1, y1, x2, y2)、coord2、coord4、space等;src/Typeset/boxes.hpp中box_rep的偏移量与包围盒(x0..y4、w()、h()、sx、sy、position_at、stack_box、composite_box、scatter_box等);src/Graphics/Renderer/renderer.hpp的原点与裁剪区(ox, oy, cx1..cy2、is_visible、clipping、put_shadow等);edit_interface_rep(scroll_to,vx1..vy2)、edit_cursor_rep(tree_path,cursor_move);pager_rep(cur_top累计、scatter_box页面阵列定位)。3. Scheme 胶水层 64 位无损交互
array_di绑定,避免将 64 位排版坐标截断为 32 位int丢失精度。测试与验证
xmake test "lolly_tests/*":34/34 单元测试 100% 通过;xmake test "moebius_tests/*":18/18 单元测试 100% 通过。Ctrl+PageDown结构化向下移动,光标与视口全程平滑推进,无任何停顿或卡死现象。