Path: blob/master/thirdparty/graphite/src/inc/Position.h
9906 views
// SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later1// Copyright 2010, SIL International, All rights reserved.23#pragma once45namespace graphite2 {67class Position8{9public:10Position() : x(0), y(0) { }11Position(const float inx, const float iny) : x(inx), y(iny) {}12Position operator + (const Position& a) const { return Position(x + a.x, y + a.y); }13Position operator - (const Position& a) const { return Position(x - a.x, y - a.y); }14Position operator * (const float m) const { return Position(x * m, y * m); }15Position &operator += (const Position &a) { x += a.x; y += a.y; return *this; }16Position &operator *= (const float m) { x *= m; y *= m; return *this; }1718float x;19float y;20};2122class Rect23{24public :25Rect() {}26Rect(const Position& botLeft, const Position& topRight): bl(botLeft), tr(topRight) {}27Rect widen(const Rect& other) { return Rect(Position(bl.x > other.bl.x ? other.bl.x : bl.x, bl.y > other.bl.y ? other.bl.y : bl.y), Position(tr.x > other.tr.x ? tr.x : other.tr.x, tr.y > other.tr.y ? tr.y : other.tr.y)); }28Rect operator + (const Position &a) const { return Rect(Position(bl.x + a.x, bl.y + a.y), Position(tr.x + a.x, tr.y + a.y)); }29Rect operator - (const Position &a) const { return Rect(Position(bl.x - a.x, bl.y - a.y), Position(tr.x - a.x, tr.y - a.y)); }30Rect operator * (float m) const { return Rect(Position(bl.x, bl.y) * m, Position(tr.x, tr.y) * m); }31float width() const { return tr.x - bl.x; }32float height() const { return tr.y - bl.y; }3334bool hitTest(Rect &other);3536// returns Position(overlapx, overlapy) where overlap<0 if overlapping else positive)37Position overlap(Position &offset, Rect &other, Position &otherOffset);38//Position constrainedAvoid(Position &offset, Rect &box, Rect &sdbox, Position &other, Rect &obox, Rect &osdbox);3940Position bl;41Position tr;42};4344} // namespace graphite2454647