本文整理汇总了C++中DPoint类的典型用法代码示例。如果您正苦于以下问题:C++ DPoint类的具体用法?C++ DPoint怎么用?C++ DPoint使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DPoint类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: computeRepulsiveForce
DPoint SpringEmbedderGridVariant::ForceModelBase::
computeRepulsiveForce(int j, double boxLength, int idealExponent, int normExponent) const
{
const NodeInfo &vj = m_vInfo[j];
int grid_x = vj.m_gridX;
int grid_y = vj.m_gridY;
// repulsive forces on node j: F_rep(d) = iel^2 / d^normExponent
DPoint force(0, 0);
for (int gi = -1; gi <= 1; ++gi) {
for (int gj = -1; gj <= 1; ++gj) {
for (int u : m_gridCell(grid_x + gi, grid_y + gj)) {
if (u == j) {
continue;
}
DPoint dist = vj.m_pos - m_vInfo[u].m_pos;
double d = dist.norm();
if(d < boxLength) {
dist /= std::pow(d, normExponent+1) + eps();
force += dist;
}
}
}
}
force *= std::pow(m_idealEdgeLength, idealExponent);
return force;
}
示例2: computeMixedForcesDisplacement
DPoint SpringEmbedderGridVariant::ForceModelBase::
computeMixedForcesDisplacement(int j, int boxLength,
std::function<DPoint(double, const DPoint &)> attractiveChange,
std::function<double()> attractiveFinal) const
{
DPoint disp(computeRepulsiveForce(j, boxLength, 2));
const NodeInfo &vj = m_vInfo[j];
DPoint forceAttr(0, 0);
DPoint forceRep(0, 0); // subtract rep. force on adjacent vertices
for (int i = vj.m_adjBegin; i != vj.m_adjStop; ++i) {
int u = m_adjLists[i];
DPoint dist = vj.m_pos - m_vInfo[u].m_pos;
double d = dist.norm();
forceAttr -= attractiveChange(d, dist);
if (d < boxLength) {
double f = 1.0 / (d * d + eps());
forceRep += f * dist;
}
}
forceAttr *= attractiveFinal();
forceRep *= m_idealEdgeLength * m_idealEdgeLength;
disp += forceAttr - forceRep;
return disp;
}
示例3: isScrollWindowNotOutSide
bool CAScrollView::isScrollWindowNotOutSide()
{
DPoint point = m_pContainer->getFrameOrigin();
this->getScrollWindowNotOutPoint(point);
return !point.equals(m_pContainer->getFrameOrigin());
}
示例4: len
double LayoutStatistics::edgeLengths(
const GraphAttributes &ga,
double *pMinLength,
double *pMaxLength,
double *pAvgLength,
double *pStdDeviation,
bool considerSelfLoops)
{
const Graph &G = ga.constGraph();
int m = G.numberOfEdges();
double totalLength = 0, minLength = numeric_limits<double>::max(), maxLength = -numeric_limits<double>::max();
EdgeArray<double> len(G);
int nSelfLoops = 0;
for(edge e : G.edges) {
if(!considerSelfLoops && e->isSelfLoop()) {
nSelfLoops++;
continue;
}
const DPolyline &dpl = ga.bends(e);
if(!dpl.empty()) {
len[e] = dpl.length();
} else {
DPoint pv = DPoint(ga.x(e->source()),ga.y(e->source()));
DPoint pw = DPoint(ga.x(e->target()),ga.y(e->target()));
len[e] = pv.distance(pw);
}
totalLength += len[e];
minLength = min(minLength, len[e]);
maxLength = max(maxLength, len[e]);
}
m -= nSelfLoops;
double avgEdgeLength = totalLength / m;
if(pAvgLength) *pAvgLength = avgEdgeLength;
if(pMinLength) *pMinLength = minLength;
if(pMaxLength) *pMaxLength = maxLength;
if(pStdDeviation) {
double sum = 0;
for(edge e : G.edges) {
if(!considerSelfLoops && e->isSelfLoop())
continue;
double d = len[e] - avgEdgeLength;
sum += d*d;
}
*pStdDeviation = sqrt(sum / m);
}
return totalLength;
}
示例5: eps
DPoint SpringEmbedderGridVariant::ForceModelGronemann::computeDisplacement(int j, double boxLength) const
{
const double cEps = eps();
const double cIELEps = m_idealEdgeLength + cEps;
const NodeInfo &vj = m_vInfo[j];
int grid_x = vj.m_gridX;
int grid_y = vj.m_gridY;
// repulsive forces on node j: F_rep(d) = iel^2 / d
DPoint force(0,0);
for(int gi = -1; gi <= 1; gi++) {
for(int gj = -1; gj <= 1; gj++) {
for(int u : m_gridCell(grid_x+gi,grid_y+gj)) {
if(u == j) continue;
DPoint dist = vj.m_pos - m_vInfo[u].m_pos;
double d = dist.norm();
if(d < boxLength) {
dist /= d * d + cEps;
force += dist;
}
}
}
}
force *= m_idealEdgeLength * m_idealEdgeLength;
DPoint disp(force);
// attractive forces on j: F_attr(d) = c / deg(v) * ln(d/iel)
const double c = 0.5;
DPoint forceRepSub(0,0); // subtract rep. force on adjacent vertices
force = DPoint(0,0);
for(int l = vj.m_adjBegin; l != vj.m_adjStop; ++l) {
int u = m_adjLists[l];
DPoint dist = vj.m_pos - m_vInfo[u].m_pos;
double d = dist.norm();
force -= log((d+cEps) / cIELEps) * dist;
if(d < boxLength) {
double f = 1.0 / (d * d + cEps);
forceRepSub += f * dist;
}
}
force *= c * (vj.m_adjStop-vj.m_adjBegin);
forceRepSub *= m_idealEdgeLength * m_idealEdgeLength;
disp += force - forceRepSub;
return disp;
}
示例6: setAnchorPoint
void CAView::setAnchorPoint(const DPoint& point)
{
if( ! point.equals(m_obAnchorPoint))
{
DPoint p;
if (m_bFrame)
{
p = this->getFrameOrigin();
}
else
{
p = this->getCenterOrigin();
}
m_obAnchorPoint = point;
m_obAnchorPointInPoints = ccp(m_obContentSize.width * m_obAnchorPoint.x,
m_obContentSize.height * m_obAnchorPoint.y );
if (m_bFrame)
{
this->setFrameOrigin(p);
}
else
{
this->setCenterOrigin(p);
}
this->updateDraw();
}
}
示例7: DPoint
void CAView::setAnchorPointInPoints(const DPoint& anchorPointInPoints)
{
if( ! anchorPointInPoints.equals(m_obAnchorPointInPoints))
{
DPoint p;
if (m_bFrame)
{
p = this->getFrameOrigin();
}
else
{
p = this->getCenterOrigin();
}
m_obAnchorPointInPoints = anchorPointInPoints;
m_obAnchorPoint = DPoint(m_obAnchorPointInPoints.x / m_obContentSize.width,
m_obAnchorPointInPoints.y / m_obContentSize.height);
if (m_bFrame)
{
this->setFrameOrigin(p);
}
else
{
this->setCenterOrigin(p);
}
this->updateDraw();
}
}
示例8: normalize
float DPoint::getAngle(const DPoint& other) const
{
DPoint a2 = normalize();
DPoint b2 = other.normalize();
float angle = atan2f(a2.cross(b2), a2.dot(b2));
if( fabs(angle) < 0.01f ) return 0.f;
return angle;
}
示例9: getSet
// Function to get the initial set
Set getSet(int PointType, bool Repetitions){
Set imgPoints = Set();
DPoint *p;
vector<float> position = vector<float>();
CImg<float> imgAux = img;
// Create the new pointer for the diferents points
switch(PointType){
case 0:
p = new DPoint();
break;
case 1:
case 2:
case 3:
imgAux.RGBtoLab();
p = new CIELABPoint();
break;
case 7:
case 8:
p = new RGBAPoint();
break;
}
// Load the image in the pointers
for(int i = 0; i < imgAux.height(); i++){
for(int j = 0; j < imgAux.width(); j++){
position.push_back(imgAux(j, i, 0, 0));
position.push_back(imgAux(j, i, 0, 1));
position.push_back(imgAux(j, i, 0, 2));
p->setPosition(position);
imgPoints.addPoint(p);
position.erase(position.begin(), position.end());
switch(PointType){
case 0:
p = new DPoint();
break;
case 1:
case 2:
case 3:
p = new CIELABPoint();
break;
case 7:
case 8:
p = new RGBAPoint();
break;
}
}
}
// If we don't need to remove repeated points we return the set
if(Repetitions){
return imgPoints;
}
// We take out the repeated points and return the set
else{
vector<DPoint*> aux = imgPoints.getPoints();
list<DPoint*> removequals = list<DPoint*>(aux.begin(), aux.end());
removequals.sort(compareDPoint);
removequals.unique(sameDPoint);
vector<DPoint*> vecaux = vector<DPoint*>(removequals.begin(), removequals.end());
Set setAux = Set();
for(int i = 0; i < vecaux.size(); i++){
setAux.addPoint(vecaux[i]);
}
return setAux;
}
}
示例10: MIN
void CAScrollView::deaccelerateScrolling(float dt)
{
dt = MIN(dt, 1/30.0f);
dt = MAX(dt, 1/100.0f);
if (m_tInertia.getLength() > maxSpeedCache(dt))
{
m_tInertia = ccpMult(m_tInertia, maxSpeedCache(dt) / m_tInertia.getLength());
}
DPoint speed = DPointZero;
if (m_tInertia.getLength() > maxSpeed(dt))
{
speed = ccpMult(m_tInertia, maxSpeed(dt) / m_tInertia.getLength());
}
else
{
speed = m_tInertia;
}
DPoint point = m_pContainer->getFrameOrigin();
if (m_bBounces)
{
DPoint resilience = DPointZero;
DSize size = this->getBounds().size;
DPoint curr_point = m_pContainer->getFrameOrigin();
DPoint relust_point = curr_point;
this->getScrollWindowNotOutPoint(relust_point);
float off_x = relust_point.x - curr_point.x;
float off_y = relust_point.y - curr_point.y;
if (fabsf(off_x) > FLT_EPSILON)
{
resilience.x = off_x / size.width;
}
if (fabsf(off_y) > FLT_EPSILON)
{
resilience.y = off_y / size.height;
}
resilience = ccpMult(resilience, maxSpeed(dt));
if (speed.getLength() < resilience.getLength())
{
speed = resilience;
m_tInertia = DPointZero;
}
}
if (speed.getLength() < 0.25f)
{
m_tInertia = DPointZero;
this->getScrollWindowNotOutPoint(point);
this->setContainerFrame(point);
this->update(0);
this->hideIndicator();
this->stopDeaccelerateScroll();
if (m_pScrollViewDelegate)
{
m_pScrollViewDelegate->scrollViewStopMoved(this);
}
}
else
{
point = ccpAdd(point, speed);
if (this->isScrollWindowNotMaxOutSide(point))
{
m_tInertia = DPointZero;
}
if (m_bBounces == false)
{
this->getScrollWindowNotOutPoint(point);
}
else
{
if (m_bBounceHorizontal == false)
{
point.x = this->getScrollWindowNotOutHorizontal(point.x);
}
if (m_bBounceVertical == false)
{
point.y = this->getScrollWindowNotOutVertical(point.y);
}
}
if (point.equals(m_pContainer->getFrameOrigin()))
{
m_tInertia = DPointZero;
}
else
{
this->showIndicator();
this->setContainerFrame(point);
//.........这里部分代码省略.........
示例11: CC_RETURN_IF
void CAScrollView::ccTouchMoved(CATouch *pTouch, CAEvent *pEvent)
{
CC_RETURN_IF(m_bPCMode);
CC_RETURN_IF(m_vTouches.contains(pTouch) == false);
DPoint p_container = m_pContainer->getFrameOrigin();
DPoint p_off = DPointZero;
if (m_vTouches.size() == 1)
{
p_off = ccpSub(this->convertToNodeSpace(pTouch->getLocation()),
this->convertToNodeSpace(pTouch->getPreviousLocation()));
DPoint off = p_off;
if (off.getLength() <= 5)
{
off = DPointZero;
}
m_tPointOffset.push_back(off);
}
else if (m_vTouches.size() == 2)
{
CATouch* touch0 = dynamic_cast<CATouch*>(m_vTouches.at(0));
CATouch* touch1 = dynamic_cast<CATouch*>(m_vTouches.at(1));
DPoint mid_point = ccpMidpoint(this->convertToNodeSpace(touch0->getLocation()),
this->convertToNodeSpace(touch1->getLocation()));
p_off = ccpSub(mid_point, ccpAdd(p_container, m_pContainer->getAnchorPointInPoints() * m_fZoomScale));
if (m_fMinimumZoomScale < m_fMaximumZoomScale)
{
float touch_lenght = ccpDistance(this->convertToNodeSpace(touch0->getLocation()) ,
this->convertToNodeSpace(touch1->getLocation()));
float scale_off = (touch_lenght - m_fTouchLength) * 0.0020f;
m_fZoomScale = m_pContainer->getScale();
m_fZoomScale += m_fZoomScale * scale_off;
m_fZoomScale = MIN(m_fZoomScale, m_fMaximumZoomScale);
m_fZoomScale = MAX(m_fZoomScale, m_fMinimumZoomScale);
m_pContainer->setScale(m_fZoomScale);
m_fTouchLength = touch_lenght;
}
}
if (m_bBounces)
{
DSize size = this->getBounds().size;
DPoint curr_point = m_pContainer->getFrameOrigin();
DPoint relust_point = curr_point;
this->getScrollWindowNotOutPoint(relust_point);
float lenght_x = fabsf(curr_point.x - relust_point.x);
float lenght_y = fabsf(curr_point.y - relust_point.y);
DPoint scale = DPoint(1.0f, 1.0f);
if (!(lenght_x < FLT_EPSILON))
{
scale.x = (0.5f - MIN(lenght_x / size.width, 0.5f));
p_off.x *= scale.x;
}
if (!(lenght_y < FLT_EPSILON))
{
scale.y = (0.5f - MIN(lenght_y / size.height, 0.5f));
p_off.y *= scale.y;
}
}
p_container = ccpAdd(p_container, p_off);
if (m_bBounces == false)
{
this->getScrollWindowNotOutPoint(p_container);
}
else
{
if (m_bBounceHorizontal == false)
{
p_container.x = this->getScrollWindowNotOutHorizontal(p_container.x);
}
if (m_bBounceVertical == false)
{
p_container.y = this->getScrollWindowNotOutVertical(p_container.y);
}
}
if (p_container.equals(m_pContainer->getFrameOrigin()) == false)
{
if (m_bTouchEnabledAtSubviews)
{
m_pContainer->setTouchEnabled(false);
}
this->setContainerFrame(p_container);
this->showIndicator();
if (m_bTracking == false)
{
//.........这里部分代码省略.........
示例12: cosf
CATransformation CAView::nodeToParentTransform(void)
{
if (m_bTransformDirty)
{
// Translate values
float height = 0;
if (this->getSuperview())
{
height= this->getSuperview()->getBounds().size.height;
}
else
{
height= CAApplication::getApplication()->getWinSize().height;
}
float x = m_obPoint.x;
float y = height - m_obPoint.y;
// Rotation values
// Change rotation code to handle X and Y
// If we skew with the exact same value for both x and y then we're simply just rotating
float cx = 1, sx = 0, cy = 1, sy = 0;
if (m_fRotationX || m_fRotationY)
{
float radiansX = -CC_DEGREES_TO_RADIANS(m_fRotationX);
float radiansY = -CC_DEGREES_TO_RADIANS(m_fRotationY);
cx = cosf(radiansX);
sx = sinf(radiansX);
cy = cosf(radiansY);
sy = sinf(radiansY);
}
bool needsSkewMatrix = ( m_fSkewX || m_fSkewY );
// optimization:
// inline anchor point calculation if skew is not needed
// Adjusted transform calculation for rotational skew
DPoint anchorPointInPoints = DPoint(m_obAnchorPointInPoints.x,
m_obContentSize.height - m_obAnchorPointInPoints.y);
if (! needsSkewMatrix && !anchorPointInPoints.equals(DPointZero))
{
x += cy * -anchorPointInPoints.x * m_fScaleX + -sx * -anchorPointInPoints.y * m_fScaleY;
y += sy * -anchorPointInPoints.x * m_fScaleX + cx * -anchorPointInPoints.y * m_fScaleY;
}
// Build Transform Matrix
// Adjusted transform calculation for rotational skew
m_sTransform = CATransformationMake(cy * m_fScaleX,
sy * m_fScaleX,
-sx * m_fScaleY,
cx * m_fScaleY,
x,
y );
// XXX: Try to inline skew
// If skew is needed, apply skew and then anchor point
if (needsSkewMatrix)
{
CATransformation skewMatrix = CATransformationMake(1.0f,
tanf(CC_DEGREES_TO_RADIANS(m_fSkewY)),
tanf(CC_DEGREES_TO_RADIANS(m_fSkewX)),
1.0f,
0.0f,
0.0f );
m_sTransform = CATransformationConcat(skewMatrix, m_sTransform);
// adjust anchor point
DPoint anchorPointInPoints = DPoint(m_obAnchorPointInPoints.x,
m_obContentSize.height - m_obAnchorPointInPoints.y);
if (!anchorPointInPoints.equals(DPointZero))
{
m_sTransform = CATransformationTranslate(m_sTransform,
-anchorPointInPoints.x,
-anchorPointInPoints.y);
}
}
m_bTransformDirty = false;
}
return m_sTransform;
}
示例13: pathClearList
void SetG1(double xpos, double ypos, double zpos)
{
double xstart, ystart,zstart;
_lastPoint.Get(xstart, ystart,zstart);
pathClearList *clearList = new pathClearList(g_path, xstart, ystart,zstart);
_millctrl.SetCommand(clearList);
pathAddLine *addLine = new pathAddLine(g_path, xpos, ypos, zpos);
_millctrl.SetCommand(addLine);
stageExecutePath *executePath = new stageExecutePath(g_stage, g_path);
_lastPoint.Set(xpos, ypos, zpos);
}
示例14: stageMoveXYZ
void SetG0(double xpos, double ypos, double zpos)
{
double x=0.0, y=0.0, z=0.0;
stageMoveXYZ *stagemoveXYZ = new stageMoveXYZ(g_stage, x+xpos, y+ypos,z+zpos);
_millctrl.SetCommand(stagemoveXYZ);
_lastPoint.Set(x+xpos, y+ypos, z+zpos);
}