The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

FastPath.vala in libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/FastPath.vala.
Merge branch '2.10'
1 /* 2 Copyright (C) 2014 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 namespace BirdFont { 16 17 /** A faster implementation of the Path and EditPoint classes. */ 18 public class FastPath : GLib.Object { 19 20 /** Control points and control point handles. 21 * 22 * Each point is stored with left handle at index - 2, 23 * the point at index, and right handle at index + 2. Both x and y 24 * coordinates is stores in this array. 25 */ 26 double* points; 27 28 /** Point types. */ 29 uint* types; 30 31 /** The number of points that can be stored in the point array. */ 32 int capacity; 33 34 public static const uint NUMBERS_PER_POINT = 6; 35 36 public static const uint LEFT_HANDLE_POS_X = 0; 37 public static const uint LEFT_HANDLE_POS_Y = 1; 38 public static const uint POS_X = 2; 39 public static const uint POS_Y = 3; 40 public static const uint RIGHT_HANDLE_POS_X = 4; 41 public static const uint RIGHT_HANDLE_POS_Y = 5; 42 43 /** Various boolean properties */ 44 uint* flags; 45 46 public static uint ACTIVE = 1 << 0; 47 public static uint SELECTED = 1 << 1; 48 public static uint DELETED = 1 << 2; 49 50 public static uint TIE_HANDLES = 1 << 3; 51 public static uint REFLECTIVE_HANDLES = 1 << 4; 52 53 /** Number of control points in this path. */ 54 int number_of_points = 0; 55 56 public FastPath () { 57 capacity = 1024; 58 points = new double[capacity * NUMBERS_PER_POINT]; 59 types = new uint[capacity]; 60 } 61 62 ~FastPath () { 63 delete points; 64 delete types; 65 } 66 67 /** @return number of control points in this path. */ 68 public int get_length () { 69 return number_of_points; 70 } 71 72 /** Get a slow representation for an edipoint. */ 73 public EditPoint get_editpoint (int index) { 74 EditPoint ep = new EditPoint (get_x (index), get_y (index), get_point_type (index)); 75 ep.get_left_handle ().move_to_coordinate (get_left_handle_x (index), get_left_handle_y (index)); 76 ep.get_right_handle ().move_to_coordinate (get_right_handle_x (index), get_right_handle_y (index)); 77 return ep; 78 } 79 80 public void set_editpoint (int index, EditPoint ep) { 81 points[NUMBERS_PER_POINT * index + POS_X] = ep.x; 82 points[NUMBERS_PER_POINT * index + POS_Y] = ep.y; 83 points[NUMBERS_PER_POINT * index + LEFT_HANDLE_POS_X] = ep.get_left_handle ().x; 84 points[NUMBERS_PER_POINT * index + LEFT_HANDLE_POS_Y] = ep.get_left_handle ().y; 85 points[NUMBERS_PER_POINT * index + RIGHT_HANDLE_POS_X] = ep.get_right_handle ().x; 86 points[NUMBERS_PER_POINT * index + RIGHT_HANDLE_POS_Y] = ep.get_right_handle ().y; 87 } 88 89 public double get_x (int index) { 90 return points[NUMBERS_PER_POINT * index + POS_X]; 91 } 92 93 public double get_y (int index) { 94 return points[NUMBERS_PER_POINT * index + POS_Y]; 95 } 96 97 public double get_left_handle_x (int index) { 98 return points[NUMBERS_PER_POINT * index + LEFT_HANDLE_POS_X]; 99 } 100 101 public double get_left_handle_y (int index) { 102 return points[NUMBERS_PER_POINT * index + LEFT_HANDLE_POS_Y]; 103 } 104 105 public double get_right_handle_x (int index) { 106 return points[NUMBERS_PER_POINT * index + RIGHT_HANDLE_POS_X]; 107 } 108 109 public double get_right_handle_y (int index) { 110 return points[NUMBERS_PER_POINT * index + RIGHT_HANDLE_POS_Y]; 111 } 112 113 public PointType get_point_type (int index) { 114 return (PointType) types[index]; 115 } 116 117 public bool is_active (int index) { 118 return (flags[index] & ACTIVE) > 0; 119 } 120 121 public bool is_selected (int index) { 122 return (flags[index] & SELECTED) > 0; 123 } 124 125 public bool is_deleted (int index) { 126 return (flags[index] & DELETED) > 0; 127 } 128 129 public bool has_tied_handles (int index) { 130 return (flags[index] & TIE_HANDLES) > 0; 131 } 132 133 public bool has_reflective_handles (int index) { 134 return (flags[index] & REFLECTIVE_HANDLES) > 0; 135 } 136 } 137 138 } 139