当前位置:网站首页>【项目实训】线形组件的细节
【项目实训】线形组件的细节
2022-06-23 05:59:00 【从冬】
组件大致可以分为矩形类组件和线形组件,矩形组件最典型的就是普通矩形,它的变化形式较为规范,变换过程中外部轮廓始终是矩形。线形的变化则相对灵活,线形组件的绘制由转折点构成,按照特定的顺序连接。
线形组件面临着一些细节问题
1.线形组件关键点的增加和减少。
2.如何正确维护线形组件关键点的顺序。
对于第一个问题,采用动态数组去维护线形组件的关键点顺序。
当移动透明关键点时,改关键点会变为非透明点,而且该点分别与其相邻的节点的中点会产生新的节点,产生新节点后,要将其插入改关键点的前后相邻位置。
关键代码
//透明关键点
*now += createPoint(dx, dy);
now->setVirtual(0);
auto nextP = pointList[realId + 1];
auto preP = pointList[realId - 1];
double n,nextN,preN;
if(nextP->getId() == "end"){
nextN = 1;
}
else{
nextN = stod(nextP->getId());
}
if(preP->getId() == "start"){
preN = 0;
}
else{
preN = stod(preP->getId());
}
n = std::stod(now->getId());
std::string name1 = std::to_string((n + preN)/2.0);
//"mid" + std::to_string(ndSize++);
std::string name2 = std::to_string((n+nextN)/2.0);
//"mid" + std::to_string(ndSize++);
auto m1 = createCorePoint(name1, (now->getX() + preP->getX()) / 2,
(now->getY() + preP->getY()) / 2);
auto m2 = createCorePoint(name2, (now->getX() + nextP->getX()) / 2,
(now->getY() + nextP->getY()) / 2);
m1->setVirtual(1);
m2->setVirtual(1);
setCorePoints({m1, m2});
pointList.insert(pointList.begin() + realId + 1, m2);
pointList.insert(pointList.begin() + realId, m1);对于第二个问题,主要是在save与load的时候会碰到,由于线的关键点变化并没有规律,每个关键点的id对于区分顺序便显得尤为重要。
最终采取的方式是将起点和终点的id分别设为“0”和“1”,中间点设为“0.5”,当“0”与“0.5”之间产生新的关键点时,新关键点id是“0.25”。
关键点的id公式为:(pre.id+next.id)/2
由此,点的id越小,其位置越靠前,便可以通过id区分关键点的顺序
边栏推荐
- JSON to proto
- asp.net文件下载demo与相关问题的处理
- Open source ecology 𞓜 super practical open source license basic knowledge literacy post (Part 2)
- 【STL】pair用法总结
- core.js是什么---kalrry
- MySQL optimization
- Centos7 MySQL records
- 2121. 相同元素的间隔之和-哈希表法
- Haas506 2.0 development tutorial - Advanced Component Library -modem Net (only supports versions above 2.2)
- XML schema record
猜你喜欢

How to realize video call and live interaction in a small program when live broadcasting is so popular?

直播带货这么火,如何在小程序中实现视频通话及直播互动功能?

Understand how learning JSX works

English语法_形容词比较级 - 3级变化

QT method of compiling projects using multithreading

XML schema record

xml schem 记录

994. rotten oranges - non recursive method

【STL】关联容器之map用法总结

XXL-SSO 实现SSO单点登录
随机推荐
Open source to the world (Part 2): the power of open source from the evolution of database technology BDTC 2021
system 权限程序不能访问sd卡问题
【STL】pair用法总结
746. 使用最小花费爬楼梯-动态规划
Qt 中 QVariant 使用总结
20220620 uniformly completely observable (UCO)
关于监督
Cetos7 record
SAP execution transaction code mrrl error -no message was found for partner 100065-
MySQL5.6 (5.7-8) 基于shardingsphere5.1.1 Sharding-Proxy模式读写分离
Measurement principle and thickness measurement mode of spectral confocal
haas506 2.0开发教程-高级组件库-modem.sim(仅支持2.2以上版本)
cmder
关于五险一金你需要知道的事情
总结的好处
Influence of steam education on domestic college students
30 data visualization tips that can not be ignored
Common setup modes (Abstract Factory & responsibility chain mode & observer mode)
【Qt】基础学习笔记
MySQL index