void ConnectorComponent::getDistancesFromEnds (int x, int y, double& distanceFromStart, double& distanceFromEnd) const { float x1, y1, x2, y2; getPoints (x1, y1, x2, y2); distanceFromStart = juce_hypot (x - (x1 - getX()), y - (y1 - getY())); distanceFromEnd = juce_hypot (x - (x2 - getX()), y - (y2 - getY())); }
static void shortenSubPath (Array<LineSection>& subPath, float amountAtStart, float amountAtEnd) { while (amountAtEnd > 0 && subPath.size() > 0) { LineSection& l = subPath.getReference (subPath.size() - 1); float dx = l.rx2 - l.rx1; float dy = l.ry2 - l.ry1; const float len = juce_hypot (dx, dy); if (len <= amountAtEnd && subPath.size() > 1) { LineSection& prev = subPath.getReference (subPath.size() - 2); prev.x2 = l.x2; prev.y2 = l.y2; subPath.removeLast(); amountAtEnd -= len; } else { const float prop = jmin (0.9999f, amountAtEnd / len); dx *= prop; dy *= prop; l.rx1 += dx; l.ry1 += dy; l.lx2 += dx; l.ly2 += dy; break; } } while (amountAtStart > 0 && subPath.size() > 0) { LineSection& l = subPath.getReference (0); float dx = l.rx2 - l.rx1; float dy = l.ry2 - l.ry1; const float len = juce_hypot (dx, dy); if (len <= amountAtStart && subPath.size() > 1) { LineSection& next = subPath.getReference (1); next.x1 = l.x1; next.y1 = l.y1; subPath.remove (0); amountAtStart -= len; } else { const float prop = jmin (0.9999f, amountAtStart / len); dx *= prop; dy *= prop; l.rx2 -= dx; l.ry2 -= dy; l.lx1 -= dx; l.ly1 -= dy; break; } } }
static void addLineEnd (Path& destPath, const PathStrokeType::EndCapStyle style, const float x1, const float y1, const float x2, const float y2, const float width) { if (style == PathStrokeType::butt) { destPath.lineTo (x2, y2); } else { float offx1, offy1, offx2, offy2; float dx = x2 - x1; float dy = y2 - y1; const float len = juce_hypot (dx, dy); if (len == 0) { offx1 = offx2 = x1; offy1 = offy2 = y1; } else { const float offset = width / len; dx *= offset; dy *= offset; offx1 = x1 + dy; offy1 = y1 - dx; offx2 = x2 + dy; offy2 = y2 - dx; } if (style == PathStrokeType::square) { // sqaure ends destPath.lineTo (offx1, offy1); destPath.lineTo (offx2, offy2); destPath.lineTo (x2, y2); } else { // rounded ends const float midx = (offx1 + offx2) * 0.5f; const float midy = (offy1 + offy2) * 0.5f; destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f, offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f, midx, midy); destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f, offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f, x2, y2); } } }
void FFT::performFrequencyOnlyForwardTransform (float* d) const noexcept { performRealOnlyForwardTransform (d); const int twiceSize = size * 2; for (int i = 0; i < twiceSize; i += 2) { d[i / 2] = juce_hypot (d[i], d[i + 1]); if (i >= size) { d[i] = 0; d[i + 1] = 0; } } }
void Graphics::drawDashedLine (const float startX, const float startY, const float endX, const float endY, const float* const dashLengths, const int numDashLengths, const float lineThickness) const { const double dx = endX - startX; const double dy = endY - startY; const double totalLen = juce_hypot (dx, dy); if (totalLen >= 0.5) { const double onePixAlpha = 1.0 / totalLen; double alpha = 0.0; float x = startX; float y = startY; int n = 0; while (alpha < 1.0f) { alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha); n = n % numDashLengths; const float oldX = x; const float oldY = y; x = (float) (startX + dx * alpha); y = (float) (startY + dy * alpha); if ((n & 1) != 0) { if (lineThickness != 1.0f) drawLine (oldX, oldY, x, y, lineThickness); else drawLine (oldX, oldY, x, y); } } } }
const Rectangle Desktop::getMonitorAreaContaining (int cx, int cy, const bool clippedToWorkArea) const throw() { Rectangle best (getMainMonitorArea (clippedToWorkArea)); double bestDistance = 1.0e10; for (int i = getNumDisplayMonitors(); --i >= 0;) { const Rectangle rect (getDisplayMonitorCoordinates (i, clippedToWorkArea)); if (rect.contains (cx, cy)) return rect; const double distance = juce_hypot ((double) (rect.getCentreX() - cx), (double) (rect.getCentreY() - cy)); if (distance < bestDistance) { bestDistance = distance; best = rect; } } return best; }
void PathStrokeType::createDashedStroke (Path& destPath, const Path& sourcePath, const float* dashLengths, int numDashLengths, const AffineTransform& transform, const float extraAccuracy) const { jassert (extraAccuracy > 0); if (thickness <= 0) return; // this should really be an even number.. jassert ((numDashLengths & 1) == 0); Path newDestPath; PathFlatteningIterator it (sourcePath, transform, PathFlatteningIterator::defaultTolerance / extraAccuracy); bool first = true; int dashNum = 0; float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f; float dx = 0.0f, dy = 0.0f; for (;;) { const bool isSolid = ((dashNum & 1) == 0); const float dashLen = dashLengths [dashNum++ % numDashLengths]; jassert (dashLen > 0); // must be a positive increment! if (dashLen <= 0) break; pos += dashLen; while (pos > lineEndPos) { if (! it.next()) { if (isSolid && ! first) newDestPath.lineTo (it.x2, it.y2); createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy); return; } if (isSolid && ! first) newDestPath.lineTo (it.x1, it.y1); else newDestPath.startNewSubPath (it.x1, it.y1); dx = it.x2 - it.x1; dy = it.y2 - it.y1; lineLen = juce_hypot (dx, dy); lineEndPos += lineLen; first = it.closesSubPath; } const float alpha = (pos - (lineEndPos - lineLen)) / lineLen; if (isSolid) newDestPath.lineTo (it.x1 + dx * alpha, it.y1 + dy * alpha); else newDestPath.startNewSubPath (it.x1 + dx * alpha, it.y1 + dy * alpha); } }
float AffineTransform::getScaleFactor() const noexcept { return juce_hypot (mat00 + mat01, mat10 + mat11); }
inline double lengthOf (float x1, float y1, float x2, float y2) noexcept { return juce_hypot ((double) (x1 - x2), (double) (y1 - y2)); }