2 * Copyright 2012 Google, Inc. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * Google Author(s): Behdad Esfahbod
23 #include "glyphy-common.hh"
27 glyphy_extents_clear (glyphy_extents_t *extents)
29 extents->min_x = GLYPHY_INFINITY;
30 extents->min_y = GLYPHY_INFINITY;
31 extents->max_x = -GLYPHY_INFINITY;
32 extents->max_y = -GLYPHY_INFINITY;
36 glyphy_extents_is_empty (const glyphy_extents_t *extents)
38 return std::isinf (extents->min_x);
42 glyphy_extents_add (glyphy_extents_t *extents,
43 const glyphy_point_t *p)
45 if (glyphy_extents_is_empty (extents)) {
46 extents->min_x = extents->max_x = p->x;
47 extents->min_y = extents->max_y = p->y;
50 extents->min_x = std::min (extents->min_x, p->x);
51 extents->min_y = std::min (extents->min_y, p->y);
52 extents->max_x = std::max (extents->max_x, p->x);
53 extents->max_y = std::max (extents->max_y, p->y);
57 glyphy_extents_extend (glyphy_extents_t *extents,
58 const glyphy_extents_t *other)
60 if (glyphy_extents_is_empty (other))
62 if (glyphy_extents_is_empty (extents)) {
66 extents->min_x = std::min (extents->min_x, other->min_x);
67 extents->min_y = std::min (extents->min_y, other->min_y);
68 extents->max_x = std::max (extents->max_x, other->max_x);
69 extents->max_y = std::max (extents->max_y, other->max_y);
73 glyphy_extents_includes (const glyphy_extents_t *extents,
74 const glyphy_point_t *p)
76 return extents->min_x <= p->x && p->x <= extents->max_x &&
77 extents->min_y <= p->y && p->y <= extents->max_y;
81 glyphy_extents_scale (glyphy_extents_t *extents,
85 extents->min_x *= x_scale;
86 extents->max_x *= x_scale;
87 extents->min_y *= y_scale;
88 extents->max_y *= y_scale;