Re: Help with perpendicular snap
Posted by
fernandohildebrand on
Feb 17, 2012; 8:18pm
URL: https://forum.librecad.org/Help-with-perpendicular-snap-tp5493585p5493849.html
Ive cloned the source. dont know how to do a pull request on github....
2012/2/17 dxli [via LibreCAD]
<[hidden email]>
Hi,
Please generate a patch (against master branch) or, send a pull request to my repo:
github.com/dxli/LibreCAD
Thanks,
Dongxu
On Fri, Feb 17, 2012 at 2:09 PM, fernandohildebrand [via LibreCAD]
<[hidden email]> wrote:
Hi al...
Need some help with the code here. heres what i got so far:
rs_entitycontainer.cpp ->
RS_Vector RS_EntityContainer::getNearestPerpendicular(const RS_Vector& coord
){
RS_Vector closestPoint(false); // closest found endpoint
RS_VectorSolutions sol;
RS_Entity* closestEntity;
closestEntity = getNearestEntity(coord, NULL, RS2::ResolveAll);
if (closestEntity!=NULL) {
for (RS_Entity* en = firstEntity(RS2::ResolveAll);
en != NULL;
en = nextEntity(RS2::ResolveAll)) {
if (
!en->isVisible()
|| en == closestEntity
|| en->rtti() == RS2::EntityPoint /**Point*/
|| en->getParent()->rtti() == RS2::EntityInsert /**Insert*/
|| en->getParent()->rtti() == RS2::EntityText /**< Text 15*/
|| en->getParent()->rtti() == RS2::EntityDimAligned /**< Aligned Dimension */
|| en->getParent()->rtti() == RS2::EntityDimLinear /**< Linear Dimension */
|| en->getParent()->rtti() == RS2::EntityDimRadial /**< Radial Dimension */
|| en->getParent()->rtti() == RS2::EntityDimDiametric /**< Diametric Dimension */
|| en->getParent()->rtti() == RS2::EntityDimAngular /**< Angular Dimension */
|| en->getParent()->rtti() == RS2::EntityDimLeader /**< Leader Dimension */
){//do not do intersection for point for Spline, Insert, text, Dim
continue;
}
sol = RS_Information::getPerpendicular(closestEntity,
en);
closestPoint = sol.getClosest(coord);
}
}
return closestPoint;
}
rs_information.cpp->
RS_VectorSolutions RS_Information::getPerpendicular(RS_Entity* e1,RS_Entity* e2){
RS_VectorSolutions ret;
RS_VectorSolutions t1;
RS_VectorSolutions t2;
if (e1==NULL || e2==NULL ) {
RS_DEBUG->print("RS_Information::getPerpendicular() for NULL entities");
return ret;
}
if (e1->getId() == e2->getId()) {
RS_DEBUG->print("RS_Information::getPerpendicular() of the same entity");
return ret;
}
// unsupported entities / entity combinations:
if (
e1->rtti()==RS2::EntityText || e2->rtti()==RS2::EntityText ||
isDimension(e1->rtti()) || isDimension(e2->rtti())) {
return ret;
}
// arc,circle,elipse/arc,circle,elipse
if(
(e1->rtti()==RS2::EntityArc || e1->rtti()==RS2::EntityCircle
|| e1->rtti()==RS2::EntityEllipse) &&
(e2->rtti()==RS2::EntityArc || e2->rtti()==RS2::EntityCircle
|| e2->rtti()==RS2::EntityEllipse)) {
t1 = e1->getTangentPoint();
t2 = e2->getTangentPoint();
if(t1.dotP(t2)==0){
ret = container->getNearestPointOnEntity(e1);
return ret;
}
}
// line/arc,circle,elipse , arc,circle,elipse/line
if(e1->rtti()==RS2::EntityArc || e1->rtti()==RS2::EntityCircle
|| e1->rtti()==RS2::EntityEllipse){
t1 = e1->getTangentPoint(e1->getNearestPointOnEntity(e2));
if(t2.dotP(t1)==0){
ret = container->getNearestPointOnEntity(e1);
return ret;
}
}
else if(e2->rtti()==RS2::EntityArc || e2->rtti()==RS2::EntityCircle
|| e2->rtti()==RS2::EntityEllipse){
t2 = e2->getTangentPoint(e2->getNearestPointOnEntity(e1));
if(t1.dotP(t2)==0){
ret = container->getNearestPointOnEntity(e1);
return ret;
}
}
//line/line
t1 = e1;
t2 = e2;
if(t1.dotP(t2)==0){
ret = container->getNearestPointOnEntity(e1);
return ret;
}
return ret;
}
See, my main problem is getting the tangent lines/vector/points from the entities on information so I can do a DotProduct, I still dont get vetor_solutions...
Help please?
--
Fernando da Motta Hildebrand
--
Dongxu Li, Ph.D.
www.librecad.org
--
Fernando da Motta Hildebrand