/
QuadraticCurvesIntersection.java
81 lines (70 loc) · 2.55 KB
/
QuadraticCurvesIntersection.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*******************************************************************************
* Copyright (c) 2011, 2015 itemis AG and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Matthias Wienand (itemis AG) - initial API and implementation
*
*******************************************************************************/
package org.eclipse.gef4.geometry.examples.intersection;
import org.eclipse.gef4.geometry.convert.swt.Geometry2SWT;
import org.eclipse.gef4.geometry.planar.IGeometry;
import org.eclipse.gef4.geometry.planar.Point;
import org.eclipse.gef4.geometry.planar.QuadraticCurve;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
public class QuadraticCurvesIntersection extends AbstractIntersectionExample {
public static void main(String[] args) {
new QuadraticCurvesIntersection(
"Quadratic Bezier Curve/Curve Intersection");
}
public QuadraticCurvesIntersection(String title) {
super(title);
}
@Override
protected Point[] computeIntersections(IGeometry g1, IGeometry g2) {
return ((QuadraticCurve) g1).getIntersections((QuadraticCurve) g2);
}
private AbstractControllableShape createControllableQuadraticBezierCurveShape(
Canvas canvas, Point... points) {
final Point start = points[0];
final Point ctrl = points[1];
final Point end = points[2];
return new AbstractControllableShape(canvas) {
@Override
public void createControlPoints() {
addControlPoint(start);
addControlPoint(ctrl);
addControlPoint(end);
}
@Override
public IGeometry createGeometry() {
return new QuadraticCurve(getControlPoints());
}
@Override
public void drawShape(GC gc) {
QuadraticCurve curve = (QuadraticCurve) createGeometry();
gc.drawPath(
new org.eclipse.swt.graphics.Path(Display.getCurrent(),
Geometry2SWT.toSWTPathData(curve.toPath())));
}
};
}
@Override
protected AbstractControllableShape createControllableShape1(
Canvas canvas) {
return createControllableQuadraticBezierCurveShape(canvas,
new Point(100, 100), new Point(300, 150), new Point(400, 400));
}
@Override
protected AbstractControllableShape createControllableShape2(
Canvas canvas) {
return createControllableQuadraticBezierCurveShape(canvas,
new Point(400, 100), new Point(310, 290), new Point(100, 400));
}
}