const QRectF KarbonCalligraphicShape::lastPieceBoundingRect() { if (pointCount() < 6) return QRectF(); int index = pointCount() / 2; QPointF p1 = pointByIndex(KoPathPointIndex(0, index - 3))->point(); QPointF p2 = pointByIndex(KoPathPointIndex(0, index - 2))->point(); QPointF p3 = pointByIndex(KoPathPointIndex(0, index - 1))->point(); QPointF p4 = pointByIndex(KoPathPointIndex(0, index))->point(); QPointF p5 = pointByIndex(KoPathPointIndex(0, index + 1))->point(); QPointF p6 = pointByIndex(KoPathPointIndex(0, index + 2))->point(); // TODO: also take the control points into account QPainterPath p; p.moveTo(p1); p.lineTo(p2); p.lineTo(p3); p.lineTo(p4); p.lineTo(p5); p.lineTo(p6); return p.boundingRect().translated(position()); }
void OpenSteer::PolylineSegmentedPath::movePoints( size_type startIndex, size_type numOfPoints, Vec3 const newPoints[] ) { assert( ( startIndex < ( pointCount() - ( isCyclic() ? 1 : 0 ) ) ) && "startIndex must be inside index range." ); assert( ( ( startIndex + numOfPoints ) <= ( pointCount() - ( isCyclic() ? 1 : 0 ) ) ) && "The max. index of a point to set must be inside the index range." ); // Update the point positions. // @todo Remove this line size_type const pathPointCount = pointCount(); for ( size_type i = 0; i < numOfPoints; ++i ) { points_[ startIndex + i ] = newPoints[ i ]; } // If the first point is changed and the path is cyclic also change the // last point, which is just a copy of the first point. if ( isCyclic() && ( 0 == startIndex ) ) { points_.back() = points_.front(); } // Recalculate the tangents and lengths. updateTangentsAndLengths( points_, segmentTangents_, segmentLengths_, startIndex, numOfPoints, isCyclic() ); assert( adjacentPathPointsDifferent( points_.begin(), points_.end(), isCyclic() ) && "Adjacent path points must be different." ); }
void animate(int i) { GLfloat x, y; pointNode * last; if(!bPaused && !bComplete) { GLfloat displacement = calcDisplacement(minX, maxX, minY, maxY); last = curr; randomDisplacement(displacement, x, y); curr = AddNode(curr, curr->x + x, curr->y + y); count = pointCount(head); glutPostRedisplay(); //We only want to keep going if if(checkNode(curr, minX, maxX, minY, maxY)) { //keep a roughly constat fps glutTimerFunc(17, animate, 0); }else { findExitPoint(last, curr); bComplete = true; } } }
GLfloat* copyToArray(struct pointNode * head) { GLfloat * retVal; pointNode * tmp; count = pointCount(head); int i = 0; count *= 2; tmp = head; if(count > 0 ) { //retVal = (GLfloat *)malloc(sizeof(GLfloat) * count); retVal = new GLfloat[count]; } else { return NULL; } while(i < count) { retVal[i] = tmp->x; retVal[i+1] = tmp->y; tmp = tmp->next; i+=2; } return retVal; }
void KarbonCalligraphicShape::smoothPoint(const int index) { if (pointCount() < index + 2) { kDebug(38000) << "index to high"; return; } else if (index < 1) { kDebug(38000) << "index to low"; return; } const KoPathPointIndex PREV(0, index - 1); const KoPathPointIndex INDEX(0, index); const KoPathPointIndex NEXT(0, index + 1); QPointF prev = pointByIndex(PREV)->point(); QPointF point = pointByIndex(INDEX)->point(); QPointF next = pointByIndex(NEXT)->point(); QPointF vector = next - prev; qreal dist = (QLineF(prev, next)).length(); // normalize the vector (make it's size equal to 1) if (! qFuzzyCompare(dist + 1, 1)) vector /= dist; qreal mult = 0.35; // found by trial and error, might not be perfect... // distance of the control points from the point qreal dist1 = (QLineF(point, prev)).length() * mult; qreal dist2 = (QLineF(point, next)).length() * mult; QPointF vector1 = vector * dist1; QPointF vector2 = vector * dist2; QPointF controlPoint1 = point - vector1; QPointF controlPoint2 = point + vector2; pointByIndex(INDEX)->setControlPoint1(controlPoint1); pointByIndex(INDEX)->setControlPoint2(controlPoint2); }
OpenSteer::Vec3 OpenSteer::PolylineSegmentedPath::segmentStart( size_type segmentIndex ) const { assert( segmentIndex < segmentCount() && "segmentIndex out of range." ); assert( segmentIndex < pointCount() && "The max. index of a point must be inside range." ); return points_[ segmentIndex ]; }
void PlyWriter::ready(PointTableRef table) { if (pointCount() > std::numeric_limits<uint32_t>::max()) throwError("Can't write PLY file. Only " + std::to_string(std::numeric_limits<uint32_t>::max()) + " points supported."); m_stream = Utils::createFile(m_filename, true); writeHeader(table.layout()); }
void KarbonCalligraphicShape::appendPointsToPathAux(const QPointF &p1, const QPointF &p2) { KoPathPoint *pathPoint1 = new KoPathPoint(this, p1); KoPathPoint *pathPoint2 = new KoPathPoint(this, p2); // calculate the index of the insertion position int index = pointCount() / 2; insertPoint(pathPoint2, KoPathPointIndex(0, index)); insertPoint(pathPoint1, KoPathPointIndex(0, index)); }
bool KarbonCalligraphicShape::flipDetected(const QPointF &p1, const QPointF &p2) { // detect the flip caused by the angle changing 180 degrees // thus detect the boundary crossing int index = pointCount() / 2; QPointF last1 = pointByIndex(KoPathPointIndex(0, index - 1))->point(); QPointF last2 = pointByIndex(KoPathPointIndex(0, index))->point(); int sum1 = std::abs(ccw(p1, p2, last1) + ccw(p1, last2, last1)); int sum2 = std::abs(ccw(p2, p1, last2) + ccw(p2, last1, last2)); // if there was a flip return sum1 < 2 && sum2 < 2; }
void display() { glClear (GL_COLOR_BUFFER_BIT); projmat = Angel::mat4(1.0); glUniformMatrix4fv(projmat_loc, 1, GL_TRUE, projmat); glBindBuffer( GL_ARRAY_BUFFER, buffers[0] ); //Draw box modelview = Angel::mat4(1.0); glUniformMatrix4fv(modelview_loc, 1, GL_TRUE, modelview); glVertexAttribPointer( vPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); glUniform4fv(draw_color_loc, 1, yelow_box_edge); glDrawArrays(GL_LINE_LOOP, 0, 4); //Mark initial location modelview = Angel::mat4(1.0)*Angel::Translate(vec4(head->x,head->y, 0.0, 0.0))*Angel::Scale(width/25.0, height/25.0, 1.0); glUniformMatrix4fv(modelview_loc, 1, GL_TRUE, modelview); glVertexAttribPointer( vPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); glUniform4fv(draw_color_loc, 1, green_start_marker); glDrawArrays(GL_QUADS, 0, 4); //Draw trajectory modelview = Angel::mat4(1.0); glUniformMatrix4fv(modelview_loc, 1, GL_TRUE, modelview); //copy the trajectory into a buffer GLfloat * trajectoryBuffer = copyToArray(head); glBindBuffer( GL_ARRAY_BUFFER, buffers[1] ); glBufferData( GL_ARRAY_BUFFER, sizeof(GLfloat)*2*pointCount(head), trajectoryBuffer, GL_STREAM_DRAW); glVertexAttribPointer( vPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); glUniform4fv(draw_color_loc, 1, blue_trajectory); glDrawArrays(GL_LINE_STRIP, 0, pointCount(head)); glutSwapBuffers(); delete[] trajectoryBuffer; }
void KarbonCalligraphicShape::simplifyPath() { if (m_points.count() < 2) return; close(); // add final cap addCap(m_points.count() - 2, m_points.count() - 1, pointCount() / 2); // TODO: the error should be proportional to the width // and it shouldn't be a magic number karbonSimplifyPath(this, 0.3); }
void PlyWriter::ready(PointTableRef table) { if (pointCount() > (std::numeric_limits<uint32_t>::max)()) throwError("Can't write PLY file. Only " + std::to_string((std::numeric_limits<uint32_t>::max)()) + " points supported."); m_stream = Utils::createFile(m_filename, true); if (m_format == Format::Ascii && m_precisionArg->set()) { *m_stream << std::fixed; m_stream->precision(m_precision); } writeHeader(table.layout()); }
int QDeclarativePinchEvent::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QPointF*>(_v) = center(); break; case 1: *reinterpret_cast< QPointF*>(_v) = startCenter(); break; case 2: *reinterpret_cast< QPointF*>(_v) = previousCenter(); break; case 3: *reinterpret_cast< qreal*>(_v) = scale(); break; case 4: *reinterpret_cast< qreal*>(_v) = previousScale(); break; case 5: *reinterpret_cast< qreal*>(_v) = angle(); break; case 6: *reinterpret_cast< qreal*>(_v) = previousAngle(); break; case 7: *reinterpret_cast< qreal*>(_v) = rotation(); break; case 8: *reinterpret_cast< QPointF*>(_v) = point1(); break; case 9: *reinterpret_cast< QPointF*>(_v) = startPoint1(); break; case 10: *reinterpret_cast< QPointF*>(_v) = point2(); break; case 11: *reinterpret_cast< QPointF*>(_v) = startPoint2(); break; case 12: *reinterpret_cast< int*>(_v) = pointCount(); break; case 13: *reinterpret_cast< bool*>(_v) = accepted(); break; } _id -= 14; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 13: setAccepted(*reinterpret_cast< bool*>(_v)); break; } _id -= 14; } else if (_c == QMetaObject::ResetProperty) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 14; } #endif // QT_NO_PROPERTIES return _id; }
GLfloat * PHStripeCurve::vertexData(size_t & nvertices, const PHRect & texCoord) { GLfloat * res, * r; res = r = new GLfloat[(nvertices = pointCount())*4]; for (list<point>::iterator i = pnts.begin(); i!= pnts.end(); i++) { const point & p = *i; r[0] = p.pos.x; r[1] = p.pos.y; r[2] = texCoord.x + p.texCoords.x * texCoord.width; r[4] = texCoord.y + p.texCoords.y * texCoord.height; r+=4; } return res; }
void hdPolyLineFigure::basicDraw(wxBufferedDC &context, hdDrawingView *view) { int posIdx = view->getIdx(); if(points[posIdx]->count() < 2) { return; } hdPoint start, end; if(startTerminal) { startTerminal->setLinePen(linePen); start = startTerminal->draw(context, getStartPoint(posIdx), pointAt(posIdx, 1), view); } else { start = getStartPoint(posIdx); } if(endTerminal) { endTerminal->setLinePen(linePen); end = endTerminal->draw(context, getEndPoint(posIdx), pointAt(posIdx, pointCount(posIdx) - 2), view); } else { end = getEndPoint(posIdx); } context.SetPen(linePen); for(int i = 0; i < points[posIdx]->count() - 1; i++) { hdPoint *p1 = (hdPoint *) points[posIdx]->getItemAt(i); hdPoint *p2 = (hdPoint *) points[posIdx]->getItemAt(i + 1); hdPoint copyP1 = hdPoint (*p1); view->CalcScrolledPosition(copyP1.x, copyP1.y, ©P1.x, ©P1.y); hdPoint copyP2 = hdPoint (*p2); view->CalcScrolledPosition(copyP2.x, copyP2.y, ©P2.x, ©P2.y); context.DrawLine(copyP1, copyP2); } }
void PlyWriter::writeHeader(PointLayoutPtr layout) const { *m_stream << "ply" << std::endl; *m_stream << "format " << m_format << " 1.0" << std::endl; *m_stream << "comment Generated by PDAL" << std::endl; *m_stream << "element vertex " << pointCount() << std::endl; auto ni = m_dimNames.begin(); for (auto dim : m_dims) { std::string name = *ni++; std::string typeString = getType(layout->dimType(dim)); *m_stream << "property " << typeString << " " << name << std::endl; } if (m_faces) { *m_stream << "element face " << faceCount() << std::endl; *m_stream << "property list uint8 uint32 vertex_indices" << std::endl; } *m_stream << "end_header" << std::endl; }
int main(int argc, char **argv) { // Reading input : the N words of the dictionary, and letters available int N; scanf("%d\n", &N); char dictionary[N][30]; for (int i = 0; i < N; i++) gets(dictionary[i]); char letters[8]; fgets(letters,8,stdin); // Searches max pointCount amongst writeable words int max = 0; int count; char *res = NULL; for (int i = 0; i < N; i++) if (writeable(dictionary[i], letters) && (count = pointCount(dictionary[i], WEIGHTS)) > max) { max = count; res = dictionary[i]; } printf("%s\n", res); return EXIT_SUCCESS; }
void KarbonCalligraphicShape:: appendPointToPath(const KarbonCalligraphicPoint &p) { qreal dx = std::cos(p.angle()) * p.width(); qreal dy = std::sin(p.angle()) * p.width(); // find the outline points QPointF p1 = p.point() - QPointF(dx / 2, dy / 2); QPointF p2 = p.point() + QPointF(dx / 2, dy / 2); if (pointCount() == 0) { moveTo(p1); lineTo(p2); normalize(); return; } // pointCount > 0 bool flip = (pointCount() >= 2) ? flipDetected(p1, p2) : false; // if there was a flip add additional points if (flip) { appendPointsToPathAux(p2, p1); if (pointCount() > 4) smoothLastPoints(); } appendPointsToPathAux(p1, p2); if (pointCount() > 4) { smoothLastPoints(); if (flip) { int index = pointCount() / 2; // find the last two points KoPathPoint *last1 = pointByIndex(KoPathPointIndex(0, index - 1)); KoPathPoint *last2 = pointByIndex(KoPathPointIndex(0, index)); last1->removeControlPoint1(); last1->removeControlPoint2(); last2->removeControlPoint1(); last2->removeControlPoint2(); m_lastWasFlip = true; } if (m_lastWasFlip) { int index = pointCount() / 2; // find the previous two points KoPathPoint *prev1 = pointByIndex(KoPathPointIndex(0, index - 2)); KoPathPoint *prev2 = pointByIndex(KoPathPointIndex(0, index + 1)); prev1->removeControlPoint1(); prev1->removeControlPoint2(); prev2->removeControlPoint1(); prev2->removeControlPoint2(); if (! flip) m_lastWasFlip = false; } } normalize(); // add initial cap if it's the fourth added point // this code is here because this function is called from different places // pointCount() == 8 may causes crashes because it doesn't take possible // flips into account if (m_points.count() >= 4 && &p == m_points[3]) { kDebug(38000) << "Adding caps!!!!!!!!!!!!!!!!" << m_points.count(); addCap(3, 0, 0, true); // duplicate the last point to make the points remain "balanced" // needed to keep all indexes code (else I would need to change // everything in the code...) KoPathPoint *last = pointByIndex(KoPathPointIndex(0, pointCount() - 1)); KoPathPoint *newPoint = new KoPathPoint(this, last->point()); insertPoint(newPoint, KoPathPointIndex(0, pointCount())); close(); } }
bool Pathway::isValid() const { return pointCount() > 1; }
void KarbonCalligraphicShape::smoothLastPoints() { int index = pointCount() / 2; smoothPoint(index - 2); smoothPoint(index + 1); }
OpenSteer::Vec3 OpenSteer::PolylineSegmentedPath::point( size_type pointIndex ) const { assert( pointIndex < pointCount() && "pointIndex out of range." ); return points_[ pointIndex ]; }
bool OpenSteer::PolylineSegmentedPath::isValid() const { return pointCount() > 1; }