The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

Intersection.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
Circle boundaries heads/master
1 /* 2 Copyright (C) 2015 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 using Cairo; 16 using Math; 17 18 namespace BirdFont { 19 20 public class Intersection : GLib.Object { 21 public bool done = false; 22 public EditPoint point; 23 public EditPoint other_point; 24 public Path path; 25 public Path other_path; 26 public bool self_intersection = false; 27 28 public Intersection (EditPoint point, Path path, 29 EditPoint other_point, Path other_path) { 30 31 this.point = point; 32 this.path = path; 33 this.other_point = other_point; 34 this.other_path = other_path; 35 } 36 37 public Intersection.empty () { 38 this.point = new EditPoint (); 39 this.path = new Path (); 40 this.other_point = new EditPoint (); 41 this.other_path = new Path (); 42 } 43 44 public Path get_other_path (Path p) { 45 if (p == path) { 46 return other_path; 47 } 48 49 if (p == other_path) { 50 return path; 51 } 52 53 warning (@"Wrong intersection."); 54 return new Path (); 55 } 56 57 public EditPoint get_point (Path p) { 58 if (p == path) { 59 return point; 60 } 61 62 if (p == other_path) { 63 return other_point; 64 } 65 66 warning ("Wrong intersection."); 67 return new EditPoint (); 68 } 69 70 public EditPoint get_other_point (Path p) { 71 if (p == path) { 72 return other_point; 73 } 74 75 if (p == other_path) { 76 return point; 77 } 78 79 warning ("Wrong intersection."); 80 return new EditPoint (); 81 } 82 83 public string to_string () { 84 return @"$(point.x), $(point.y) & $(other_point.x), $(other_point.y)"; 85 } 86 } 87 88 public class IntersectionList : GLib.Object { 89 public Gee.ArrayList<Intersection> points = new Gee.ArrayList<Intersection> (); 90 91 public IntersectionList () { 92 } 93 94 public Intersection get_point (EditPoint ep, out bool other) { 95 other = false; 96 foreach (Intersection i in points) { 97 if (likely (i.other_point == ep || i.point == ep)) { 98 other = (i.other_point == ep); 99 return i; 100 } 101 } 102 103 warning (@"No intersection found for point ($(ep.x), $(ep.y)).\n"); 104 105 return new Intersection.empty (); 106 } 107 108 public bool has_point (EditPoint ep) { 109 foreach (Intersection i in points) { 110 if (i.other_point == ep || i.point == ep) { 111 return true; 112 } 113 } 114 115 return false; 116 } 117 118 } 119 120 } 121