Line::Line(cv::Vec4i points) { m_StartPt = cv::Point(points[0], points[1]); m_EndPt = cv::Point(points[2], points[3]); m_Length = 0; calcSlope(); calcLength(); }
void Line::adjustLineLength(ushort rows) { corrLineDirection(); adjustPoint(rows, true); adjustPoint((rows >> 1), false); calcLength(); calcSlope(); }
// since the collections are to be "live", we have to do the // calculation every time if anything has changed unsigned HTMLCollection::length() const { resetCollectionInfo(); if (!m_info->hasLength) { m_info->length = calcLength(); m_info->hasLength = true; } return m_info->length; }
/* *Normal Chemical synapses - common for node interconnection in the network */ dojoChemicalSynapse::dojoChemicalSynapse(dojoNode* source, dojoNode* target) { Source = source; Target = target; Terminals = 100; Cleft = 0; Permability = 5; calcLength(); }
void PinNode::drawShape( QPainter & p ) { initPainter( p ); double v = pin() ? pin()->voltage() : 0.0; QColor voltageColor = Component::voltageColor( v ); QPen pen = p.pen(); if ( isSelected() ) pen = m_selectedColor; else if ( m_bShowVoltageColor ) pen = voltageColor; if (m_pinPoint) { bool drawDivPoint; QPoint divPoint = findConnectorDivergePoint(&drawDivPoint); m_pinPoint->setVisible(drawDivPoint); m_pinPoint->move( divPoint.x()-1, divPoint.y()-1 ); m_pinPoint->setBrush( pen.color() ); m_pinPoint->setPen( pen.color() ); } // Now to draw on our current/voltage bar indicators int length = calcLength( v ); if ( (numPins() == 1) && m_bShowVoltageBars && length != 0 ) { // we can assume that v != 0 as length != 0 double i = pin()->current(); double iProp = calcIProp(i); int thickness = calcThickness(iProp); p.setPen( QPen( voltageColor, thickness ) ); // The node line (drawn at the end of this function) will overdraw // some of the voltage bar, so we need to adapt the length if ( (v > 0) && (((225 < m_dir) && (m_dir < 315)) || ((45 < m_dir) && (m_dir < 135))) ) length--; else if ( (v < 0) && (((135 < m_dir) && (m_dir < 225)) || ((315 < m_dir) || (m_dir < 45))) ) length++; if ( (m_dir > 270) || (m_dir <= 90) ) p.drawLine( 3, 0, 3, length ); else p.drawLine( 3, 0, 3, -length ); } pen.setWidth( (numPins() > 1) ? 2 : 1 ); p.setPen( pen ); p.drawLine( 0, 0, m_length, 0 ); deinitPainter( p ); }
void twistedpair::initAC (void) { calcLength (); if (len != 0.0) { setVoltageSources (0); allocMatrixMNA (); } else { setVoltageSources (2); allocMatrixMNA (); voltageSource (VSRC_1, NODE_1, NODE_2); voltageSource (VSRC_2, NODE_3, NODE_4); } }
/***************************************************** ** ** EphemExpert --- calcIngress ** ******************************************************/ int EphemExpert::calcIngress() { int p; int ret = 0; if ( !clen ) ret = calcLength(); ingressEvents.clear(); // Achtung: das geht nicht immer für den Mond, weil der mehr als ein Event am Tag haben kann for ( int i = 0; i < nb_days; i++ ) { d->setDate( i+1, month, year, 12 ); for ( unsigned int j = 0; j < planetdata.size(); j++ ) { p = planetdata[j].pindex; if ( p == OARIES || p == OASCENDANT || p == OMERIDIAN ) continue; if( planetdata[j].rasi[i] != planetdata[j].rasi[i+1] ) { testIngressEvent( planetdata[j].rasi[i], planetdata[j].rasi[i+1], p, 0, planetdata[j].retro[i] ); } if ( chartprops->isVedic() ) { // Nakshatra changes if ( planetdata[j].nakshatra[i] != planetdata[j].nakshatra[i+1] ) { const int base_nak = planetdata[j].nakshatra[i]; const int diff_nak = red27( planetdata[j].nakshatra[i+1] - base_nak ); switch( diff_nak ) { case 1: testIngressEvent( base_nak, red27( base_nak + 1 ), p, 1, planetdata[j].retro[i] ); break; case 2: testIngressEvent( base_nak, red27( base_nak + 1 ), p, 1, planetdata[j].retro[i] ); testIngressEvent( red27( base_nak + 1 ), red27( base_nak + 2 ), p, 1, planetdata[j].retro[i+1] ); break; default: break; } } } } } ingressEvents.sort( IngressEventSorter() ); cingress = true; return ret; }
/***************************************************** ** ** EphemExpert --- calcLunar ** ******************************************************/ void EphemExpert::calcLunar() { int i, t, t2; double diff, diff2; lunarEvents.clear(); if ( !clen ) calcLength(); diff = red_deg( planetdata[OMOON].len[0] - planetdata[OSUN].len[0] ); t = (int)(diff/12); for ( i = 1; i <= nb_days; i++ ) { diff2 = red_deg( planetdata[OMOON].len[i] - planetdata[OSUN].len[i] ); t2 = (int)(diff2/12); if ( t2 != t ) { addLunarEvent( i-1, t2 * 12, diff, diff2 ); // Happens once a month, i.e. double step if ( t2 - t > 1 ) { addLunarEvent( i-1, ( t + 1 ) * 12, diff, diff2 ); } } // Squares addLunarSpecialEvent( i-1, 90, diff, diff2 ); addLunarSpecialEvent( i-1, 270, diff, diff2 ); // Semi Squares addLunarSpecialEvent( i-1, 45, diff, diff2 ); addLunarSpecialEvent( i-1, 135, diff, diff2 ); addLunarSpecialEvent( i-1, 225, diff, diff2 ); addLunarSpecialEvent( i-1, 315, diff, diff2 ); diff = diff2; t = t2; } lunarEvents.sort( LunarEventSort() ); clunar = true; }
/***************************************************** ** ** EphemExpert --- calcKP ** ******************************************************/ void EphemExpert::calcKP( const int &dasa ) { KPEvent *e; vector<KPEvent>::iterator iter; Calculator *calculator = CalculatorFactory().getCalculator(); DasaExpert *expert = DasaExpertFactory::get()->getDasaExpert( dasa ); if ( ! expert->hasKpFeatures() || dasa == 2 ) return; if ( !clen ) calcLength(); kpevents = expert->getKPEventList( planetdata[OMOON].len[0], planetdata[OMOON].len[nb_days], jd[0] ); // calculates all lord/sublord events for ( iter = kpevents.begin(); iter != kpevents.end(); iter++ ) { e = (KPEvent*)(&(*iter)); d->setDate( e->jd ); e->jd = calculator->calcPlanetaryEvent( d, e->len, 1, chartprops->isVedic() ); // get the dates for the events } ckp = true; mydasa = dasa; }
void twistedpair::initDC (void) { nr_double_t d = getPropertyDouble ("d"); nr_double_t rho = getPropertyDouble ("rho"); calcLength (); if (d != 0.0 && rho != 0.0 && len != 0.0) { // tiny resistances nr_double_t g1 = M_PI * sqr (d / 2) / rho / len; nr_double_t g2 = g1; setVoltageSources (0); allocMatrixMNA (); setY (NODE_1, NODE_1, +g1); setY (NODE_2, NODE_2, +g1); setY (NODE_1, NODE_2, -g1); setY (NODE_2, NODE_1, -g1); setY (NODE_3, NODE_3, +g2); setY (NODE_4, NODE_4, +g2); setY (NODE_3, NODE_4, -g2); setY (NODE_4, NODE_3, -g2); } else { // DC shorts setVoltageSources (2); allocMatrixMNA (); voltageSource (VSRC_1, NODE_1, NODE_2); voltageSource (VSRC_2, NODE_3, NODE_4); } }
/***************************************************** ** ** EphemExpert --- writeDefaultEphemeris ** ******************************************************/ int EphemExpert::writeDefaultEphemeris( Writer *writer ) { int ret = 0; wxString tz_str, s, rasi_str, nak_str; int i, j, deg, min, numcols; unsigned int i1; double rasilen; bool showrasi, shownak; wxString d; Lang lang; if ( !clen ) ret = calcLength(); writeHeaderInfo( writer ); numcols = planetdata.size() + 1; int line = 1; int nb_leaps = 0; for ( i = 0; i < nb_days; i++ ) { if ( i > 0 && weekday[i] == 0 ) nb_leaps++; } Table table( numcols, nb_days+nb_leaps+2 ); table.setHeader( 0, _( "Day" )); // Header int col = 1; for ( i1 = 0; i1 < planetdata.size(); i1++ ) { table.setHeader( col, writer->getObjectName( planetdata[i1].pindex, TLARGE, chartprops->isVedic() )); col++; } line = 1; for ( i = 0; i < nb_days; i++ ) { //if ( i > 0 && weekday[i] == 0 ) o << Endl; // blank line on weekend if ( i > 0 && weekday[i] == 0 ) { for ( j = 0; j < numcols; j++ ) table.setHeaderEntry( j, line, wxEmptyString ); line++; } s.Printf( wxT( "%02d %s" ), i+1, (const wxChar*)lang.getWeekdayName( weekday[i] ).Left(2) ); // write TZ if change during month /* if ( dstchange ) { TzFormattedDate fd = tzutil.getDateFormatted( jd[i], isLocaltime ); s << wxT( " " ) << fd.timezoneFormatted; } */ if ( testDayIndexForCurrent( i+1 )) table.setHeaderEntry( 0, line, s ); else table.setEntry( 0, line, s ); col = 1; for ( i1 = 0; i1 < planetdata.size(); i1++ ) { rasilen = getRasiLen( planetdata[i1].len[i] ) + .008333333; deg = (int)rasilen; min = (int)( 60 * ( rasilen - (double)deg )); // symbol for retrogression d = wxT( " " ); if ( planetdata[i1].retro[i] ) { d = writer->getRetroSymbol(); } else if ( i > 1 && planetdata[i1].retro[i] != planetdata[i1].retro[i-1] ) { planetdata[i1].retro[i] ? d = writer->getRetroSymbol(): d = writer->getRetroSymbol( 1 ); } else if ( i == nb_days - 1 && planetdata[i1].retro[i] ) { d = writer->getRetroSymbol(); } showrasi = shownak = true; rasi_str = showrasi ? writer->getSignName( planetdata[i1].rasi[i] ) : wxT( " " ); nak_str = shownak ? lang.getNakshatraName( planetdata[i1].nakshatra[i], N27 ) : wxT( " " ); // ready to print now if ( config->useVedicPositions ) { if ( chartprops->isVedic() ) { s.Printf( wxT( "%s%02d-%02d-%02d %s" ), (const wxChar*)d, planetdata[i1].rasi[i], deg, min, (const wxChar*)nak_str ); } else { s.Printf( wxT( "%s%02d-%02d-%02d" ), (const wxChar*)d, planetdata[i1].rasi[i], deg, min ); } } else { if ( chartprops->isVedic() ) { s.Printf( wxT( "%s%02d%s%02d %s" ), (const wxChar*)d, deg, (const wxChar*)rasi_str, min, (const wxChar*)nak_str ); } else { s.Printf( wxT( "%s%02d%s%02d" ), (const wxChar*)d, deg, (const wxChar*)rasi_str, min ); } } table.setEntry( col, line, s ); col++; } line++; } // Header table.setHeaderEntry( 0, line, _( "Day" )); col = 1; for ( i1 = 0; i1 < planetdata.size(); i1++ ) { table.setHeaderEntry( col, line, writer->getObjectName( planetdata[i1].pindex, TLARGE, chartprops->isVedic() )); col++; } writer->writeTable( table ); return ret; }
/***************************************************** ** ** EphemExpert --- calcMonth ** ******************************************************/ int EphemExpert::calcMonth() { if ( !clen ) return calcLength(); else return 0; }
void twistedpair::initSP (void) { allocMatrixS (); calcLength (); }
ushort Line::getLength() { if (m_Length == 0) { calcLength(); } return m_Length; }
int main() { int n; scanf("%d", &n); std::vector<pos> cities(n); for(int i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); cities[i] = pos(x, y); } double result = 0.f; for(auto it = cities.begin(); it < cities.end(); it++) { std::unordered_map<ratio, segment, ratiohash> h; h.reserve(300); for(auto it2 = cities.begin(); it2 < cities.end(); it2++) { if(it == it2) continue; pos c1 = *it, c2 = *it2; if(c2.x < c1.x) // c2 must always refers to the rightmost (or topmost) city std::swap(c1, c2); int dx = c2.x - c1.x; int dy = c2.y - c1.y; if(dx != 0) { // We map each slope to its (reduced) ratio int g = gcd(dx, dy); ratio slope = ratio(dx/g, dy/g); auto it = h.find(slope); if(it != h.end()) { int& np = it->second.mul; // Number of other cities along this line int& x1 = it->second.v1; int& x2 = it->second.v2; // We update the result, so remove the old one result -= calcLength(slope, x1, x2)/np; if(c2.x > x2) // Possibly expand the interval x2 = c2.x; else if(c1.x < x1) x1 = c1.x; np++; // We have to divide the result by the number of cities along this line since // we will be recalculating it each time the outer loop encounters such a city result += calcLength(slope, x1, x2)/double(np); } else { // This is the first other city found along this slope. If there turns out to // be only two cities along this line, we will be overestimating the result by // 2 since our outer loop will reach the other city, so preemptively divide by 2 h.insert(std::make_pair(slope, segment(c1.x, c2.x, 2))); result += calcLength(slope, c1.x, c2.x)/2.0f; } } else // dx = 0 - in this case the interval is not along the x axis but the y axis { // so we adjust accordingly auto it = h.find(pos(0, 1)); if(c2.y < c1.y) std::swap(c1, c2); if(it != h.end()) { int& np = it->second.mul; int& y1 = it->second.v1; int& y2 = it->second.v2; double dy = y2-y1; result -= dy/np; if(c2.y > y2) y2 = c2.y; else if(c1.y < y1) y1 = c1.y; np++; result += (y2-y1)/double(np); } else { h.insert(std::make_pair(pos(0, 1), segment(c1.y, c2.y, 2))); result += std::abs(dy)/2.f; } } } } std::printf("%.0lf\n", result); return 0; }
void ofxJpegGlitch::glitch() { unsigned char* bytes = (unsigned char *)buf.getBinaryBuffer(); int cur = 0; MarkerType startMarker = calcMarkerType(bytes, cur); if(startMarker != MT_SOI) { ofLogError("this isn't jpeg"); return; } cur += 2; int mcuNumber = 0; int bpp = 0; int width = 0; int height = 0; int resetMarkerNum = 0; while(cur < buf.size()) { MarkerType marker = calcMarkerType(bytes, cur); cur += 2; int length = 0; switch (marker) { case MT_DRI: { length = calcLength(bytes, cur); mcuNumber = bytes[cur + 2] * 256 + bytes[cur + 3]; break; } case MT_DQT: { length = calcLength(bytes, cur); int offset = 2; int Pqn = 0; int Tqn = 0; int Qn[64]; while(offset < length) { Pqn = (*(bytes + cur + offset) & 0xF0) >> 4; Tqn = *(bytes + cur + offset) & 0x0F; if(Pqn == 0) { for(int i = 0; i < 64; i++) { Qn[i] = *(bytes + cur + offset + i); // RANDOMIZE if(ofRandom(0.0f, randomMax) < qnBlock) { *(bytes + cur + offset + i) = rand() % 256; } } offset += 64 + 1; } else { for(int i = 0; i < 64; i++) { Qn[i] = *(bytes + cur + offset + 2 * i); Qn[i] = Qn[i] * 256 + *(bytes + cur + offset + 2 * i + 1); // RANDOMIZE if(ofRandom(0.0f, randomMax) < qnBlock) { *(bytes + cur + offset + i) = rand() % 256; } } offset += 128 + 1; } } break; } case MT_DHT: { length = calcLength(bytes, cur); int offset = 2; int Tcn = 0; int Thn = 0; Byte Ln[16]; Byte Vnn[16][256]; while(offset < length) { Tcn = (*(bytes + cur + offset) & 0xF0) >> 4; Thn = *(bytes + cur + offset) & 0x0F; offset += 1; memcpy(Ln, bytes + cur + offset, 16); int vOffset = 0; for(int i = 0; i < 16; i++) { memcpy(Vnn[i], bytes + cur + offset + vOffset, Ln[i]); for(int i = 0; i < Ln[i]; i++) { if(ofRandom(0.0f, randomMax) < dhtBlock) { *(bytes + cur + offset + vOffset) = rand() % 256; } } vOffset += Ln[i]; } offset += vOffset; } break; } case MT_SOS: { length = calcLength(bytes, cur); break; } case MT_APP0: case MT_APP1: case MT_APP2: case MT_APP3: case MT_APP4: case MT_APP5: case MT_APP6: case MT_APP7: case MT_APP8: case MT_APP9: case MT_APPa: case MT_APPb: case MT_APPc: case MT_APPd: case MT_APPe: case MT_APPf: { length = calcLength(bytes, cur); break; } case MT_SOF0: case MT_SOF1: case MT_SOF2: case MT_SOF3: case MT_SOF4: case MT_SOF5: case MT_SOF6: case MT_SOF7: case MT_SOF8: case MT_SOF9: case MT_SOFa: case MT_SOFb: case MT_SOFc: case MT_SOFd: case MT_SOFe: case MT_SOFf: { length = calcLength(bytes, cur); bpp = bytes[cur + 2]; width = bytes[cur + 3] * 256 + bytes[cur + 4]; height = bytes[cur + 5] * 256 + bytes[cur + 6]; break; } default: { length = calcLength(bytes, cur); break; } } cur += length; if(marker == MT_SOS) { break; } } while(cur < buf.size()) { if(bytes[cur] == 0xFF && bytes[cur] != 0x0) { cur += 2; } else { // RANDOMIZE if(*(bytes + cur) != 0xFF && (ofRandom(0.0f, randomMax) < dataBlock)) { *(bytes + cur) = rand() % 255; } cur++; } } bImageLoaded = false; }