Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsPoint.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef NSPOINT_H
8
#define NSPOINT_H
9
10
#include "nsCoord.h"
11
#include "mozilla/gfx/BaseSize.h"
12
#include "mozilla/gfx/BasePoint.h"
13
#include "nsSize.h"
14
#include "mozilla/gfx/Point.h"
15
16
// nsIntPoint represents a point in one of the types of pixels.
17
// Uses of nsIntPoint should eventually be converted to CSSIntPoint,
18
// LayoutDeviceIntPoint, etc. (see layout/base/Units.h).
19
typedef mozilla::gfx::IntPoint nsIntPoint;
20
21
// nsPoint represents a point in app units.
22
23
struct nsPoint : public mozilla::gfx::BasePoint<nscoord, nsPoint> {
24
  typedef mozilla::gfx::BasePoint<nscoord, nsPoint> Super;
25
26
0
  nsPoint() : Super() {}
27
0
  nsPoint(const nsPoint& aPoint) : Super(aPoint) {}
28
0
  nsPoint(nscoord aX, nscoord aY) : Super(aX, aY) {}
29
30
  inline nsIntPoint ScaleToNearestPixels(float aXScale, float aYScale,
31
                                         nscoord aAppUnitsPerPixel) const;
32
  inline nsIntPoint ToNearestPixels(nscoord aAppUnitsPerPixel) const;
33
34
  /**
35
   * Return this point scaled to a different appunits per pixel (APP) ratio.
36
   * @param aFromAPP the APP to scale from
37
   * @param aToAPP the APP to scale to
38
   */
39
  MOZ_MUST_USE inline nsPoint
40
    ScaleToOtherAppUnits(int32_t aFromAPP, int32_t aToAPP) const;
41
42
  MOZ_MUST_USE inline nsPoint
43
    RemoveResolution(const float resolution) const;
44
  MOZ_MUST_USE inline nsPoint
45
    ApplyResolution(const float resolution) const;
46
};
47
48
inline nsPoint ToAppUnits(const nsIntPoint& aPoint, nscoord aAppUnitsPerPixel);
49
50
inline nsIntPoint
51
nsPoint::ScaleToNearestPixels(float aXScale, float aYScale,
52
                              nscoord aAppUnitsPerPixel) const
53
0
{
54
0
  return nsIntPoint(
55
0
      NSToIntRoundUp(NSAppUnitsToDoublePixels(x, aAppUnitsPerPixel) * aXScale),
56
0
      NSToIntRoundUp(NSAppUnitsToDoublePixels(y, aAppUnitsPerPixel) * aYScale));
57
0
}
58
59
inline nsIntPoint
60
nsPoint::ToNearestPixels(nscoord aAppUnitsPerPixel) const
61
0
{
62
0
  return ScaleToNearestPixels(1.0f, 1.0f, aAppUnitsPerPixel);
63
0
}
64
65
inline nsPoint
66
nsPoint::ScaleToOtherAppUnits(int32_t aFromAPP, int32_t aToAPP) const
67
0
{
68
0
  if (aFromAPP != aToAPP) {
69
0
    nsPoint point;
70
0
    point.x = NSToCoordRound(NSCoordScale(x, aFromAPP, aToAPP));
71
0
    point.y = NSToCoordRound(NSCoordScale(y, aFromAPP, aToAPP));
72
0
    return point;
73
0
  }
74
0
  return *this;
75
0
}
76
77
inline nsPoint
78
0
nsPoint::RemoveResolution(const float resolution) const {
79
0
  if (resolution != 1.0f) {
80
0
    nsPoint point;
81
0
    point.x = NSToCoordRound(NSCoordToFloat(x) / resolution);
82
0
    point.y = NSToCoordRound(NSCoordToFloat(y) / resolution);
83
0
    return point;
84
0
  }
85
0
  return *this;
86
0
}
87
88
inline nsPoint
89
0
nsPoint::ApplyResolution(const float resolution) const {
90
0
  if (resolution != 1.0f) {
91
0
    nsPoint point;
92
0
    point.x = NSToCoordRound(NSCoordToFloat(x) * resolution);
93
0
    point.y = NSToCoordRound(NSCoordToFloat(y) * resolution);
94
0
    return point;
95
0
  }
96
0
  return *this;
97
0
}
98
99
// app units are integer multiples of pixels, so no rounding needed
100
inline nsPoint
101
ToAppUnits(const nsIntPoint& aPoint, nscoord aAppUnitsPerPixel)
102
0
{
103
0
  return nsPoint(NSIntPixelsToAppUnits(aPoint.x, aAppUnitsPerPixel),
104
0
                 NSIntPixelsToAppUnits(aPoint.y, aAppUnitsPerPixel));
105
0
}
106
107
#endif /* NSPOINT_H */