Path: blob/master/thirdparty/msdfgen/core/edge-selectors.h
9903 views
1#pragma once23#include "Vector2.hpp"4#include "SignedDistance.hpp"5#include "edge-segments.h"67namespace msdfgen {89struct MultiDistance {10double r, g, b;11};12struct MultiAndTrueDistance : MultiDistance {13double a;14};1516/// Selects the nearest edge by its true distance.17class TrueDistanceSelector {1819public:20typedef double DistanceType;2122struct EdgeCache {23Point2 point;24double absDistance;2526EdgeCache();27};2829void reset(const Point2 &p);30void addEdge(EdgeCache &cache, const EdgeSegment *prevEdge, const EdgeSegment *edge, const EdgeSegment *nextEdge);31void merge(const TrueDistanceSelector &other);32DistanceType distance() const;3334private:35Point2 p;36SignedDistance minDistance;3738};3940class PerpendicularDistanceSelectorBase {4142public:43struct EdgeCache {44Point2 point;45double absDistance;46double aDomainDistance, bDomainDistance;47double aPerpendicularDistance, bPerpendicularDistance;4849EdgeCache();50};5152static bool getPerpendicularDistance(double &distance, const Vector2 &ep, const Vector2 &edgeDir);5354PerpendicularDistanceSelectorBase();55void reset(double delta);56bool isEdgeRelevant(const EdgeCache &cache, const EdgeSegment *edge, const Point2 &p) const;57void addEdgeTrueDistance(const EdgeSegment *edge, const SignedDistance &distance, double param);58void addEdgePerpendicularDistance(double distance);59void merge(const PerpendicularDistanceSelectorBase &other);60double computeDistance(const Point2 &p) const;61SignedDistance trueDistance() const;6263private:64SignedDistance minTrueDistance;65double minNegativePerpendicularDistance;66double minPositivePerpendicularDistance;67const EdgeSegment *nearEdge;68double nearEdgeParam;6970};7172/// Selects the nearest edge by its perpendicular distance.73class PerpendicularDistanceSelector : public PerpendicularDistanceSelectorBase {7475public:76typedef double DistanceType;7778void reset(const Point2 &p);79void addEdge(EdgeCache &cache, const EdgeSegment *prevEdge, const EdgeSegment *edge, const EdgeSegment *nextEdge);80DistanceType distance() const;8182private:83Point2 p;8485};8687/// Selects the nearest edge for each of the three channels by its perpendicular distance.88class MultiDistanceSelector {8990public:91typedef MultiDistance DistanceType;92typedef PerpendicularDistanceSelectorBase::EdgeCache EdgeCache;9394void reset(const Point2 &p);95void addEdge(EdgeCache &cache, const EdgeSegment *prevEdge, const EdgeSegment *edge, const EdgeSegment *nextEdge);96void merge(const MultiDistanceSelector &other);97DistanceType distance() const;98SignedDistance trueDistance() const;99100private:101Point2 p;102PerpendicularDistanceSelectorBase r, g, b;103104};105106/// Selects the nearest edge for each of the three color channels by its perpendicular distance and by true distance for the alpha channel.107class MultiAndTrueDistanceSelector : public MultiDistanceSelector {108109public:110typedef MultiAndTrueDistance DistanceType;111112DistanceType distance() const;113114};115116}117118119