Okular::NormalizedPoint

Search for usage in LXR

#include <area.h>

Public Member Functions

 NormalizedPoint ()
 
 NormalizedPoint (const NormalizedPoint &)
 
 NormalizedPoint (double x, double y)
 
 NormalizedPoint (int x, int y, int xScale, int yScale)
 
double distanceSqr (double x, double y, double xScale, double yScale) const
 
NormalizedPointoperator= (const NormalizedPoint &)
 
void transform (const QTransform &matrix)
 

Static Public Member Functions

static double distanceSqr (double x, double y, double xScale, double yScale, const NormalizedPoint &start, const NormalizedPoint &end)
 

Public Attributes

double x
 
double y
 

Detailed Description

NormalizedPoint is a helper class which stores the coordinates of a normalized point.

Normalized Coordinate System

Normalized means that the coordinates are always between 0 and 1, unless the point shall be outside of the reference area.

The reference area is a rectangle, and all normalized points with coordinates of 0 or 1 describe its edges.

This allows to locate things on a reference area without knowing its (current or future) actual size. When the reference area is resized, all things which are described in normalized coordinates keep their proportional position on the area.

Transformation to and from Normalized Coordinates

To transform normalized coordinates to coordinates on the reference area, just multiply them with the size of the reference area.

To get normalized coordinates from a point on the reference area, just divide its coordinates with the size of the reference area.

Many methods have parameters xScale and yScale, these are equal to the size of the reference area.

Normalized Coordinate System Applied to Pages

Okular uses a normalized coordinate system mainly to describe positions on pages. This is useful because pages can be shown in different sizes (zoom), but all objects shall keep their proportional position on the page.

Okular maps from page to normalized coordinates as follows:

  • Left edge of the page: x = 0
  • Right edge of the page: x = 1
  • Top edge of the page: y = 0
  • Bottom edge of the page: y = 1
Example: Draw a Point on a Page

The point is given in normalized coordinates (0.5, 0.3).

If you want to draw it on a 800x600 page, just multiply the x coordinate (0.5) with the page width (800), and the y coordinate (0.3) with the page height (600). So, the point will be drawn on the page at (400, 180).

That allows you to zoom the page by just multiplying the normalized points with the zoomed page size.

Example: Select Text on a Page using Mouse Events

The position of all glyphs and words is stored in normalized coordinates. (This is what TextPage actually does.) Mouse press and release events are given in page coordinates (400, 180) and (600, 450), while the page has a size of 800x600.

If you want to search all text between the mouse click and release event, you need their normalized coordinates. Just divide the x coordinates (400 and 600) by the page width (800), and the y coordinates (180 and 450) by the page height (600). So, you have to search for all glyphs between (0.5, 0.3) and (0.75, 0.75).

That allows you to process all glyphs and words without having to keep any of their positions in sync with the page.

Geometric operations

NormalizedPoint supports basic geometric operations.

  • You can transform it with a QTransform matrix.
  • With the size of the reference area, you can calculate the squared absolute distance to another NormalizedPoint or a line of two NormalizedPoints.

NormalizedRect provides additional geometric operations for rectangles.

See also
NormalizedRect

Definition at line 116 of file area.h.

Constructor & Destructor Documentation

◆ NormalizedPoint() [1/3]

NormalizedPoint::NormalizedPoint ( )

Creates a normalized point at (0, 0).

class NormalizedPoint

Definition at line 21 of file area.cpp.

◆ NormalizedPoint() [2/3]

NormalizedPoint::NormalizedPoint ( double x,
double y )

Creates a new normalized point with the normalized coordinates (x, y ).

Definition at line 27 of file area.cpp.

◆ NormalizedPoint() [3/3]

NormalizedPoint::NormalizedPoint ( int x,
int y,
int xScale,
int yScale )

Creates a new normalized point from an absolute point (x, y) on a reference area of size xScale x yScale.

Definition at line 33 of file area.cpp.

Member Function Documentation

◆ distanceSqr() [1/2]

double NormalizedPoint::distanceSqr ( double x,
double y,
double xScale,
double yScale ) const

Returns squared distance to normalized point (x, y) on a reference area of size xScale x yScale.

Since
0.17 (KDE 4.11)

Definition at line 51 of file area.cpp.

◆ distanceSqr() [2/2]

double NormalizedPoint::distanceSqr ( double x,
double y,
double xScale,
double yScale,
const NormalizedPoint & start,
const NormalizedPoint & end )
static

Returns squared distance of the normalized point (x, y) to the line segment from start to end on a reference area of size xScale x yScale.

Calculates distance of the point x y xScale yScale to the line segment from start to end.

Since
0.17 (KDE 4.11)

Definition at line 68 of file area.cpp.

◆ operator=()

NormalizedPoint & NormalizedPoint::operator= ( const NormalizedPoint & )
default

◆ transform()

void NormalizedPoint::transform ( const QTransform & matrix)

Transforms the normalized point with the operations defined by matrix.

Definition at line 42 of file area.cpp.

Member Data Documentation

◆ x

double Okular::NormalizedPoint::x

The normalized x coordinate.

Definition at line 166 of file area.h.

◆ y

double Okular::NormalizedPoint::y

The normalized y coordinate.

Definition at line 171 of file area.h.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.