]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/snap/RelativeScaleSnapAdvisor.java
Option to use custom snap advisor for scaling
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / snap / RelativeScaleSnapAdvisor.java
1 /*******************************************************************************
2  * Copyright (c) 2020 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.scenegraph.g2d.snap;
13
14 import java.awt.geom.Point2D;
15
16 public class RelativeScaleSnapAdvisor implements ISnapAdvisor {
17
18     private double step;
19
20     public RelativeScaleSnapAdvisor(double step) {
21         this.step = step;
22     }
23
24     @Override
25     public void snap(Point2D point) {
26         point.setLocation(
27                 Math.pow(1 + step, Math.round(Math.log(point.getX()) / Math.log(1 + step))),
28                 Math.pow(1 + step, Math.round(Math.log(point.getY()) / Math.log(1 + step))));
29     }
30
31     @Override
32     public void snap(Point2D point, Point2D[] features) {
33         snap(point);
34     }
35
36 }